Skip to content

Commit

Permalink
feat: implement "configureLoaderRule" method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 1, 2019
1 parent 0facc4d commit 9892516
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class WebpackConfig {
this.eslintLoaderOptionsCallback = () => {};
this.tsConfigurationCallback = () => {};
this.handlebarsConfigurationCallback = () => {};
this.loaderConfigurationCallbacks = {
'eslint': () => {},
};

// Plugins options
this.cleanWebpackPluginPaths = ['**/*'];
Expand Down Expand Up @@ -716,6 +719,18 @@ class WebpackConfig {
});
}

configureLoaderRule(name, callback) {
if (!(name in this.loaderConfigurationCallbacks)) {
throw new Error(`Loader "${name}" is not configurable. Either open an issue or a pull request.`);
}

if (typeof callback !== 'function') {
throw new Error('Argument 2 to configureLoaderRule() must be a callback function.');
}

this.loaderConfigurationCallbacks[name] = callback;
}

useDevServer() {
return this.runtimeConfig.useDevServer;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ class ConfigGenerator {
}

if (this.webpackConfig.useEslintLoader) {
rules.push({
rules.push(applyOptionsCallback(this.webpackConfig.loaderConfigurationCallbacks['eslint'], {
test: /\.jsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
enforce: 'pre',
options: eslintLoaderUtil.getOptions(this.webpackConfig)
});
}));
}

if (this.webpackConfig.useTypeScriptLoader) {
Expand Down

0 comments on commit 9892516

Please sign in to comment.