-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support import attributes #7648
Comments
I don't think we can use import assertions like we do pipelines. They are only meant for actual assertions, not transformations.
|
Now that the proposal was updated to be able to indicate the module type: import json from "./foo.json" with { type: "json" };
import("foo.json", { with: { type: "json" } }); But also to allow for any extensible object in the |
Import attribute could replace query parameters/be another source for |
🙋 feature request
Hello dear Parcel maintainers 👋
I'm opening this to propose supporting import assertions in parcel. I looked at the issues I don't think this was proposed yet (the only issue mentioning import assertions is #3757 but it doesn't talk about this).
Import assertions (see https://github.com/tc39/proposal-import-assertions) are getting added to the standard. And some tools already support it (like Deno).
As parcel tries to follow the regular JS spec as close as possible (for instance with workers
new Worker(new URL('worker.js', import.meta.url), {type: 'module'})
), this could be a good addition to parcel.So we could do
import file from "./version.json" assert { type: "json" }
in addition toimport file from "./version.json"
to import a JSON file.This could allow us to maybe do something like
import file from "./file" assert { type: "pipeline" }
in addition toimport file from "pipeline:./file"
for named pipelines.🤔 Expected Behavior
By default, this would only work for JSON, but we could also use it to apply the named pipeline to imports.
😯 Current Behavior
At the moment, parcel crashes on those:
💁 Possible Solution
SWC already supports it (playground) and babel too with the plugin
@babel/plugin-syntax-import-assertions
SWC
Input:
Output:
🔦 Context
One of the possibilities offered by this is to be able to re-use the same spec-compliant syntax across all bundlers (if others also decide to support this)
💻 Examples
The text was updated successfully, but these errors were encountered: