Skip to content
Merged
Changes from all 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
21 changes: 13 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 @@ -272,7 +273,7 @@ export default env => {
addPlugins([
new ExtractTextPlugin({
filename: 'style.css',
disable: !env.production,
disable: !isProd,
allChunks: true
})
]),
Expand All @@ -287,7 +288,7 @@ export default env => {

htmlPlugin(env),

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

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

return group([
addPlugins([
new webpack.NamedModulesPlugin()
]),

devServer({
port,
host,
Expand Down