Skip to content

Instantly share code, notes, and snippets.

@chrisforrette
Created November 15, 2016 01:31
Show Gist options
  • Save chrisforrette/9ae937acd7662d2e09b7f550de033c45 to your computer and use it in GitHub Desktop.
Save chrisforrette/9ae937acd7662d2e09b7f550de033c45 to your computer and use it in GitHub Desktop.
Remo webpack config
var webpack = require('webpack');
var env = process.env.NODE_ENV;
var production = env === 'production';
var staging = env === 'staging';
var optimize = production || staging;
// Plugins
var plugins = [];
if (optimize) {
plugins = plugins.concat([
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
},
}),
// This plugins defines various variables that we can set to false
// in production to avoid code related to them from being compiled
// in our final bundle
new webpack.DefinePlugin({
__SERVER__: false,
__DEVELOPMENT__: false,
__DEVTOOLS__: false,
'process.env': {
BABEL_ENV: JSON.stringify(env)
}
})
]);
}
// Config
module.exports = {
debug: !optimize,
devtool: optimize ? false : 'eval',
entry: {
main: './static/js/main.js',
admin: './static/js/admin.js'
},
plugins: plugins,
output: {
path: './static/build/js/',
filename: '[name].js'
},
externals: [{
'handlebars/runtime': {
root: 'Handlebars',
amd: 'handlebars/runtime',
commonjs2: 'handlebars/runtime',
commonjs: 'handlebars/runtime'
},
'handlebars': {
root: 'Handlebars',
amd: 'Handlebars',
commonjs: 'handlebars',
commonjs2: 'handlebars'
}
}],
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
include: __dirname + '/static/js',
query: {
presets: ['es2015'],
plugins: ['transform-es2015-arrow-functions']
}
},
{
test: /\.json$/,
loader: 'json',
include: __dirname + '/static'
},
{
test: /\.hbs$/,
loader: 'handlebars',
include: __dirname + '/static/js',
query: {
extensions: ['.hbs'],
// Don't try to resolve helpers and partials in node_modules. Handlebars loader tries to resolve
// even simple variables as helpers/partials, so event {{url}} gets fucked up because there's a Node
// module called "url"
exclude: 'node_modules',
helperDirs: __dirname + '/static/js/helpers',
debug: false
}
}
]
},
resolve: {
alias: {
'underscore': 'lodash',
// Get Flickity working
'eventEmitter/EventEmitter': 'wolfy87-eventemitter/EventEmitter',
'get-style-property/get-style-property': 'desandro-get-style-property/get-style-property',
'matches-selector/matches-selector': 'desandro-matches-selector/matches-selector',
'classie/classie': 'desandro-classie/classie'
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment