Last active
January 27, 2019 15:29
-
-
Save schalkneethling/95c0f8322ba02220ecc482a260077068 to your computer and use it in GitHub Desktop.
Small tweak to Sean Larkins' LoadPresets script for Webpack
This file contains hidden or 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
// Original: https://github.com/TheLarkInn/webpack-workshop-2018/blob/feature/build-utils/build-utils/loadPresets.js | |
/** | |
* Usage: | |
* Use via NPM script | |
* Passing a single preset: | |
* "prod:compress": "npm run prod -- --env.presets compress", | |
* "prod:analyze": "npm run prod -- --env.presets analyze", | |
* Passing a multiple preset as a , separate list: | |
* "prod:compress-analyze": "npm run prod -- --env.presets compress,analyze", | |
*/ | |
const webpackMerge = require("webpack-merge"); | |
const applyPresets = (env = { presets: [] }) => { | |
let presets = env.presets || []; | |
// only split if the array has more than one item | |
if (presets.length) { | |
presets = presets.split(","); | |
} | |
/** @type {string[]} */ | |
const mergedPresets = [].concat(...[presets]); | |
const mergedConfigs = mergedPresets.map(presetName => | |
require(`./presets/webpack.${presetName}`)(env) | |
); | |
return webpackMerge({}, ...mergedConfigs); | |
}; | |
module.exports = applyPresets; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment