Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Last active August 5, 2016 16:19
Show Gist options
  • Save daniellizik/0a166f32e478d75d12db0e5f17cc2bea to your computer and use it in GitHub Desktop.
Save daniellizik/0a166f32e478d75d12db0e5f17cc2bea to your computer and use it in GitHub Desktop.
webpack config with dynamic multiple entry
// for HMR, don't add webpack/hot/devserver or whatever to config, just use --hot --inline in cli args
// https://github.com/webpack/webpack/issues/1151
'use strict';
const prod = /prod|production/i.test(process.env.NODE_ENV);
const webpack = require('webpack');
const env = process.env.NODE_ENV;
const dev = /dev|development/i.test(env);
const prod = /prod|production/i.test(env);
const uglyConf = {
compress: {
warnings: false
},
output: {
comments: false
}
};
const output = (name) => {
if (dev)
return { path: './', publicPath: '/', filename: name }
else if (staging || prod || !env)
return { path: './dist', filename: name }
}
let config = {
entry: {
'htmlsave.bundle': '',
'page.bundle': ''
},
output: output('[name].js'),
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
{ test: /\.html$|\.txt$|\.css$/, loader: 'raw' }
]
},
plugins: prod ? [
new webpack.optimize.UglifyJsPlugin(uglyConf)
] : []
}
if (dev)
config.target = 'web';
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment