One config file for development, test and production. ✨
Useful when you want to have simplicity your configuration pipeline.
Work with a webpack-merge.
{
development: { // <--
stats: {
colors: true,
},
},
module: {},
plugins: [],
}
Output for process.env.NODE_ENV === 'development':
{
stats: {
colors: true,
},
module: {},
plugins: [],
}
Output for process.env.NODE_ENV === 'production':
{
module: {},
plugins: [],
}
{
development: { // <--
stats: {
colors: true,
warnings: true,
},
},
module: {
rules: [
{
include: [paths.dir.app],
use: [
{
loader: 'css-loader',
options: {
modules: true,
development: { // <--
minimize: false,
},
}
},
],
},
],
},
plugins: [
new Dotenv(config.dotenv),
{development: () => { // <--
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
return [
new HardSourceWebpackPlugin(),
]
}},
{production: [ // <--
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HashedModuleIdsPlugin(),
]},
],
}
Output for process.env.NODE_ENV === 'development':
{
stats: {
colors: true,
warnings: true,
},
module: {
rules: [
{
include: [paths.dir.app],
use: [
{
loader: 'css-loader',
options: {
modules: true,
minimize: false,
}
},
],
},
],
},
plugins: [
new Dotenv(config.dotenv),
new HardSourceWebpackPlugin(),
],
}
{
presets: ['@babel/preset-env'],
plugins: [
[
'emotion',
{
hoist: true,
development: { // <--
sourceMap: true,
hoist: false,
},
},
],
'react-hot-loader/babel',
{development: ['@babel/plugin-transform-react-jsx-source']}, // <--
{production: [ // <--
'transform-react-remove-prop-types',
]},
],
}
Output for process.env.NODE_ENV === 'production':
{
presets: ['@babel/preset-env'],
plugins: [
[
'emotion',
{
hoist: true,
},
],
'react-hot-loader/babel',
'transform-react-remove-prop-types',
],
}
$ npm install config-reducer
or
$ yarn add config-reducer
Copy and paste ;)
const { devProdReducer } = require('config-reducer')
module.exports = devProdReducer({
development: {
devtool: 'inline-cheap-module-source-map',
mode: 'development',
},
devtool: 'source-map',
name: 'client',
target: 'web',
// ...
})
const configReducer = require('config-reducer').default
const commonConfig = {
development: {
stats: {
colors: true,
warnings: true,
},
},
// ... config -> go to example 2
}
const result = configReducer(commonConfig, process.env.NODE_ENV, [
'development',
'production',
])
const configReducer = require('config-reducer').default
module.exports = api => {
const babelConfig = {
presets: ['@babel/preset-env', '@babel/preset-react'],
// ... config -> go to example 3
}
return configReducer(babelConfig, api.env(), [
'development',
'production',
'test',
])
}
const { devReducer } = require('config-reducer')
module.exports = devReducer({
development: {
devtool: 'inline-cheap-module-source-map',
mode: 'development',
},
devtool: 'source-map',
name: 'client',
target: 'web',
// ... config -> go to example 2
})
const { prodReducer } = require('config-reducer')
const { testReducer } = require('config-reducer')
const { devProdReducer } = require('config-reducer')
module.exports = devReducer({
development: {
devtool: 'inline-cheap-module-source-map',
mode: 'development',
},
output: {
production: {
filename: '[name].[chunkhash].js',
},
filename: '[name].js',
},
devtool: 'source-map',
name: 'client',
target: 'web',
// ... config -> go to example 2
})
const { devTestReducer } = require('config-reducer')
const { prodTestReducer } = require('config-reducer')
const { devProdTestReducer } = require('config-reducer')
Module steps:
- find and prepare (deep duplicate) -
input
- apply to parent -
reducer
- delete references -
cleanup
devProdReducer(input, reducer, cleanup)
Type: Object|Array
Required: true
Your configuration object or array variants:
The function warrant is intended to be postponed until the configurations are reduced. Thanks to this, we do not have to import modules from which we do not use:
1 Install module for development mode
$ yarn add --dev hard-source-webpack-plugin
2 Configuration
{
plugins: [
new Dotenv(config.dotenv),
{development: () => {
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
return [
new HardSourceWebpackPlugin(),
]
}},
],
}
3 Compile production version - work fine, without hard-source-webpack-plugin
$ yarn prod
Useful in Dockerfile.
Type: string
Default: process.env.NODE_ENV
This key will be merged.
Type: boolean|string|Array<string>
Default: true
These keys will be deleted.
- false: do nothing
- true: delete reducer
- string: delete key
- array of strings: delete keys
- array/object reducer
- reducer in reducer / nested reducers
- alias ex: test = _test
If you find a bug, please file an issue on issue tracker on GitHub.
MIT