useful codes you can copy and use in webpack.monkey.js file.
In real project I copy some of them in other file and use require function:
Add webpack plugin
function addPlugin(webpackConfig, plugin) {
webpackConfig.plugins.push(plugin);
}
function findRule(webpackConfig, callback) {
const rules = webpackConfig.module.rules[1].oneOf;
const index = rules.findIndex(callback);
if (index === -1) throw Error('Loader not found');
return rules[index]
}
requirement: findRule
function findBabelRule(webpackConfig, plugins) {
// find babel rule
const babelRule = findRule(webpackConfig, (rule) => {
return ('' + rule.test === '' + /\.(js|jsx)$/)
});
return babelRule;
}