-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
116 lines (108 loc) · 2.31 KB
/
webpack.config.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require("path");
const commonConfig = {
devtool: 'eval-cheap-module-source-map',
resolve: {
extensions: ["*", ".js", ".jsx"],
// Note: Separate aliases are required for aliases to work in unit tests. These should
// be added in package.json in the jest configuration.
alias: {
'@ml': path.resolve(__dirname, 'src'),
'@public': path.resolve(__dirname, 'public')
}
},
output: {
filename: "[name].js",
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader'
},
{test: /\.css$/, loader: 'style-loader!css-loader'},
{
test: /\.jsx$/,
enforce: 'pre',
exclude: /(node_modules)/,
use: [
{
loader: 'babel-loader',
}
]
},
{
test: /\.(png|jpg)$/,
loader: 'url-loader',
options: {
limit: 8192,
outputPath: 'assets/images',
publicPath: 'images',
postTransformPublicPath: p =>
`__ml_playground_asset_public_path__ + ${p}`,
name: '[name].[ext]?[contenthash]'
}
},
]
},
performance: {
assetFilter: function(assetFilename) {
return /^assets\//.test(assetFilename);
},
maxAssetSize: 300000,
maxEntrypointSize: 10500000
}
};
const firstConfigOnly = {
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin([
{
from: 'public/datasets/*.*',
to: 'assets/datasets/',
flatten: true
}
])
]
};
const externalConfig = {
externals: {
lodash: 'lodash',
radium: 'radium',
react: 'react',
'react-dom': 'react-dom'
}
};
const defaultConfig = [
{
entry: {
assetPath: './src/assetPath.js'
},
...commonConfig,
...firstConfigOnly,
...externalConfig
},
{
entry: {
mainDev: './src/indexDev.js'
},
...commonConfig
}
];
const productionConfig = [
{
entry: {
main: './src/indexProd.js'
},
...commonConfig,
...externalConfig
}
];
module.exports = (env, argv) => {
if (argv.mode === 'production') {
return [...defaultConfig, ...productionConfig];
}
return defaultConfig;
};