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:
Andrey Okonetchnikov
2016-10-26 19:51:35 +02:00
committed by Cássio Souza
parent 5151e7cdb1
commit 434f45c97c
8 changed files with 69 additions and 58 deletions

View File

@ -2,6 +2,8 @@
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HOST = 'localhost';
const PORT = '8080';
@ -9,29 +11,46 @@ module.exports = merge.smart(require('./webpack.base.js'), {
entry: {
cms: [
'webpack/hot/dev-server',
`webpack-dev-server/client?http://${HOST}:${PORT}/`,
`webpack-dev-server/client?http://${ HOST }:${ PORT }/`,
'react-hot-loader/patch',
'./index'
'./index',
],
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
publicPath: `http://${HOST}:${PORT}/`,
publicPath: `http://${ HOST }:${ PORT }/`,
},
context: path.join(__dirname, 'src'),
module: {
loaders: [
{
loader: 'babel',
test: /\.js?$/,
exclude: /node_modules/,
query: {
plugins: [
'react-hot-loader/babel',
],
},
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
},
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
new ExtractTextPlugin('[name].css', { disable: true }),
],
devServer: {
hot: true,
contentBase: 'example/',
historyApiFallback: true,
devTool: 'cheap-module-source-map'
devTool: 'cheap-module-source-map',
},
});