Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize new URL("./thing.png", import.meta.url) #5473

Closed
mischnic opened this issue Dec 14, 2020 · 7 comments · Fixed by #5846
Closed

Recognize new URL("./thing.png", import.meta.url) #5473

mischnic opened this issue Dec 14, 2020 · 7 comments · Fixed by #5846

Comments

@mischnic
Copy link
Member

🙋 feature request

As introduced by Webpack.

🤔 Expected Behavior

Behave like import ... from "url:./thing.png".

💁 Possible Solution

Should be implemented here: https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/src/visitors/dependencies.js

🔦 Context

This isn't related to new Worker(new URL(...)): #5430, because we need to detect the environment context web-worker in that case.

@hsablonniere
Copy link

Hello @mischnic 😉

I’m not sure you will need help on this but I implemented this as a Rollup plugin so I would be glad to participate if necessary

@mischnic
Copy link
Member Author

mischnic commented Dec 15, 2020

Thanks! I haven't looked into this further but I think we already have all the needed architecture (copying/hashing files, ...) and this is essentially an alias for url: imports.

@devongovett
Copy link
Member

Should that always create a dependency or only when used in contexts that already create one (eg workers). What if you want to create a URL relative to the actual bundle as would happen today?

@mischnic
Copy link
Member Author

If we go by the principle "executing the source should behave just like executing the Parcel output", it should always be processed.

@devongovett
Copy link
Member

We'd need to change the dependency based on where it's used though in order for the correct context to be applied, which may be hard.

eg

let url = new URL("./worker.js", import.meta.url);
let worker = new Worker(url);

And what happens if the url is used in multiple places?

@mischnic
Copy link
Member Author

My suggestion was:

  1. recognize new Worker(new URL(...)): WebWorkers: Support new Worker( new URL() ) syntax #5430 (and worklet...)
  2. treat everything that's left as url: import (this issue)

Otherwise, there is no way to easily determine how it's used.

@ProLoser
Copy link

@devongovett are you still looking into this? Do you have a WIP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants