Last active
May 25, 2016 12:58
-
-
Save giacomorebonato/b571e91f548090b5aa43 to your computer and use it in GitHub Desktop.
Really basic Webpack configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack') | |
var path = require('path') | |
var NODE_ENV = process.env.NODE_ENV || 'development' | |
var conf = { | |
entry: { | |
'front-end': [path.join(__dirname, '/client/front/front-end.js')], | |
'back-end': [path.join(__dirname, '/client/back/back-end.js')] | |
}, | |
output: { | |
publicPath: '/public', | |
path: path.join(__dirname, '/public/' + NODE_ENV), | |
filename: '[name].js' | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }, | |
{ | |
test: /\.css$/, | |
exclude: /(node_modules|global)/, | |
loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]!postcss-loader' | |
}, | |
{ | |
test: /\.css$/, | |
loader: 'style!css!postcss', | |
include: /global/ | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.ProvidePlugin({ | |
fetch: 'imports?this=>global!exports?global.fetch!whatwg-fetch' | |
}), | |
new webpack.DefinePlugin({ | |
'process.env': { | |
'NODE_ENV': JSON.stringify(NODE_ENV) | |
} | |
}), | |
new webpack.DefinePlugin({ | |
NODE_ENV: JSON.stringify(NODE_ENV) | |
}), | |
new webpack.DefinePlugin({ | |
BASE_URL: JSON.stringify('http://localhost:3000') | |
}) | |
] | |
} | |
if (NODE_ENV === 'production') { | |
conf.plugins.push( | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { warnings: false }, | |
comments: false | |
}) | |
) | |
} else if (NODE_ENV === 'development') { | |
let onlyServer = 'webpack/hot/only-dev-server' | |
let mwClient = 'webpack-hot-middleware/client' | |
conf.entry['front-end'].splice(1, 0, onlyServer, mwClient) | |
conf.entry['back-end'].splice(1, 0, onlyServer, mwClient) | |
conf.plugins.push(new webpack.optimize.OccurrenceOrderPlugin()) | |
conf.plugins.push(new webpack.HotModuleReplacementPlugin()) | |
conf.plugins.push(new webpack.NoErrorsPlugin()) | |
conf.module.loaders.push({ test: /\.(js|jsx)$/, exclude: /(node_modules|server)/, loaders: ['react-hot', 'babel'] }) | |
} | |
module.exports = conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment