Commit 9652973e authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Optimize the production build (#49)

Inspired by react-boilerplate setup
parent 29ac0ed5
No related merge requests found
Showing with 9 additions and 3 deletions
+9 -3
...@@ -11,6 +11,7 @@ var path = require('path'); ...@@ -11,6 +11,7 @@ var path = require('path');
var autoprefixer = require('autoprefixer'); var autoprefixer = require('autoprefixer');
var webpack = require('webpack'); var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var isInNodeModules = 'node_modules' === var isInNodeModules = 'node_modules' ===
path.basename(path.resolve(path.join(__dirname, '..', '..'))); path.basename(path.resolve(path.join(__dirname, '..', '..')));
...@@ -22,7 +23,8 @@ module.exports = { ...@@ -22,7 +23,8 @@ module.exports = {
entry: './src/index.js', entry: './src/index.js',
output: { output: {
path: path.resolve(__dirname, relative, 'build'), path: path.resolve(__dirname, relative, 'build'),
filename: '[name].[hash].js', filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].chunk.js',
// TODO: this wouldn't work for e.g. GH Pages. // TODO: this wouldn't work for e.g. GH Pages.
// Good news: we can infer it from package.json :-) // Good news: we can infer it from package.json :-)
publicPath: '/' publicPath: '/'
...@@ -49,7 +51,7 @@ module.exports = { ...@@ -49,7 +51,7 @@ module.exports = {
{ {
test: /\.css$/, test: /\.css$/,
include: path.resolve(__dirname, relative, 'src'), include: path.resolve(__dirname, relative, 'src'),
loader: 'style!css!postcss' loader: ExtractTextPlugin.extract('style', 'css!postcss')
}, },
{ {
test: /\.json$/, test: /\.json$/,
...@@ -93,6 +95,7 @@ module.exports = { ...@@ -93,6 +95,7 @@ module.exports = {
}), }),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }), new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
compressor: { compressor: {
screw_ie8: true, screw_ie8: true,
...@@ -105,6 +108,7 @@ module.exports = { ...@@ -105,6 +108,7 @@ module.exports = {
comments: false, comments: false,
screw_ie8: true screw_ie8: true
} }
}) }),
new ExtractTextPlugin('[name].[contenthash].css')
] ]
}; };
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
"eslint-loader": "1.4.1", "eslint-loader": "1.4.1",
"eslint-plugin-import": "1.10.3", "eslint-plugin-import": "1.10.3",
"eslint-plugin-react": "5.2.2", "eslint-plugin-react": "5.2.2",
"extract-text-webpack-plugin": "1.0.1",
"file-loader": "0.9.0", "file-loader": "0.9.0",
"html-webpack-plugin": "2.22.0", "html-webpack-plugin": "2.22.0",
"json-loader": "0.5.4", "json-loader": "0.5.4",
...@@ -77,6 +78,7 @@ ...@@ -77,6 +78,7 @@
"eslint-loader", "eslint-loader",
"eslint-plugin-import", "eslint-plugin-import",
"eslint-plugin-react", "eslint-plugin-react",
"extract-text-webpack-plugin",
"file-loader", "file-loader",
"html-webpack-plugin", "html-webpack-plugin",
"json-loader", "json-loader",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment