forked from noodlapp/modules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (74 loc) · 2.12 KB
/
webpack.config.js
File metadata and controls
79 lines (74 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const path = require('path')
const fs = require('fs-extra')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const pjson = require('./package.json')
var outputPath = path.resolve(
__dirname,
'../project/noodl_modules/' + pjson.name
)
function stripStartDirectories(targetPath, numDirs) {
const p = targetPath.split('/')
p.splice(0, numDirs)
return p.join('/')
}
module.exports = {
entry: './src/index.ts',
mode: 'production',
devtool: 'source-map',
output: {
filename: 'index.js',
path: outputPath,
},
externals: {
react: 'React',
'react-dom': 'ReactDOM',
},
resolve: {
extensions: ['.js', '.json', '.css', '.ts', '.tsx'],
},
plugins: [
new CleanWebpackPlugin(outputPath),
new CopyWebpackPlugin([
{
from: 'assets/**/*',
transformPath: (targetPath) =>
stripStartDirectories(targetPath, 1),
},
]),
// Copy the generated module files to the tests project if it exists
{
apply: (compiler) => {
compiler.hooks.afterEmit.tap(
'AfterEmitPlugin',
(compilation) => {
if (
fs.existsSync(path.resolve(__dirname, '../tests'))
) {
fs.copySync(
outputPath,
path.resolve(
__dirname,
'../tests/noodl_modules/' + pjson.name
)
)
}
}
)
},
},
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
}