Skip to content

Plan for import assertions and non-JS module types #3799

@justinfagnani

Description

@justinfagnani

Feature Use Case

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

Feature Proposal

Import assertions are a Stage 3 TC39 proposal to allow source code to assert that an import has a specific type (among other possible assertions): https://github.com/tc39/proposal-import-assertions

Assertions are being added to unblock the JSON, CSS, and HTML modules proposals which allow importing those file type as JavaScript modules.

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'}});

I filed an issue on Acorn for import assertion support.

The JSON and CSS proposals are furthest along, with implementations in Chromium behind flags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions