Created
July 10, 2018 21:08
-
-
Save yattias/48e77c8f25b2e368726b17caa89332ef to your computer and use it in GitHub Desktop.
Sample webpack config for prod
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
const path = require('path'); | |
const webpack = require('webpack'); | |
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); | |
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | |
const settings = require('./settings'); | |
module.exports = { | |
entry: [ | |
'./src/client/index' | |
], | |
output: { | |
path: path.join(__dirname, 'dist'), | |
filename: 'bundle.js', | |
publicPath: '/static/' | |
}, | |
plugins: [ | |
new BundleAnalyzerPlugin({ | |
reportFilename: 'report.html', | |
analyzerMode: 'static' | |
}), | |
new webpack.LoaderOptionsPlugin({ | |
minimize: true, | |
debug: false | |
}), | |
new webpack.optimize.AggressiveMergingPlugin(), | |
new UglifyJSPlugin({ | |
uglifyOptions: { | |
compress: { | |
warnings: true | |
}, | |
output: { | |
comments: false, | |
beautify: true | |
} | |
}, | |
sourceMap: false | |
}), | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify('production'), | |
'process.env.BUILD_ENV': JSON.stringify(process.env.BUILD_ENV), | |
'__API_HOST__': JSON.stringify(settings.api.host), | |
'__HUB_HOST__': JSON.stringify(settings.hub.host) | |
}) | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.js?/, | |
include: [ | |
path.join(__dirname, '../../client'), | |
path.join(__dirname, 'config') | |
], | |
exclude: [ | |
/node_modules/, /styles/ | |
], | |
use: [ | |
{ | |
loader: 'babel-loader' | |
} | |
] | |
}, | |
{ | |
test: /\.(jpe?g|png|gif|svg|mov)$/i, | |
loader: 'file-loader?name=[name].[ext]' | |
}, | |
{ | |
test: /\.(scss|css)$/, | |
use: [ | |
'style-loader', | |
'css-loader', | |
'sass-loader' | |
] | |
} | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment