Webpack optimizations (#140)
* Less repetition in webpack configs. Minify CSS classnames in production. * Ignore all optional deps of moment.js. Fixes #138 * Added target to webpack config * Automatically extract all 3rd party modules into a separate 'vendor' chunk * Inline only assets that are smaller than 10KB * Added autoprefixer options * Replaced sinfle babel transforms with the stage-1 preset. Cleaned up webpack configs. * Do not include hot module replacement in production
This commit is contained in:
committed by
Cássio Souza
parent
5151e7cdb1
commit
434f45c97c
@ -6,9 +6,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
|
||||
module.exports = merge.smart(require('./webpack.base.js'), {
|
||||
entry: {
|
||||
cms: [
|
||||
'./index',
|
||||
],
|
||||
cms: './index',
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, 'dist'),
|
||||
@ -16,26 +14,36 @@ module.exports = merge.smart(require('./webpack.base.js'), {
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loader: ExtractTextPlugin.extract('style', 'css?modules!sass'),
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1&&localIdentName=cms__[name]__[local]!postcss'),
|
||||
loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1!postcss'), // Use minified class names on production
|
||||
},
|
||||
],
|
||||
},
|
||||
context: path.join(__dirname, 'src'),
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
|
||||
'process.env': {
|
||||
NODE_ENV: JSON.stringify('production'),
|
||||
},
|
||||
}),
|
||||
new webpack.optimize.OccurenceOrderPlugin(),
|
||||
new webpack.optimize.UglifyJsPlugin(),
|
||||
|
||||
// Minify and optimize the JavaScript
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
// ...but do not show warnings in the console (there is a lot of them)
|
||||
warnings: false,
|
||||
},
|
||||
}),
|
||||
|
||||
// Extract CSS
|
||||
new ExtractTextPlugin('[name].css', { allChunks: true }),
|
||||
|
||||
// Automatically extract all 3rd party modules into a separate 'vendor' chunk
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: 'vendor',
|
||||
minChunks: ({ resource }) => /node_modules/.test(resource),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
Reference in New Issue
Block a user