web
web copied to clipboard
[rollup-plugin-import-meta-assets]: The output result was wrapped twice with `new URL()`
I was using the plugin in vite and here's the source code:
and it result as follows that confused me:
Maybe there's something wrong, please help, thanks!
Here's my vite configuration
Is this just confusing code or it's broken too?
It's indeed confusing, but IIRC we process all import.meta.url
and add extra URL wrapper to resolve it relatively to the original file location after bundling, where the JS file location often changes, so the extra wrapper is necessary in a general case.
It's broken in rspack, but I think of it as a flaw of rspack after your explanation, I have filed an issue to their team.
Oh, actually, I just looked once more at the screenshot. After bundling the wrapper should contain the original file name, and not just import.meta.url
twice, e.g. smth like this - a rewritten example from my app bundle, but should be clear I think:
new URL("./../../../assets/images/",new URL("./node_modules/path/to/my/original/file.js",import.meta.url).href).href;
Looks like smth is not working correctly in Vite. Maybe our plugin is not Vite compatible, not sure if anyone ever tested it with it. IIRC, Vite plugins are an extension of rollup API and should be working fine with most of rollup plugins, but I can imagine it's not always guaranteed.
emm, actually the output result is working fine in webpack where the double URL would be replaced with the real path. 🤔🤔
emm, actually the output result is working fine in webpack where the double URL would be replaced with the real path. 🤔🤔
if it's working, then probably your JS files remain on the same location in the folder structure, otherwise won't work, but if so, you might not need this plugin, I think the main goal of it is to be able to bundle JS and extract assets
on a different note: why do you need this plugin in Vite? I think Vite has it's own assets handling guidelines?
in vite's library mode,all assets will be inlined,which causes a long time cost.unfortunately It doesn't support to extract assets now...
Pure Rollup gives me:
const program_path = new URL(new URL('asset/program.wasm', import.meta.url).href, import.meta.url);
The second URL constructor looks pointless to me.
Pure Rollup gives me:
const program_path = new URL(new URL('asset/program.wasm', import.meta.url).href, import.meta.url);
The second URL constructor looks pointless to me. Does it mean you can remove the double wrap?🤔