@plumeria/next-plugin 16.5.0 → 17.0.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 +103 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +28 -9
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @plumeria/next-plugin
|
|
2
|
+
|
|
3
|
+
Next.js plugin for Plumeria.
|
|
4
|
+
It registers the compiler with Turbopack and Webpack, and emits the project's stylesheet at build time.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install -D @plumeria/next-plugin
|
|
10
|
+
# or
|
|
11
|
+
yarn add -D @plumeria/next-plugin
|
|
12
|
+
# or
|
|
13
|
+
pnpm add -D @plumeria/next-plugin
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
No PostCSS setup is required. `@plumeria/postcss-plugin` was removed in 17.0.0 — if you are upgrading, delete `postcss.config.js` and the `@plumeria` at-rule from your global stylesheet.
|
|
17
|
+
|
|
18
|
+
## How to Use
|
|
19
|
+
|
|
20
|
+
Wrap your config with `withPlumeria`. It works with both Turbopack and Webpack.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// next.config.ts
|
|
24
|
+
import type { NextConfig } from 'next';
|
|
25
|
+
import { withPlumeria } from '@plumeria/next-plugin';
|
|
26
|
+
|
|
27
|
+
const nextConfig: NextConfig = {
|
|
28
|
+
/* config options here */
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default withPlumeria(nextConfig);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Then declare the styling prop once in your project. `@plumeria/core` ships no prop declaration of its own, so nothing is accepted on host elements until you do:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// plumeria.d.ts
|
|
38
|
+
/// <reference types="@plumeria/core/style-name" />
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
Options are passed as the second argument.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
export default withPlumeria(nextConfig, {
|
|
47
|
+
styleProp: 'sx',
|
|
48
|
+
include: ['./src/**/*.{ts,tsx}'],
|
|
49
|
+
exclude: ['**/node_modules/**', '**/.next/**'],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Option | Default | Description |
|
|
54
|
+
| :-- | :-- | :-- |
|
|
55
|
+
| `styleProp` | `'styleName'` | The JSX prop that carries styles. |
|
|
56
|
+
| `include` | all `js/jsx/ts/tsx` | Globs the stylesheet is compiled from. |
|
|
57
|
+
| `exclude` | `node_modules`, `dist`, `.next` | Globs excluded from that compilation. |
|
|
58
|
+
|
|
59
|
+
### styleProp
|
|
60
|
+
|
|
61
|
+
Renaming the prop takes two steps, and they have to agree. Tell the plugin:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export default withPlumeria(nextConfig, { styleProp: 'sx' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
and declare the same name for TypeScript instead of referencing the default:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// plumeria.d.ts
|
|
71
|
+
import type { Style } from '@plumeria/core';
|
|
72
|
+
|
|
73
|
+
declare global {
|
|
74
|
+
namespace React {
|
|
75
|
+
interface HTMLAttributes<T> {
|
|
76
|
+
sx?: Style
|
|
77
|
+
}
|
|
78
|
+
interface SVGAttributes<T> {
|
|
79
|
+
sx?: Style
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If the two disagree, the prop type-checks but is never compiled away. [`@plumeria/eslint-plugin`](https://www.npmjs.com/package/@plumeria/eslint-plugin) reads the same name from `settings.plumeria.styleProp`.
|
|
86
|
+
|
|
87
|
+
### include / exclude
|
|
88
|
+
|
|
89
|
+
The stylesheet is compiled from every source file by default. Narrowing the globs reduces build times on large projects.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
export default withPlumeria(nextConfig, {
|
|
93
|
+
include: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Requirements
|
|
98
|
+
|
|
99
|
+
Turbopack rule conditions keep the compiler from being handed every module in the graph, `node_modules` included. They are a Next.js 16 option, and the plugin applies them only from 16.0.0 up — on 15.x the rule stays unfiltered and builds are slower. Everything else works on both.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
Plumeria is [MIT licensed](https://github.com/zss-in-js/plumeria/blob/main/LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
|
-
|
|
2
|
+
import type { LoaderOptions } from '@plumeria/turbopack-loader';
|
|
3
|
+
export declare function withPlumeria(nextConfig?: NextConfig, options?: LoaderOptions): NextConfig;
|
package/dist/index.js
CHANGED
|
@@ -36,10 +36,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.withPlumeria = withPlumeria;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const isRuleConfigItem = (rule) => !Array.isArray(rule) && typeof rule === 'object' && rule !== null;
|
|
39
|
-
function
|
|
39
|
+
function supportsRuleCondition() {
|
|
40
|
+
try {
|
|
41
|
+
const { version } = require('next/package.json');
|
|
42
|
+
return Number(version.split('.')[0]) >= 16;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function withPlumeria(nextConfig = {}, options = {}) {
|
|
40
49
|
const globalRef = global;
|
|
41
|
-
if (
|
|
42
|
-
!globalRef.__PLUMERIA_RESET_DONE__) {
|
|
50
|
+
if (!globalRef.__PLUMERIA_RESET_DONE__) {
|
|
43
51
|
globalRef.__PLUMERIA_RESET_DONE__ = true;
|
|
44
52
|
try {
|
|
45
53
|
const VIRTUAL_FILE_PATH = require.resolve('@plumeria/turbopack-loader/zero-virtual.css');
|
|
@@ -59,13 +67,24 @@ function withPlumeria(nextConfig = {}) {
|
|
|
59
67
|
}
|
|
60
68
|
const originalWebpack = nextConfig.webpack;
|
|
61
69
|
const turbopackLoaders = [
|
|
62
|
-
{
|
|
70
|
+
{
|
|
71
|
+
loader: '@plumeria/turbopack-loader',
|
|
72
|
+
options: options,
|
|
73
|
+
},
|
|
63
74
|
];
|
|
75
|
+
const ruleItem = supportsRuleCondition()
|
|
76
|
+
? {
|
|
77
|
+
loaders: turbopackLoaders,
|
|
78
|
+
condition: {
|
|
79
|
+
all: [{ not: 'foreign' }, { content: /@plumeria\/core/ }],
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
: { loaders: turbopackLoaders };
|
|
64
83
|
const plumeriaRules = {
|
|
65
|
-
'*.ts':
|
|
66
|
-
'*.tsx':
|
|
67
|
-
'*.js':
|
|
68
|
-
'*.jsx':
|
|
84
|
+
'*.ts': ruleItem,
|
|
85
|
+
'*.tsx': ruleItem,
|
|
86
|
+
'*.js': ruleItem,
|
|
87
|
+
'*.jsx': ruleItem,
|
|
69
88
|
};
|
|
70
89
|
const mergeTurbopackRules = (existingRules = {}, newRules) => {
|
|
71
90
|
const mergedRules = { ...existingRules };
|
|
@@ -119,7 +138,7 @@ function withPlumeria(nextConfig = {}) {
|
|
|
119
138
|
enforce: 'pre',
|
|
120
139
|
test: /\.(tsx|ts|jsx|js)$/,
|
|
121
140
|
exclude: [/node_modules/, /\.next/, /\.git/],
|
|
122
|
-
use: '@plumeria/turbopack-loader',
|
|
141
|
+
use: { loader: '@plumeria/turbopack-loader', options },
|
|
123
142
|
});
|
|
124
143
|
return config;
|
|
125
144
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/next-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Plumeria Next.js plugin",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist/"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@plumeria/turbopack-loader": "^
|
|
32
|
+
"@plumeria/turbopack-loader": "^17.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"next": "^16.2.10",
|