dynamic-resolve-webpack-plugin
v2.0.0
Published
a webpack plugin for dynamic resolve paths
Downloads
9
Readme
A webpack plugin for dynamic resolve paths, you can use it to resolve paths dynamically.
Getting Started
- Install as devDependencies:
pnpm install dynamic-resolve-webpack-plugin
- custom dynamic resolve function:
const targetDir = path.resolve('./custom-icon');
const baseDir = require
.resolve('@ant-design/icons-svg')
.replace(/lib\/index\.js/, 'es/asn/');
const scopeList = list.map((file) => path.join(baseDir, file));
function dynamic(request) {
const innerPath = request.request || request.path;
if (scopeList.includes(innerPath)) {
request.path = path.join(targetDir, innerPath.split(baseDir)[1]);
return request;
}
return request;
}
- then add it to webpack resolve plugin config:
config.resolve.plugins.push(
new DynamicResolvePlugin({
dynamic,
})
);
Ensure This Plugin is used in webpack resolve plugins
Options
type IOptions = {
source: string; // enhanced-resolve register hook, default value is `file`
target: string; // next hooks to call, default value is `final-file`
dynamic: <T>(request: T) => T; //dynamic function, you can do whatever you want with callback parameter request, and you should return it back after modified.
};