Runtime externals don't work in webpack
Environment
unplugin 1.0.1
Reproduction
https://github.com/ef4/unplugin-bug-repro (edited to add)
Describe the bug
This code:
https://github.com/unjs/unplugin/blob/c29ef3e6d39bf65da63fd43269f030c64587ed4b/src/webpack/index.ts#L126-L128
tries to locate external modules on the filesystem at build time, and if they're not found it introduces empty virtual modules for them.
But this means we cannot actually use externals the way that both webpack and rollup typically understand externals: they're supposed to get resolved at runtime. Whether they existed during build time is not supposed to matter.
Expected behavior:
- If my
resolveIdhook returnsfalse, the original import statement should be left alone in the output, so that it will be resolved at runtime. - If my
resolveIdhook returns{ external: true, id: 'xyz' }, the original import statement gets replaced with an import statement for'xyz', and that redirected import statement will get resolved at runtime.
Actual behavior:
- In both the above cases, the original import is replaced with an empty virtual module, and no runtime resolution ever happens.
Additional context
No response
Logs
No response
Could you provide a duplicate? I can't debugger
Here is a reproduction: https://github.com/ef4/unplugin-bug-repro
It contains both rollup and webpack configs, so you can see that the rollup build works correctly and the webpack build fails at runtime.