Skip to content

Commit 9892516

Browse files
committed
feat: implement "configureLoaderRule" method
1 parent 0facc4d commit 9892516

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/WebpackConfig.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class WebpackConfig {
100100
this.eslintLoaderOptionsCallback = () => {};
101101
this.tsConfigurationCallback = () => {};
102102
this.handlebarsConfigurationCallback = () => {};
103+
this.loaderConfigurationCallbacks = {
104+
'eslint': () => {},
105+
};
103106

104107
// Plugins options
105108
this.cleanWebpackPluginPaths = ['**/*'];
@@ -716,6 +719,18 @@ class WebpackConfig {
716719
});
717720
}
718721

722+
configureLoaderRule(name, callback) {
723+
if (!(name in this.loaderConfigurationCallbacks)) {
724+
throw new Error(`Loader "${name}" is not configurable. Either open an issue or a pull request.`);
725+
}
726+
727+
if (typeof callback !== 'function') {
728+
throw new Error('Argument 2 to configureLoaderRule() must be a callback function.');
729+
}
730+
731+
this.loaderConfigurationCallbacks[name] = callback;
732+
}
733+
719734
useDevServer() {
720735
return this.runtimeConfig.useDevServer;
721736
}

lib/config-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,13 @@ class ConfigGenerator {
357357
}
358358

359359
if (this.webpackConfig.useEslintLoader) {
360-
rules.push({
360+
rules.push(applyOptionsCallback(this.webpackConfig.loaderConfigurationCallbacks['eslint'], {
361361
test: /\.jsx?$/,
362362
loader: 'eslint-loader',
363363
exclude: /node_modules/,
364364
enforce: 'pre',
365365
options: eslintLoaderUtil.getOptions(this.webpackConfig)
366-
});
366+
}));
367367
}
368368

369369
if (this.webpackConfig.useTypeScriptLoader) {

0 commit comments

Comments
 (0)