Skip to content

Instantly share code, notes, and snippets.

@gregnb
Created June 5, 2017 23:36
Show Gist options
  • Select an option

  • Save gregnb/4da26484da8a93d9f11dcea2a7731260 to your computer and use it in GitHub Desktop.

Select an option

Save gregnb/4da26484da8a93d9f11dcea2a7731260 to your computer and use it in GitHub Desktop.
simple webpack config
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var config = {
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
resolve: {
alias: {
"store": path.resolve(__dirname, "assets/js/libs/store.min.js"),
"react-slick" : path.resolve(__dirname, "assets/js/libs/react-slick.min.js")
},
extensions: ['.js', '.jsx']
},
devtool: 'eval-cheap-source-map',
entry: {
app: "./src/app.jsx",
vendor: ["react", "react-dom", "store", "react-slick"]
},
output: {
path: path.resolve(__dirname, 'assets/'),
filename: "js/bundle.js"
},
plugins: [
new ExtractTextPlugin('css/build-styles.css'),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.ProvidePlugin({
'store' : 'store',
'window.store' : 'store',
'react-slick' : 'react-slick'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'js/vendor.bundle.js'
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
})
],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel-loader'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
loader: 'css-loader?-url&importLoaders=1&modules=true&localIdentName=[name]_[local]_[sha1:hash:hex:5]',
}),
}
]
}
};
console.log(process.env.NODE_ENV + " place");
if (process.env.NODE_ENV === 'production') {
config.devtool = 'source-map';
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
output: {
comments: false,
},
}));
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment