Skip to content

Instantly share code, notes, and snippets.

@drwpow
Last active December 4, 2017 00:06
Show Gist options
  • Save drwpow/aaf9e8e5475579aa9da8829ad60f7934 to your computer and use it in GitHub Desktop.
Save drwpow/aaf9e8e5475579aa9da8829ad60f7934 to your computer and use it in GitHub Desktop.
Separate Production/Development webpack Setups

Setup

yarn add webpack webpack-merge

File structure

Can be changed, but affects context and resolve.modules in webpack.common.js:

├── config
│  ├── webpack.common.js
│  ├── webpack.dev.js
│  └── webpack.prod.js
└── src
   └── …project
const webpack = require('webpack');
const path = require('path');
module.exports = {
context: path.resolve(__dirname, '..', 'src'),
entry: {
app: './app',
},
module: {
rules: [
{
test: /\.jsx?$/i,
use: 'babel-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'runtime',
}),
],
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules', path.resolve(__dirname, '..', 'src')],
},
};
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge.smart(common, {
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('development'),
},
}),
],
});
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge.smart(common, {
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
}),
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment