unplugin icon indicating copy to clipboard operation
unplugin copied to clipboard

Add `resolve` to `this` context

Open sxzz opened this issue 2 years ago • 4 comments

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~~

sxzz avatar Jan 19 '22 18:01 sxzz

@antfu Would you accept a PR adding this for everything but webpack?

calebeby avatar Jul 01 '22 03:07 calebeby

Yeah, I think we can have it.

sxzz avatar Mar 15 '23 16:03 sxzz

Any updates to this? would have been a great addition.

lxsmnsyc avatar Feb 13 '24 14:02 lxsmnsyc

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);
                    }
                },
            );
        },
    );
},

tjx666 avatar Mar 22 '24 03:03 tjx666