ember-scoped-css 3.1.0 → 3.3.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
 
@@ -458,20 +496,27 @@ const Outer = <template>
458
496
 
459
497
  ### Passing classes as arguments to a component
460
498
 
461
- There is a `scopedClass` helper that you can use to pass a class name as an argument to a component. The helper takes a class name and returns a scoped class name. `scopedClass` helper is replaced at build time so there is no performance hit when running the app.
499
+ There is a `scopedClass` helper that you can use to pass a class name as an argument to a component. The helper takes a class name — or a space-separated list of class names — and returns the scoped equivalent. `scopedClass` helper is replaced at build time so there is no performance hit when running the app.
462
500
 
463
501
  ```gjs
464
502
  import { scopedClass } from 'ember-scoped-css';
465
503
 
466
504
  <template>
467
505
  <OtherComponent @internalClass={{scopedClass 'hello-class'}} />
468
- <OtherComponent @internalClass={{(scopedClass 'hello-class')}} />
469
- <OtherComponent
470
- @internalClass={{concat (scopedClass 'hello-class') ' other-class'}}
471
- />
506
+ <OtherComponent @internalClass={{scopedClass 'hello-class other-class'}} />
507
+ <OtherComponent @internalClass="{{scopedClass 'hello-class'}} global-class" />
472
508
  </template>
473
509
  ```
474
510
 
511
+ Every class in the argument is scoped, so
512
+ ```hbs
513
+ <div class={{scopedClass 'hello-class other-class'}}>
514
+ ```
515
+ is equivalent to
516
+ ```hbs
517
+ <div class="{{scopedClass 'hello-class'}} {{scopedClass 'other-class'}}">
518
+ ```
519
+
475
520
  ## Testing
476
521
 
477
522
  As classes are renamed during the build process you can't directly verify if classes are present in your tests. To solve this problem you can use the `scopedClass` function from the `ember-scoped-css/test-support` module. The function takes the class names and path to the CSS file where are the classes defined and returns the scoped class names.