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

Add support for import assertions and non-JS module types #2682

Closed
anil9973 opened this issue Nov 18, 2022 · 3 comments
Closed

Add support for import assertions and non-JS module types #2682

anil9973 opened this issue Nov 18, 2022 · 3 comments

Comments

@anil9973
Copy link

anil9973 commented Nov 18, 2022

Feature Use Case
Importing JSON, CSS, and HTML according to upcoming JavaScript and HTML standards.

CSS modules are standardized (In the HTML spec here) and shipping in Chrome and Edge since v93. Firefox and Webkit were involved in the development of import assertions as a result of working out CSS modules, and are both currently implementing the prerequisites for CSS modules (constructible stylesheets and adopedStyleSheets).

This means that we'll be able to import JSON, CSS and HTML into JavaScript natively, and ideally in bundlers without any specific loaders (or perhaps a "web standard loader" that implements all web-native module types?):

import styles from './styles.css' assert {type: 'css'};

// or

const styles = await import('./styles.css', {assert: {type: 'css'}});

It is very helpful for shadowDOM web custom elements.

know more at
web.dev/css-module-scripts

@anil9973
Copy link
Author

Rollup v3.3.0 add support for import assertions.

[v3.0] Basic support for import assertions #4646

@anil9973 anil9973 changed the title Add support for for import assertions and non-JS module types Add support for import assertions and non-JS module types Nov 18, 2022
@evanw
Copy link
Owner

evanw commented Dec 3, 2022

Import assertions are already supported. They are passed through to the output unmodified so that the browser can interpret them (unless you tell esbuild that they are unsupported, in which case esbuild will remove them):

$ echo "import {default as foo} from './foo.json' assert {type: 'json'}" | esbuild
import { default as foo } from "./foo.json" assert { type: "json" };

$ echo "import {default as foo} from './foo.json' assert {type: 'json'}" | esbuild --supported:import-assertions=false
import { default as foo } from "./foo.json";

@anilkumarum
Copy link

anilkumarum commented Dec 6, 2022

Thanks for reply.
My issue is solved and it work perfect.
please close this issue.

@evanw evanw closed this as completed Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants