-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
103 lines (97 loc) · 2.16 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
var path = require('path');
var webpack = require('webpack');
var env = process.env.NODE_ENV;
var PATHS = {
static: path.resolve(__dirname, 'src/snowflakes/static'),
build: path.resolve(__dirname, 'src/snowflakes/static/build'),
}
var plugins = [];
// don't include momentjs locales (large)
plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]));
var chunkFilename = '[name].js';
if (env === 'production') {
// uglify code for production
plugins.push(new webpack.optimize.UglifyJsPlugin({minimize: true}));
// add chunkhash to chunk names for production only (it's slower)
chunkFilename = '[name].[chunkhash].js';
}
var preLoaders = [
// Strip @jsx pragma in react-forms, which makes babel abort
{
test: /\.js$/,
include: path.resolve(__dirname, 'node_modules/react-forms'),
loader: 'string-replace',
query: {
search: '@jsx',
replace: 'jsx',
}
}
];
var loaders = [
// add babel to load .js files as ES6 and transpile JSX
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src/snowflakes/static'),
path.resolve(__dirname, 'node_modules/react-forms'),
],
loader: 'babel',
},
{
test: /\.json$/,
loader: 'json',
}
];
module.exports = [
// for browser
{
context: PATHS.static,
entry: {inline: './inline'},
output: {
path: PATHS.build,
publicPath: '/static/build/',
filename: '[name].js',
chunkFilename: chunkFilename,
},
module: {
preLoaders: preLoaders,
loaders: loaders,
},
devtool: 'source-map',
plugins: plugins,
debug: true
},
// 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-core/register',
],
output: {
path: PATHS.build,
filename: '[name].js',
libraryTarget: 'commonjs2',
chunkFilename: chunkFilename,
},
module: {
preLoaders: preLoaders,
loaders: loaders,
},
devtool: 'source-map',
plugins: plugins,
debug: true
}
];