ember-scoped-css 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,7 @@ This build tool can emit CSS in a `@layer`.
48
48
 
49
49
  - Vite
50
50
  - V2 addons with `@embroider/addon-dev` @ v8+ (or similar)
51
+ - V2 addons / libraries built with rolldown or tsdown (e.g. via [`@nullvoxpopuli/ember-rolldown`](https://github.com/NullVoxPopuli/ember.nvp/tree/main/packages/rolldown))
51
52
  - For [hbs, broccoli, or webpack-based builds, view this version of the docs](https://github.com/auditboard/ember-scoped-css/tree/hbs-classic-and-webpack-support)
52
53
  - For [bugfixes for the pre-ember-scoped-css-1.0 code, PR here](https://github.com/auditboard/ember-scoped-css/tree/hbs-classic-and-webpack-support)
53
54
 
@@ -55,6 +56,7 @@ This build tool can emit CSS in a `@layer`.
55
56
  | -------- | ----------- | ---------------------- | --- |
56
57
  | vite | >= 1.0.0 | 🚫 | [main][docs-main]
57
58
  | gjs / gts library (no hbs) | >= 1.0.0 | 🚫 | [main][docs-main]
59
+ | rolldown / tsdown | >= 3.1.0 | 🚫 | [main][docs-main]
58
60
  | webpack | <= 0.24.3 | <= 10.0.0 | [0.24.3][docs-2]
59
61
  | hbs | <= 0.24.3 | <= 10.0.0 | [0.24.3][docs-2]
60
62
  | ember-template-imports@v4 or babel-plugin-ember-template-compilation@2.2.5+ | 0.19.0 | 10.0.0 | [0.19][docs-3] - [0.24][docs-2]
@@ -78,7 +80,7 @@ npm install --save-dev ember-scoped-css
78
80
  Configuration happens in multiple locations to take over the need portion of your build steps.
79
81
 
80
82
  - `vite.config.*`
81
- - `rollup.config.*`
83
+ - `rollup.config.*` (or `rolldown.config.*` / `tsdown.config.*`)
82
84
  - `babel.config.*`
83
85
 
84
86
  #### Vite
@@ -149,6 +151,42 @@ plugins: [
149
151
 
150
152
  - `layerName: string` - Wrap your CSS in a `@layer` with this given name
151
153
 
154
+ #### Rolldown / tsdown
155
+
156
+ The rollup plugin also works under [rolldown](https://rolldown.rs/) and [tsdown](https://tsdown.dev/).
157
+ For a v2 library built with tsdown via [`@nullvoxpopuli/ember-rolldown`](https://github.com/NullVoxPopuli/ember.nvp/tree/main/packages/rolldown),
158
+ the whole setup lives in `tsdown.config.js` — no `babel.config.js` needed:
159
+
160
+ ```js
161
+ import { defineConfig } from 'tsdown';
162
+ import { ember } from '@nullvoxpopuli/ember-rolldown';
163
+ import { scopedCSS } from 'ember-scoped-css/rollup';
164
+ import { scopedCSS as scopedCssBabel } from 'ember-scoped-css/babel';
165
+
166
+ export default defineConfig({
167
+ entry: ['./src/index.ts'],
168
+ css: { inject: true },
169
+ plugins: [
170
+ ember({
171
+ babel: {
172
+ // only needed if you use scopedClass in module code
173
+ plugins: [scopedCssBabel()],
174
+ templateTransforms: [scopedCssBabel.template({})],
175
+ },
176
+ }),
177
+ scopedCSS(),
178
+ ],
179
+ });
180
+ ```
181
+
182
+ Notes:
183
+
184
+ - [`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) must be installed (it releases in lockstep with tsdown) — it bundles the scoped CSS into `dist/style.css`.
185
+ - `css: { inject: true }` keeps the `import './style.css'` statement in the built JS, so consuming apps load the CSS through the module graph. Without it the CSS is emitted but nothing imports it.
186
+ - If your library has its own `babel.config.js`, configure the plugins there instead (see [Babel](#babel) below) — `ember()` picks the config file up automatically.
187
+
188
+ This supports co-located `.css` files, inline `<style scoped>` blocks, and the `scopedClass` pseudo-helper, same as the other build tools.
189
+
152
190
  #### Babel
153
191
 
154
192
  In your `babel.config.*`, add the plugins:
@@ -181,7 +219,7 @@ There are two plugins, but you made only need one:
181
219
  ##### Configuration Options (`scopedCSS.template()`)
182
220
 
183
221
  - `layerName: string` - Wrap your CSS in a `@layer` with this given name
184
- - `additionalRoots: string[]` - When you want to procss more folders. For example you want to support pods structure
222
+ - `additionalRoots: string[]` - Process additional directories, for example pods or directories from other packages in a monorepo.
185
223
 
186
224
  ### TypeScript
187
225
 
@@ -194,7 +232,25 @@ Requires
194
232
  - @glint/template 1.7.0 or higher
195
233
  - @glint/tsserver-plugin 2.0.5 or higher
196
234
 
197
- In `types/index.d.ts` (or similar for apps) or `unpublished-development-types/index.d.ts` (for libraries), we'll declaration merge merge the known attributes for the `<style>` tag:
235
+ Add `ember-scoped-css/types` to the [`types`](https://www.typescriptlang.org/tsconfig#types) array in your `tsconfig.json`:
236
+
237
+ ```jsonc
238
+ {
239
+ "compilerOptions": {
240
+ "types": ["ember-scoped-css/types"]
241
+ }
242
+ }
243
+ ```
244
+
245
+ If your project doesn't use `compilerOptions.types` (note that specifying it disables automatic inclusion of `@types/*` packages), you can instead import the declarations from a type-declaration file that is included in your project — `types/index.d.ts` (or similar for apps) or `unpublished-development-types/index.d.ts` (for libraries):
246
+
247
+ ```ts
248
+ import 'ember-scoped-css/types';
249
+ ```
250
+
251
+ <details><summary>What <code>ember-scoped-css/types</code> provides</summary>
252
+
253
+ It declaration-merges the known attributes for the `<style>` tag:
198
254
 
199
255
  ```ts
200
256
  import '@glint/template';
@@ -207,6 +263,8 @@ declare global {
207
263
  }
208
264
  ```
209
265
 
266
+ </details>
267
+
210
268
  ### template-lint
211
269
 
212
270
  If you use [ember-template-lint](https://github.com/ember-template-lint/ember-template-lint) for linting the `<template>...</template>` regions of your components, you'll need to allow the `<style>` attribute to be used. The easiest way is to disable the [`no-forbidden-elements`](https://github.com/ember-template-lint/ember-template-lint/blob/main/docs/rule/no-forbidden-elements.md) rule: