Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/lib/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function readJson(file) {
readJson.cache = {};

export default env => {
let isProd = env && env.production;
let cwd = env.cwd = resolve(env.cwd || process.cwd());
let src = dir => resolve(env.cwd, env.src || 'src', dir);

Expand Down Expand Up @@ -178,7 +179,7 @@ export default env => {
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
`css-loader?modules&localIdentName=[local]__[hash:base64:5]&importLoaders=1&sourceMap=${env.production}`,
`css-loader?modules&localIdentName=[local]__[hash:base64:5]&importLoaders=1&sourceMap=${isProd}`,
`postcss-loader`
]
})
Expand All @@ -192,7 +193,7 @@ export default env => {
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
`css-loader?sourceMap=${env.production}`,
`css-loader?sourceMap=${isProd}`,
`postcss-loader`
]
})
Expand All @@ -215,7 +216,7 @@ export default env => {
},
{
test: /\.(svg|woff2?|ttf|eot|jpe?g|png|gif)(\?.*)?$/i,
loader: env.production ? 'file-loader' : 'url-loader'
loader: isProd ? 'file-loader' : 'url-loader'
}
]
}
Expand All @@ -235,18 +236,18 @@ export default env => {
]),

defineConstants({
'process.env.NODE_ENV': env.production ? 'production' : 'development'
'process.env.NODE_ENV': isProd ? 'production' : 'development'
}),

// monitor output size and warn if it exceeds 200kb:
env.production && performance(Object.assign({
isProd && performance(Object.assign({
maxAssetSize: 200 * 1000,
maxEntrypointSize: 200 * 1000,
hints: 'warning'
}, env.pkg.performance || {})),

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

// remove unnecessary shims:
customConfig({
Expand All @@ -260,6 +261,11 @@ export default env => {
}
}),

// dev-only plugins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: maybe drop this into the development() group instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. My hesitation was that it wasn't modifying plugins but, ofc, that's what addPlugins is doing 😅

!isProd && addPlugins([
new webpack.NamedModulesPlugin()
]),

// copy any static files
addPlugins([
new CopyWebpackPlugin([
Expand All @@ -272,7 +278,7 @@ export default env => {
addPlugins([
new ExtractTextPlugin({
filename: 'style.css',
disable: !env.production,
disable: !isProd,
allChunks: true
})
]),
Expand All @@ -287,7 +293,7 @@ export default env => {

htmlPlugin(env),

env.production ? production(env) : development(env),
isProd ? production(env) : development(env),

addPlugins([
new webpack.NoEmitOnErrorsPlugin(),
Expand Down