Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created August 22, 2016 13:31
Show Gist options
  • Save rafaelrinaldi/d0ed1b01a254ef6590cfff50bc8197f0 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/d0ed1b01a254ef6590cfff50bc8197f0 to your computer and use it in GitHub Desktop.
const webpack = require('webpack');
const PORT = process.env.PORT || 3000;
module.exports = {
devtool: 'eval',
entry: [
'babel-polyfill',
`webpack-dev-server/client?http://localhost:${PORT}`,
'webpack/hot/only-dev-server',
],
devServer: {
colors: true,
historyApiFallback: true,
hot: true,
inline: true,
port: PORT,
progress: true,
stats: 'errors-only'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development')
}
}),
]
};
/* eslint-disable prefer-es6-imports */
const merge = require('webpack-merge');
const commonConfig = require('./build/common');
const devConfig = require('./build/development');
const prodConfig = require('./build/production');
const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV || !NODE_ENV.length) {
throw new Error('Either not specified or invalid `NODE_ENV`');
}
const isDev = /dev/i.test(NODE_ENV);
const isProd = /prod/i.test(NODE_ENV);
if(isDev) {
module.exports = merge(commonConfig, devConfig);
} else if(isProd) {
module.exports = merge(commonConfig, prodConfig);
} else {
console.error('"%s" is not a valid `NODE_ENV` value', NODE_ENV);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment