A Rollup plugin that enables import assertions (formerly import attributes) for CSS and JSON modules, allowing developers to import stylesheets as constructible stylesheets and JSON modules with type assertions. Version 3.0.1 works with Rollup 3+ and requires acorn-import-assertions as a peer dependency. It transforms CSS imports into CSS module scripts for use with adoptedStyleSheets. Compared to alternatives like @rollup/plugin-json or raw CSS imports, this plugin provides standardized import assertion syntax as per the TC39 proposal, but only supports static imports with literal assertion values. It does not handle dynamic imports with dynamic expressions. The package ships TypeScript definitions.
npm install rollup-plugin-import-assertVerified import paths — ran on the pinned version, not inferred.
Shows how to install, configure Rollup with acorn-import-assertions and the plugin, and use import assertions for CSS modules.
Upgrade Rollup to version 3 or later, or use older versions of this plugin (not specified).
Use static imports or ensure the import path is a string literal for assertions to work.
Watch for future updates; may need to use 'with' syntax in newer versions.
Install construct-style-sheets-polyfill for cross-browser support.
npm install -D acorn-import-assertions
Change import to: import { importAssertionsPlugin } from 'rollup-plugin-import-assert'Use a static import with assert syntax or avoid dynamic expressions in the import path.