This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
223 lines (207 loc) · 5.04 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Dependencies
*/
var webpack = require('webpack');
/**
* Import hash output plugin
*/
var OutputHashAsModulePlugin = require('./webpack-output-hash-as-module-plugin');
/**
* Environment
*/
var isProduction = process.env.NODE_ENV === 'production';
var port = process.env.PORT || 3000;
/**
* Plugins
*/
var plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'__DEVELOPMENT__': JSON.stringify(!isProduction)
}),
new webpack.IgnorePlugin(new RegExp('node-sass'))
];
/**
* Add hot module replacement
* when developing
*/
if (!isProduction) {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.NoEmitOnErrorsPlugin());
}
/**
* Do code de-duping and minification
* when running production mode
*/
if (isProduction) {
plugins.push(new OutputHashAsModulePlugin({ file: 'bundle-hash.js' }));
if (!process.env.DISABLE_JS_UGLIFY) {
plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false, }, sourceMap: true, }));
}
}
/**
* Entry points
*/
var entry = ['./src/client-bootstrap'];
/**
* Add required entry points
* when using hot module replacement
* and webpack-dev-server
*/
if (!isProduction) {
entry.unshift('webpack/hot/only-dev-server');
entry.unshift('webpack-dev-server/client?http://localhost:' + port);
}
/**
* Config
*
* TODO: Make the parts of the config that should be
* customizable properties that you can inject into
* a constructor function (entry, output.path, output.publicPath, etc...)
*/
module.exports = {
/**
* Use source maps for better debugging
* http://cheng.logdown.com/posts/2016/03/25/679045
*/
devtool: isProduction ? 'cheap-module-source-map' : 'cheap-module-eval-source-map',
/**
* Add our entry file(s)
*/
entry: entry,
/**
* Bundle output settings
*
* Production: Use the hash to tag the output bundles
* Development: No hashing (as we refer to just "app.js" in /public/static/index.html)
*/
output: isProduction ? {
path: './public/static/',
publicPath: '/static/',
filename: 'app.[hash].js',
chunkFilename: '[id].app.[chunkHash].js'
} : {
path: './public/static/',
publicPath: '/static/',
filename: 'app.js',
chunkFilename: '[id].app.js'
},
/**
* Add out plugins to the config
*/
plugins: plugins,
/**
* Module loaders for resolving
* the different file extensions
* using loaders
*/
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: !isProduction ? [
{
loader: 'react-hot-loader',
}, {
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
// ['es2015', {modules: false}],
'es2015',
'stage-0',
'react',
],
plugins: [
// All these plugins transform dynamic import with async/await
'syntax-async-functions',
'syntax-dynamic-import',
'transform-async-to-generator',
'transform-regenerator',
'transform-runtime',
// Now for some other plugins
'transform-flow-strip-types',
'styled-components',
],
}
},
] : [
{
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
//['es2015', {modules: false}],
'es2015',
'stage-0',
'react',
],
plugins: [
// All these plugins transform dynamic import with async/await
'syntax-async-functions',
'syntax-dynamic-import',
'transform-async-to-generator',
'transform-regenerator',
'transform-runtime',
// Now for some other plugins
'transform-flow-strip-types',
'styled-components',
],
}
}
],
}, {
test: /\.scss$/,
use: !isProduction ? [
{
loader: 'style-loader',
}, {
loader: 'css-loader',
options: {
minimize: true,
autoprefixer: true,
},
}, {
loader: 'postcss-loader',
}, {
loader: 'sass-loader'
},
] : [
{
loader: 'css-loader',
options: {
minimize: true,
autoprefixer: false,
},
}, {
loader: 'postcss-loader',
}, {
loader: 'sass-loader',
},
]
}]
},
/**
* Add resolver aliases that
* we want to ignore in our
* webpack bundle
*
* NOTE: We just replace any
* server specific modules
* with a no-op (from npm)
*/
resolve: {
alias: {
'node-sass': 'no-op'
}
},
/**
* Add node built-ins requires that should
* be ignored when creating
* the webpack bundle (since these are server-only)
*/
node: {
'fs': 'empty',
'node-sass': 'empty'
}
};