Skip to content

Repository files navigation

rule-inheritance-webpack-plugin

NPM Version

Inherit webpack rules from sub-packages. This plugin will copy all configuration from module.rules with additional include option to make rules are only applied in sub-packages. It will be useful when working with a monorepo with multiple webpack configurations.

Important

Currently we do not support multiple plugins coexists with different versions. If you are using this plugin in your monorepo, please ensure that all rule-inheritance-webpack-plugin are in the same version.

Usage

const RuleInheritancePlugin = require('rule-inheritance-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new RuleInheritancePlugin({
      // List of paths to sub-packages.
      packages: [
        path.resolve(__dirname, '../packages/package-a'),
        path.resolve(__dirname, '../packages/package-b')
      ],

      // [Optional] True to inherit rules recursively if sub-package also have
      // a RuleInheritancePlugin. Default value is `true`.
      recursive: true,

      // [Optional] Map from loader name to callback function which is called
      // when processing loader options. (e.g. Redirect to correct config path)
      callbacks: {},

      // [Optional] True to ignore builtin callback functions. Default value is
      // `false`.
      ignoreBuiltinCallbacks: false
    })
  ],
};

We have defiend some default callbacks to update loader options:

  • ts-loader: Update or add options.configFile to correct path.
  • babel-loader: Update or add options.cwd to correct path.

About

Inherit webpack rules from sub-packages for monorepo development.

Topics

Resources

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages