Skip to content

Instantly share code, notes, and snippets.

@rod-dot-codes
Created December 7, 2015 13:49
Show Gist options
  • Save rod-dot-codes/5537fee78c3da3b07f35 to your computer and use it in GitHub Desktop.
Save rod-dot-codes/5537fee78c3da3b07f35 to your computer and use it in GitHub Desktop.
Example Webpack configuration
import webpack from 'webpack';
import config from '../../config';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
const paths = config.get('utils_paths'),
globals = config.get('globals');
const webpackConfig = {
name : 'server',
target : 'web',
entry : {
app : [
paths.src('entry-points/client')
]
},
output : {
filename : 'index.js',
path : paths.dist('server'),
publicPath: 'http://127.0.0.1:4000/'
},
plugins : [
new webpack.DefinePlugin(config.get('globals')),
new webpack.optimize.DedupePlugin(),
new ExtractTextPlugin('styles.css'),
new HtmlWebpackPlugin({
template : paths.src('index.html'),
hash : true,
filename : 'index.html',
minify : globals.__PROD__,
inject : 'body'
})
],
resolve : {
extensions : ['', '.js', '.jsx'],
alias : config.get('utils_aliases')
},
module : {
preLoaders : [
{
test : /\.(js|jsx)$/,
loaders : ['eslint-loader'],
include : paths.project(config.get('dir_src'))
}
],
loaders : [
{
test: /\.(jpe?g|png|gif)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}, {
test: /\.(ttf|woff|woff2|svg|eot)(\?\S*)?$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]'
]
},
{
test : /\.(js|jsx)$/,
include : paths.project(config.get('dir_src')),
loaders : ['babel?optional[]=runtime']
},
{
test : /\.scss$/,
loader : 'style!css?sourceMap!ruby-sass'
},
{
test : /\.json$/,
loader : 'json'
}
]
},
eslint : {
configFile : paths.project('.eslintrc'),
failOnError : globals.__PROD__,
emitWarning : globals.__DEV__
}
};
// ----------------------------------
// Environment-Specific Defaults
// ----------------------------------
// if (globals.__PROD__) {
// webpackConfig.plugins.push(
// new webpack.optimize.UglifyJsPlugin({
// output : {
// 'comments' : false
// },
// compress : {
// 'unused' : true,
// 'dead_code' : true
// }
// })
// );
// }
export default webpackConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment