Last active
August 1, 2017 16:52
-
-
Save ArunMichaelDsouza/49ad0e6978e23c71fecfff09a1a85cb4 to your computer and use it in GitHub Desktop.
Demo webpack config for a production build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Demo webpack config for a production build | |
This setup can be further combined with tree-shaking and async code splitting for best results */ | |
const path = require('path'), | |
webpack = require('webpack'), | |
buildPath = '../public/assets/js/builds/', | |
ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
module.exports = [{ | |
// Entry point | |
entry: { | |
outer: path.join(__dirname, 'app/outer.js') | |
}, | |
// Output | |
output: { | |
path: path.join(__dirname, buildPath), | |
filename: '[name].js' | |
}, | |
// ES6 Module resolution | |
resolve: { | |
alias: { | |
react: path.resolve('./node_modules/react'), | |
React: path.resolve('./node_modules/react'), | |
}, | |
modules: ['./components/', './components/outer', './components/shared', 'node_modules'], | |
extensions: ['.js', '.jsx', '.css'] | |
}, | |
// Loader setup | |
module: { | |
loaders: [{ | |
test: /.jsx?$/, | |
loader: 'babel-loader', // babel-loader for ES6 and jsx files | |
exclude: /node_modules/, | |
query: { | |
presets: ['es2015', 'react', 'stage-2'] | |
} | |
}, | |
{ | |
test: /\.css$/, | |
loader: ['css-loader'], // css-loader for css files | |
use: ExtractTextPlugin.extract({ | |
use: 'css-loader' | |
}) | |
} | |
] | |
}, | |
// Plugins | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin(), // Minification plugin | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify('production') // Node Env production flag | |
}), | |
new ExtractTextPlugin('./build/app-styles.css'), // CSS code splitting | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor', | |
minChunks: function(module) { | |
return module.context && module.context.indexOf('node_modules') !== -1; // Vendor bundle creation (all modules included from node_modules) | |
} | |
}) | |
] | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment