README
This is a Webpack plugin that allows you to override module imports based on file paths. It's called OverrideResolver and you can use it by importing the necessary packages and creating a new instance of the class. Here's an example of how to use it:
const OverrideResolver = require('path/to/OverrideResolver');
const overrideResolver = new OverrideResolver(
// An array of base source roots to search for module imports
['./src'],
// An array of override source roots to search for overrides
['./src/overrides'],
// An array of directory names that can be overridden
['myDirectory'],
// An array of directories to exclude from the override
['node_modules'],
// An object that maps a module name to an override file path
{ 'myModule': './src/overrides/myModule.js' },
// An array of objects that specify import guard rules
[
{
// The directory to guard
ward: './src/myDirectory',
// An array of whitelisted directories that can be imported
whitelist: ['./src/allowedDirectory']
}
]
);
module.exports = {
// ...
resolve: {
plugins: [overrideResolver]
}
// ...
}
Here's what each argument to the OverrideResolver constructor does:
baseSourceRoots: An array of directory names to search for module imports.
overrideSourceRoots: An array of directory names to search for overrides.
overridableDirectories: An array of directory names that can be overridden.
excludedRequestDirectories: An array of directories to exclude from the override.
additionalDependencies: An object that maps a module name to an override file path.
importGuard: An array of objects that specify import guard rules.
After creating an instance of OverrideResolver, you can add it to your webpack config by including it in the resolve.plugins array.