{"library":"rollup-plugin-import-assert","title":"rollup-plugin-import-assert","description":"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.","language":"javascript","status":"active","last_verified":"Mon Apr 27","install":{"commands":["npm install rollup-plugin-import-assert"],"cli":null},"imports":["import { importAssertionsPlugin } from 'rollup-plugin-import-assert'","import { importAssertions } from 'acorn-import-assertions'","import { importAssertionsPlugin } from 'rollup-plugin-import-assert'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// Install: npm i -D rollup-plugin-import-assert acorn-import-assertions\n// rollup.config.js\nimport { importAssertionsPlugin } from 'rollup-plugin-import-assert';\nimport { importAssertions } from 'acorn-import-assertions';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    format: 'esm',\n    dir: 'dist',\n  },\n  acornInjectPlugins: [importAssertions],\n  plugins: [importAssertionsPlugin()],\n};\n\n// src/index.js\nimport styles from './styles.css' assert { type: 'css' };\nclass MyElement extends HTMLElement {\n  connectedCallback() {\n    this.attachShadow({ mode: 'open' }).adoptedStyleSheets = [styles];\n  }\n}\ncustomElements.define('my-element', MyElement);","lang":"javascript","description":"Shows how to install, configure Rollup with acorn-import-assertions and the plugin, and use import assertions for CSS modules.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}