-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
150 lines (139 loc) · 4.6 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
/* global process, __dirname */
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const env = process.env.NODE_ENV;
const PATHS = {
static: path.resolve(__dirname, 'src/encoded/static'),
build: path.resolve(__dirname, 'src/encoded/static/build'),
serverbuild: path.resolve(__dirname, 'src/encoded/static/build-server'),
fonts: path.resolve(__dirname, 'src/encoded/static/font'),
images: path.resolve(__dirname, 'src/encoded/static/img'),
};
const plugins = [];
// don't include momentjs locales (large)
plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, [/moment$/]));
// To get auth0 v11 to build correctly:
// https://github.com/felixge/node-formidable/issues/337#issuecomment-183388869
plugins.push(new webpack.DefinePlugin({ 'global.GENTLY': false }));
let chunkFilename = '[name].js';
let styleFilename = './css/[name].css';
if (env === 'production') {
// uglify code for production
plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true }));
// Set production version of React
// https://stackoverflow.com/questions/37311972/react-doesnt-switch-to-production-mode#answer-37311994
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
})
);
// add chunkhash to chunk names for production only (it's slower)
chunkFilename = '[name].[chunkhash].js';
styleFilename = './css/[name].[chunkhash].css';
}
const loaders = [
// add babel to load .js files as ES6 and transpile JSX
{
test: /\.js$/,
include: [
PATHS.static,
path.resolve(__dirname, 'node_modules/dagre-d3'),
path.resolve(__dirname, 'node_modules/dalliance'),
path.resolve(__dirname, 'node_modules/superagent'),
path.resolve(__dirname, 'node_modules/d3-sequence-logo'),
],
loader: 'babel',
query: { compact: false },
},
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.(jpg|png|gif)$/,
loader: 'url?limit=25000',
include: PATHS.images,
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css!sass'),
},
];
module.exports = [
// for browser
{
context: PATHS.static,
entry: {
inline: './inline',
style: './scss/style.scss',
},
output: {
path: PATHS.build,
publicPath: '/static/build/',
filename: '[name].js',
chunkFilename,
},
module: {
loaders,
},
devtool: 'source-map',
plugins: plugins.concat(
// Add a browser-only plugin to extract Sass-compiled styles and place them into an
// external CSS file
new ExtractTextPlugin(styleFilename, {
disable: false,
allChunks: true,
}),
// Add a browser-only plugin executed when webpack is done with all transforms. it
// writes minimal build statistics to the "build" directory that contains the hashed
// CSS file names that the server can render into the <link rel="stylesheet"> tag.
function writeWPStats() {
this.plugin('done', (stats) => {
// Write hash stats to stats.json so we can extract the CSS hashed file name.
require('fs').writeFileSync(
path.join(PATHS.build, 'stats.json'),
JSON.stringify(stats.toJson({ hash: true }, 'none')));
});
}
),
debug: true,
},
// for server-side rendering
{
entry: {
renderer: './src/encoded/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',
'chart.js',
'dalliance',
// avoid bundling babel transpiler, which is not used at runtime
'babel-core/register',
],
output: {
path: PATHS.serverbuild,
publicPath: '/static/build-server',
filename: '[name].js',
libraryTarget: 'commonjs2',
chunkFilename,
},
module: {
loaders,
},
devtool: 'source-map',
plugins,
debug: true,
},
];