├── .editorconfig
├── .gitignore
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── public
├── data
│ ├── info.json
│ └── x.css
├── index.js
├── other.css
├── style.css
└── test-el
│ ├── test-el.wc.css
│ └── test-el.wc.js
├── rollup.config.js
├── rollup.dev.cjs.config.js
├── rollup.dev.esm.config.js
├── src
└── import-assert.ts
└── tsconfig.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | indent_style = space
8 | indent_size = 2
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | insert_final_newline = false
13 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | dist
4 | lib
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ### [3.0.1](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v3.0.0...v3.0.1) (2023-05-04)
6 |
7 | ## [3.0.0](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.3...v3.0.0) (2023-05-04)
8 |
9 |
10 | ### ⚠ BREAKING CHANGES
11 |
12 | * Bump deps because of rollup 3
13 |
14 | ### Features
15 |
16 | * upgrade to rollup 3 ([309e531](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/309e531288d2835e4bbcfddbccdb91eb7bcc7149))
17 |
18 | ### [2.1.3](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.2...v2.1.3) (2022-11-08)
19 |
20 | ### [2.1.2](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.0...v2.1.2) (2022-10-27)
21 |
22 | ### [2.1.1](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v2.1.0...v2.1.1) (2022-10-27)
23 |
24 | ## [2.1.0](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v1.1.2...v2.1.0) (2022-01-05)
25 |
26 |
27 | ### Features
28 |
29 | * cjs and esm support ([dc11dc1](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/dc11dc1a5940c2e301e0b5a918c9e0ee2ae1e2d5))
30 | * handle edgecases in dynamic imports ([b821aa6](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/b821aa623d23d317e35be629a76ac86401879787))
31 |
32 | ### [1.1.2](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v1.1.1...v1.1.2) (2022-01-04)
33 |
34 | ### [1.1.1](https://github.com/calebdwilliams/rollup-plugin-import-assert/compare/v1.1.0...v1.1.1) (2021-07-21)
35 |
36 |
37 | ### Bug Fixes
38 |
39 | * add keywords to package.json ([55cb627](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/55cb627bfd0f489acb715526ff91c352c4e5195e))
40 |
41 | ## 1.1.0 (2021-07-21)
42 |
43 |
44 | ### Features
45 |
46 | * initial commit ([428e1d3](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/428e1d378a2f6c1aeb34dbf7207656e41aba450a))
47 |
48 |
49 | ### Bug Fixes
50 |
51 | * properly escape temlate literals ([0223958](https://github.com/calebdwilliams/rollup-plugin-import-assert/commit/02239585e468acfc9ea7bd0f081748a0ebab10a1))
52 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright 2021 Caleb Williams
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rollup-plugin-import-assert
2 |
3 | 🍣 A Rollup plugin which enables [import assertions](https://github.com/tc39/proposal-import-assertions) for top-level CSS and JSON modules.
4 |
5 | ## Installation
6 |
7 | This package is available on the npm registry under the name `rollup-plugin-import-assert` and can be installed with npm, yarn or however else you consume dependencies.
8 |
9 | ### Example commands
10 |
11 | npm:
12 |
13 | ```zsh
14 | npm i -D rollup-plugin-import-assert
15 | ```
16 |
17 | yarn:
18 |
19 | ```zsh
20 | yarn add -D rollup-plugin-import-assert
21 | ```
22 |
23 | ## Usage
24 |
25 | Once the plugin is installed, you will also need to make sure you have the `acorn-import-assertions` package installed. You can then add both items to your Rollup configuration as below:
26 |
27 | ```javascript
28 | import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
29 | import { importAssertions } from 'acorn-import-assertions';
30 |
31 | export default {
32 | input: 'path/to/file.js'
33 | output: {
34 | format: 'esm',
35 | dir: 'lib' // only necessary to enable dynamic imports
36 | },
37 | acornInjectPlugins: [ importAssertions ],
38 | plugins: [ importAssertionsPlugin() ]
39 | }
40 | ```
41 |
42 | These two plugins will enable the import assertion syntax and behavior in your Rollup build. In your input file, you can import files using type assertions as follows:
43 |
44 | ```javascript
45 | import styles from './styles.css' assert { type: 'css' };
46 |
47 | class MyCustomElement extends HTMLElement {
48 | connectedCallback() {
49 | const root = this.attachShadow({ mode: 'open' });
50 | root.innerHTML = `
Hello world
`;
51 | root.adoptedStyleSheets = [ styles ];
52 | }
53 | }
54 |
55 | customElements.define('my-custom-element', MyCustomElement);
56 | ```
57 |
58 | Assuming valid CSS in `styles.css`, the contents of the the CSS will be transformed to use CSS module scripts for use with `DocumentOrShadowRoot.prototype.adoptedStyleSheets`. Currently this API only exists in Chrome, but a [polyfill exists](https://www.npmjs.com/package/construct-style-sheets-polyfill) to port the behavior back to IE11.
59 |
60 | ## Limitations
61 |
62 | This plugin will ignore dynamic imports with dynamic values, e.g.:
63 |
64 | ```js
65 | import(`./foo/${bar}.json`, { assert: { type: 'json' } }); // will be ignored
66 |
67 | const foo = './foo.json';
68 | import(foo, { assert: { type: 'json' } }); // will be ignored
69 | ```
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Test page
5 |
6 |
7 |
8 |
9 |
10 |
11 |