unplugin
unplugin copied to clipboard
Add `resolve` to `this` context
ESBuild: https://esbuild.github.io/plugins/#resolve Rollup: https://rollupjs.org/guide/en/#thisresolve Rspack: ~~wait PR https://github.com/web-infra-dev/rspack/pull/2080~~
@antfu Would you accept a PR adding this for everything but webpack?
Yeah, I think we can have it.
Any updates to this? would have been a great addition.
So, what'is the best practice getting get the resolved id in webpack now? Following is chatgpt answer:
webpack(compiler) {
compiler.hooks.normalModuleFactory.tap(
`${name}.normalModuleFactory`,
(normalModuleFactory) => {
normalModuleFactory.hooks.afterResolve.tapAsync(
`${name}.normalModuleFactory.afterResolve`,
(data, callback) => {
const importer = data.contextInfo.issuer;
const resolvedId = data.createData.resource;
if (importer && resolvedId) {
parseModule(resolvedId, importer).then(() => {
// eslint-disable-next-line promise/no-callback-in-promise
callback(null);
});
} else {
callback(null);
}
},
);
},
);
},