Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active October 28, 2018 17:02
Show Gist options
  • Save kavitshah8/1a27e3207c6ecaf87220cc765ffb6257 to your computer and use it in GitHub Desktop.
Save kavitshah8/1a27e3207c6ecaf87220cc765ffb6257 to your computer and use it in GitHub Desktop.
Webpack Configs
var config = {
entry: {
app: addEntryPoint('./src/Router.jsx'),
vendor: ['lodash', 'react', 'react-router', 'react-dom', 'rc-slider']
},
output: {
path: options.devServer ? path.join( __dirname, 'public', 'js') : 'public',
filename: '[name]-[chunkhash].js',
publicPath: '',
},
plugins: [
new CommonsChunkPlugin({
name: 'commons',
filename: 'commons-[hash].js',
chunks: ['vendor', 'app']
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join( __dirname, 'src', 'index.tpl.html'),
chunks: ['commons', 'app']
}),
new CopyWebpackPlugin([{
from: path.join(__dirname, 'src', 'assets', 'images'),
to: 'images'
}])
].concat(plugins)
};
function addEntryPoint(entryPoint) {
var entry = ['babel-polyfill', entryPoint];
if (options.hotReload) {
entry = [
'webpack-dev-server/client?http://localhost:3443',
'webpack/hot/dev-server'
].concat(entry);
}
return entry;
}
var config = {
entry: addEntryPoint('./src/Router.jsx'),
output: {
path: options.devServer ? path.join( __dirname, 'public', 'js') : 'public',
filename: 'build.js',
publicPath: '',
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join( __dirname, 'src', 'index.tpl.html')
}),
new CopyWebpackPlugin([
{from: path.join(__dirname, 'src', 'assets', 'images'), to: 'images'}
])
].concat(plugins)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment