@plumeria/turbopack-loader 18.3.0 → 18.3.2
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 +2 -97
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,103 +1,8 @@
|
|
|
1
1
|
# @plumeria/turbopack-loader
|
|
2
2
|
|
|
3
|
-
The loader that compiles Plumeria styles in a Next.js build, under Turbopack and webpack alike.
|
|
3
|
+
The loader that compiles Plumeria styles in a Next.js build, under Turbopack and webpack alike. It is installed and wired by [`@plumeria/next-plugin`](https://www.npmjs.com/package/@plumeria/next-plugin), which is where a build is set up and where the options it takes are documented.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
// in
|
|
9
|
-
const styles = css.create({ box: { padding: 16, color: 'red' } });
|
|
10
|
-
export const A = () => <div classStyle={styles.box} />;
|
|
11
|
-
|
|
12
|
-
// out
|
|
13
|
-
export const A = () => <div className={"xqqbxt1d xq96bg3w"} />;
|
|
14
|
-
import "../../node_modules/@plumeria/turbopack-loader/zero-virtual.css";
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Nothing of the library survives into the output, so a React Server Component keeps its styles with no `'use client'` boundary to add.
|
|
18
|
-
|
|
19
|
-
## Setup
|
|
20
|
-
|
|
21
|
-
You do not configure this loader yourself. [`@plumeria/next-plugin`](https://www.npmjs.com/package/@plumeria/next-plugin) installs it and wires it into both bundlers:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm i -D @plumeria/next-plugin
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
// next.config.ts
|
|
29
|
-
import { withPlumeria } from '@plumeria/next-plugin';
|
|
30
|
-
|
|
31
|
-
export default withPlumeria({});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Options
|
|
35
|
-
|
|
36
|
-
`withPlumeria` passes its second argument through as the loader's options:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
export default withPlumeria({}, {
|
|
40
|
-
include: ['./app/**/*.{ts,tsx}'],
|
|
41
|
-
exclude: ['**/node_modules/**'],
|
|
42
|
-
styleProp: 'sx',
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
- `include` — the files to compile. The default is `['**/*.{js,jsx,ts,tsx}']`.
|
|
47
|
-
- `exclude` — the files to leave alone. The default is `['**/node_modules/**', '**/dist/**', '**/.next/**']`.
|
|
48
|
-
- `styleProp` — the JSX prop that carries styles. The default is `'classStyle'`.
|
|
49
|
-
|
|
50
|
-
The prop name here and the one declared in `plumeria.d.ts` have to match. If they disagree, the prop type-checks but is never compiled away.
|
|
51
|
-
|
|
52
|
-
## The stylesheet
|
|
53
|
-
|
|
54
|
-
Rules are written to `zero-virtual.css` inside this package, and each compiled module imports it by relative path. In development the file grows as modules are compiled; a production build fills it in one pass before any module is processed, which is what [`@plumeria/compiler`](https://www.npmjs.com/package/@plumeria/compiler) is installed for. Writes are taken under a lock, so concurrent builds do not lose rules.
|
|
55
|
-
|
|
56
|
-
If styles are missing from a page, the module was not compiled — check that its path is matched by `include` and not by `exclude`.
|
|
57
|
-
|
|
58
|
-
## Testing
|
|
59
|
-
|
|
60
|
-
A loader is a function that reads four properties off `this`, so it can be called on its own, with no bundler and no DOM in between. A Next.js project tests the loader its own build runs:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
// compile.test.js
|
|
64
|
-
const loader = require('@plumeria/turbopack-loader');
|
|
65
|
-
const fn = loader.default ?? loader; // built as CommonJS with an ESM default
|
|
66
|
-
|
|
67
|
-
const compile = (source) =>
|
|
68
|
-
new Promise((resolve, reject) => {
|
|
69
|
-
fn.call(
|
|
70
|
-
{
|
|
71
|
-
resourcePath: `${__dirname}/fixture.tsx`,
|
|
72
|
-
async: () => (err, content) => (err ? reject(err) : resolve(content)),
|
|
73
|
-
addDependency: () => {},
|
|
74
|
-
clearDependencies: () => {},
|
|
75
|
-
},
|
|
76
|
-
source,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('a media query does not collide with the base rule', async () => {
|
|
81
|
-
const code = await compile(`
|
|
82
|
-
import * as css from '@plumeria/core';
|
|
83
|
-
const styles = css.create({
|
|
84
|
-
box: { color: 'red', '@media (min-width: 640px)': { color: 'blue' } },
|
|
85
|
-
});
|
|
86
|
-
export const A = () => <div classStyle={styles.box} />;
|
|
87
|
-
`);
|
|
88
|
-
|
|
89
|
-
const classes = code.match(/className=\{"([^"]*)"\}/)[1].split(' ');
|
|
90
|
-
expect(new Set(classes).size).toBe(classes.length);
|
|
91
|
-
});
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
It is plain asynchronous JavaScript, so Jest, Vitest and `node:test` all run it as it stands. Add this package to your `devDependencies` before requiring it: it arrives as a dependency of the plugin either way, but a strict package manager such as pnpm does not put a transitive dependency where your own code can reach it.
|
|
95
|
-
|
|
96
|
-
The rewritten code comes back through `async`. The stylesheet is written only under `NODE_ENV=development`, so a test run reads the class names and leaves the file alone; set the variable when the stylesheet is what you came for.
|
|
97
|
-
|
|
98
|
-
Read the class names out of the returned code rather than hard-coding them. An atomic class name is one property–value pair, hashed, so a list spelled out in a test breaks the next time a property is added to the style.
|
|
99
|
-
|
|
100
|
-
See [Testing](https://plumeria.dev/docs/testing) for the layer this belongs to, and the two it does not cover.
|
|
5
|
+
There is one reason to install it yourself: it is exported as a plain function, so a test can call it and assert on the compiled output with no bundler in between. See [Testing](https://plumeria.dev/docs/testing) for the example. If you are looking for Plumeria itself, start at [`@plumeria/core`](https://www.npmjs.com/package/@plumeria/core).
|
|
101
6
|
|
|
102
7
|
## API Stability
|
|
103
8
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "18.3.
|
|
3
|
+
"version": "18.3.2",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"zero-virtual.css"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@plumeria/compiler": "^18.3.
|
|
33
|
-
"@plumeria/utils": "^18.3.
|
|
32
|
+
"@plumeria/compiler": "^18.3.2",
|
|
33
|
+
"@plumeria/utils": "^18.3.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@swc/core": "1.15.47",
|