question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support new URL("./image.png", import.meta.url) Asset modules

See original GitHub issue

Webpack 5 support new URL("./image.png", import.meta.url) as asset modules.

Can vite support it?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jiangfengmingcommented, Jan 27, 2021

@jiangfengming What’s difference with @web/rollup-plugin-import-meta-assets?

example: https://modern-web.dev/docs/building/rollup-plugin-import-meta-assets/#examples

That plugin just doesn’t work with vite.

If put it into plugins field, the code would be transformed into new URL(import.meta.ROLLUP_FILE_URL_1, import.meta.url), but import.meta.ROLLUP_FILE_URL_1 is undefined at runtime.

If put it into build.rollupOptions.plugins section, the generated code would be something like new URL(new URL("foo.688baecb.png",t.url).href,t.url)', but t.url(import.meta.url) is undefined` in production build. So it will fail to construct URL because lack of origin.

And @web/rollup-plugin-import-meta-assets doesn’t obey build.assetsInlineLimit option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asset Modules - webpack
To exclude assets that came from new URL calls from the asset loaders add ... path/to/asset', import.meta.url) , webpack creates an asset module...
Read more >
Building: Rollup Plugin Import Meta Assets - Modern Web
Rollup plugin that detects assets references relative to modules using patterns such as new URL('./assets/my-img.png', import.meta.url) .
Read more >
Bundling non-JavaScript resources - web.dev
Learn how to import and bundle various types of assets from ... image.png', import.meta.url)); ... module.wasm') with fetch(new URL('.
Read more >
Angular CLI and loading assets with import.meta.url causing ...
... new URL(',,/../assets/images/noimage.png', import.meta.url);. however I get an error. Not allowed to load local resource: file url here.
Read more >
Static Asset Handling - Vite
Importing Asset as URL #. Importing a static asset will return the resolved public URL when it is served: js import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found