-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
158 lines (148 loc) · 3.73 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const path = require('path');
const webpack = require('webpack');
const env = process.env.NODE_ENV;
const PATHS = {
static: path.resolve(__dirname, 'src/snowflakes/static'),
build: path.resolve(__dirname, 'src/snowflakes/static/build'),
}
const plugins = [];
// don't include momentjs locales (large)
//plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]));
let chunkFilename = '[name].js';
let mode = 'development';
const TerserPlugin = require('terser-webpack-plugin');
let optimization = {
minimize: false,
};
if (env === 'production') {
mode = 'production';
// uglify code for production
optimization.minimizer= [
new TerserPlugin({
terserOptions: {
warning: true,
mangle:true,
}
})
];
optimization.minimize= true;
// add chunkhash to chunk names for production only (it's slower)
chunkFilename = '[name].[chunkhash].js';
}
plugins.push(new webpack.LoaderOptionsPlugin({
debug: true
}));
// Strip @jsx pragma in react-forms, which makes babel abort
// add babel to load .js files as ES6 and transpile JSX
const rules = [
{
test: /\.js$/,
include: path.resolve(__dirname, 'node_modules/react-forms'),
enforce: "pre",
loader: 'string-replace-loader',
options: {
search: '@jsx',
replace: 'jsx',
}
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src/snowflakes/static'),
path.resolve(__dirname, 'node_modules/react-forms'),
path.resolve(__dirname, 'node_modules/terser-webpack-plugin/dist'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/flow']
}
}
},
];
// const rules = [
// {
// test: /\.js$/,
// include: [
// PATHS.static,
// path.resolve(__dirname, 'node_modules/dagre-d3'),
// path.resolve(__dirname, 'node_modules/superagent'),
// ],
// use: {
// loader: 'babel-loader',
// },
// },
// {
// test: /\.(jpg|png|gif)$/,
// include: PATHS.images,
// use: [
// {
// loader: 'url-loader',
// options: {
// limit: 25000,
// },
// }
// ],
// },
// {
// test: /\.scss$/,
// use: [
// MiniCssExtractPlugin.loader,
// { loader: 'css-loader', options: { url: false, sourceMap: true } },
// { loader: 'sass-loader', options: { sourceMap: true } }
// ],
// },
// ];
module.exports = [
// for browser
{
context: PATHS.static,
entry: {inline: './inline'},
output: {
path: PATHS.build,
publicPath: '/static/build/',
filename: '[name].js',
chunkFilename: chunkFilename,
},
module: {
rules,
},
mode,
optimization,
devtool: 'source-map',
plugins: plugins
},
// for server-side rendering
{
entry: {
renderer: './src/snowflakes/static/server.js',
},
target: 'node',
// make sure compiled modules can use original __dirname
node: {
__dirname: true,
},
externals: [
'brace',
'brace/mode/json',
'brace/theme/solarized_light',
'd3',
'dagre-d3',
// avoid bundling babel transpiler, which is not used at runtime
'@babel/register',
],
output: {
path: PATHS.build,
filename: '[name].js',
libraryTarget: 'commonjs2',
chunkFilename: chunkFilename,
},
module: {
rules,
},
mode,
optimization,
devtool: 'source-map',
plugins: plugins
}
];