Conditionally spread object and array items.
npm i cond-spread
yarn add cond-spread
First import the cond-spread
package:
import condSpread from 'cond-spread';
condSpread
is a curried function that takes a boolean, and an object or array. It returns the object or array is the boolean was true, otherwise it returns an empty object or array.
...
import condSpread from 'cond-spread';
export default (env, { mode }) => {
const isDev = condSpread(mode === 'development');
const isProd = condSpread(mode === 'production');
return {
plugins: [
...isDev([new BundleAnalyzerPlugin()]),
...isProd([
new CleanWebpackPlugin(),
new CopyPlugin(),
]),
],
...isDev({
devServer: {
hot: true,
},
}),
};
};