Skip to content

Instantly share code, notes, and snippets.

@mikechau
Created April 28, 2015 05:25
Show Gist options
  • Save mikechau/8d2184845fdbb12bfad6 to your computer and use it in GitHub Desktop.
Save mikechau/8d2184845fdbb12bfad6 to your computer and use it in GitHub Desktop.
/*
* Webpack production build configuration
*
* This file is set up for building assets ready to be served in production.
*/
'use strict';
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
output: {
path: path.join(__dirname, 'build', 'assets'),
publicPath: '/assets/',
filename: "[name].js",
chunkFilename: "[id].chunk.[hash].js",
// sourceMapFilename: "[file].map",
pathinfo: false
},
debug: false,
devtool: false,
// devtool: "source-map",
entry: {
main: './app/main.jsx',
vendor: ['react', 'react-router', 'react-bootstrap', 'react-datagrid', 'moment', 'bluebird', 'lodash', 'alt', 'superagent', 'alertifyjs', 'normalizr', 'humps']
},
stats: {
colors: true,
reasons: false
},
resolve: {
root: path.join(__dirname, 'app'),
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.jsx']
},
module: {
preLoaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'eslint-loader'
}
],
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader?stage=0&optional=runtime'
},
{
test: /\.css$/,
// loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
loader: 'style-loader!css-loader'
},
{
test: /\.less/,
loader: 'style-loader!css-loader!less-loader'
},
{
test: /\.(scss|sass)/,
loader: 'css-loader!sass-loader'
},
{
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: 'url-loader?limit=10000'
},
{
test: /\.(woff|woff2)$/,
loader: 'url-loder?limit=10000'
},
{
test: /\.(ttf|eot)$/,
loader: 'file-loader'
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.json5$/,
loader: 'json5-loader'
},
{
test: /\.(wav|mp3)$/,
loader: 'file-loader'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.txt$/,
loader: 'raw-loader'
},
{
test: /\.(md|markdown)$/,
loaders: ['html-loader', 'markdown-loader']
}
]
},
plugins: [
function() {
this.plugin("done", function(stats) {
var jsonStats = stats.toJson({
chunkModules: true,
exclude: [
/node_modules[\\\/]react(-router)?[\\\/]/
]
});
jsonStats.publicPath = '/assets/';
require("fs").writeFileSync(path.join(__dirname, "build", "stats.json"), JSON.stringify(jsonStats));
});
},
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
},
DEBUG: false,
BROWSER: true
}),
new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js"),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.MinChunkSizePlugin({minChunkSize: 10000}),
new webpack.NoErrorsPlugin(),
new CompressionPlugin()
],
devServer: {
stats: {
exclude: [
/node_modules[\\\/]react(-router)?[\\\/]/
]
}
},
eslint: {
configFile: './.eslintrc',
ignorePath: './.eslintignore'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment