Skip to content

Commit f1d0f96

Browse files
authored
Merge pull request #20 from developit/dev-named-modules
Add NamedModulesPlugin for Dev
2 parents a1adc1c + cab9fe4 commit f1d0f96

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/lib/webpack-config.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function readJson(file) {
3838
readJson.cache = {};
3939

4040
export default env => {
41+
let isProd = env && env.production;
4142
let cwd = env.cwd = resolve(env.cwd || process.cwd());
4243
let src = dir => resolve(env.cwd, env.src || 'src', dir);
4344

@@ -178,7 +179,7 @@ export default env => {
178179
loader: ExtractTextPlugin.extract({
179180
fallback: 'style-loader',
180181
use: [
181-
`css-loader?modules&localIdentName=[local]__[hash:base64:5]&importLoaders=1&sourceMap=${env.production}`,
182+
`css-loader?modules&localIdentName=[local]__[hash:base64:5]&importLoaders=1&sourceMap=${isProd}`,
182183
`postcss-loader`
183184
]
184185
})
@@ -192,7 +193,7 @@ export default env => {
192193
loader: ExtractTextPlugin.extract({
193194
fallback: 'style-loader',
194195
use: [
195-
`css-loader?sourceMap=${env.production}`,
196+
`css-loader?sourceMap=${isProd}`,
196197
`postcss-loader`
197198
]
198199
})
@@ -215,7 +216,7 @@ export default env => {
215216
},
216217
{
217218
test: /\.(svg|woff2?|ttf|eot|jpe?g|png|gif)(\?.*)?$/i,
218-
loader: env.production ? 'file-loader' : 'url-loader'
219+
loader: isProd ? 'file-loader' : 'url-loader'
219220
}
220221
]
221222
}
@@ -235,18 +236,18 @@ export default env => {
235236
]),
236237

237238
defineConstants({
238-
'process.env.NODE_ENV': env.production ? 'production' : 'development'
239+
'process.env.NODE_ENV': isProd ? 'production' : 'development'
239240
}),
240241

241242
// monitor output size and warn if it exceeds 200kb:
242-
env.production && performance(Object.assign({
243+
isProd && performance(Object.assign({
243244
maxAssetSize: 200 * 1000,
244245
maxEntrypointSize: 200 * 1000,
245246
hints: 'warning'
246247
}, env.pkg.performance || {})),
247248

248249
// Source maps for dev/prod:
249-
setDevTool(env.production ? 'source-map' : 'cheap-module-eval-source-map'),
250+
setDevTool(isProd ? 'source-map' : 'cheap-module-eval-source-map'),
250251

251252
// remove unnecessary shims:
252253
customConfig({
@@ -272,7 +273,7 @@ export default env => {
272273
addPlugins([
273274
new ExtractTextPlugin({
274275
filename: 'style.css',
275-
disable: !env.production,
276+
disable: !isProd,
276277
allChunks: true
277278
})
278279
]),
@@ -287,7 +288,7 @@ export default env => {
287288

288289
htmlPlugin(env),
289290

290-
env.production ? production(env) : development(env),
291+
isProd ? production(env) : development(env),
291292

292293
addPlugins([
293294
new webpack.NoEmitOnErrorsPlugin(),
@@ -317,6 +318,10 @@ const development = config => {
317318
origin = `${config.https===true?'https':'http'}://${host}:${port}/`;
318319

319320
return group([
321+
addPlugins([
322+
new webpack.NamedModulesPlugin()
323+
]),
324+
320325
devServer({
321326
port,
322327
host,

0 commit comments

Comments
 (0)