@plumeria/unplugin 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 +44 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +2 -1
- package/dist/core.mjs +3 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -146,8 +146,52 @@ plumeria.vite({
|
|
|
146
146
|
include: ['**/*.{ts,tsx}'],
|
|
147
147
|
exclude: ['**/node_modules/**'],
|
|
148
148
|
devEmitToDisk: false,
|
|
149
|
+
styleProp: 'sx',
|
|
149
150
|
});
|
|
150
151
|
```
|
|
152
|
+
|
|
153
|
+
| Option | Default | Description |
|
|
154
|
+
| :-- | :-- | :-- |
|
|
155
|
+
| `include` | `ts/tsx/js/jsx` | Files to transform. |
|
|
156
|
+
| `exclude` | — | Files to skip. |
|
|
157
|
+
| `devEmitToDisk` | `false` | Write CSS to disk in development so the bundler's watcher drives HMR. |
|
|
158
|
+
| `styleProp` | `'styleName'` | The JSX prop that carries styles. |
|
|
159
|
+
|
|
160
|
+
### styleProp
|
|
161
|
+
|
|
162
|
+
Renaming the prop takes two steps, and they have to agree. Tell the plugin:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
plumeria.vite({ styleProp: 'sx' });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
and declare the same name for TypeScript. `@plumeria/core` ships no prop declaration of its own, so add one file to your project:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// plumeria.d.ts
|
|
172
|
+
import type { Style } from '@plumeria/core';
|
|
173
|
+
|
|
174
|
+
declare global {
|
|
175
|
+
namespace React {
|
|
176
|
+
interface HTMLAttributes<T> {
|
|
177
|
+
sx?: Style
|
|
178
|
+
}
|
|
179
|
+
interface SVGAttributes<T> {
|
|
180
|
+
sx?: Style
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For the default name, reference the declaration that ships with the package instead:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
// plumeria.d.ts
|
|
190
|
+
/// <reference types="@plumeria/core/style-name" />
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
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`.
|
|
194
|
+
|
|
151
195
|
## Development Mode and HMR (Hot Module Replacement)
|
|
152
196
|
|
|
153
197
|
`@plumeria/unplugin` provides HMR optimized for each bundler in development mode (dev server).
|
package/dist/core.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface PluginOptions {
|
|
|
3
3
|
include?: string | RegExp | Array<string | RegExp>;
|
|
4
4
|
exclude?: string | RegExp | Array<string | RegExp>;
|
|
5
5
|
devEmitToDisk?: boolean;
|
|
6
|
+
styleProp?: string;
|
|
6
7
|
}
|
|
7
8
|
export declare const TARGET_EXTENSIONS: string[];
|
|
8
9
|
export declare const EXTENSION_PATTERN: RegExp;
|
package/dist/core.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
|
|
|
43
43
|
exports.EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
|
|
44
44
|
const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
45
45
|
const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
|
|
46
|
+
const styleProp = options.styleProp ?? utils_1.DEFAULT_STYLE_PROP;
|
|
46
47
|
const cssLookup = new Map();
|
|
47
48
|
const cssFileLookup = new Map();
|
|
48
49
|
const targets = [];
|
|
@@ -1485,7 +1486,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1485
1486
|
if (node.name.type !== 'Identifier')
|
|
1486
1487
|
return;
|
|
1487
1488
|
const attrName = node.name.value;
|
|
1488
|
-
if (attrName !==
|
|
1489
|
+
if (attrName !== styleProp) {
|
|
1489
1490
|
let parentTagName = '';
|
|
1490
1491
|
for (const [, val] of jsxOpeningElementMap) {
|
|
1491
1492
|
const found = val.attributes
|
package/dist/core.mjs
CHANGED
|
@@ -2,11 +2,12 @@ import { createFilter } from '@rollup/pluginutils';
|
|
|
2
2
|
import { parseSync } from '@swc/core';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { applyCssValue, genBase36Hash, exceptionCamelCase, camelToKebabCase, isAtRule, } from 'zss-engine';
|
|
5
|
-
import { traverse, collectReferenceIdentifiers, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, getLeadingCommentLength, optimizer, getFileDependencies, resolveExport, } from '@plumeria/utils';
|
|
5
|
+
import { traverse, collectReferenceIdentifiers, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, getRootIdentifier, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, getLeadingCommentLength, optimizer, getFileDependencies, resolveExport, DEFAULT_STYLE_PROP, } from '@plumeria/utils';
|
|
6
6
|
export const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
|
|
7
7
|
export const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
|
|
8
8
|
export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
9
9
|
const filter = createFilter(options.include, options.exclude);
|
|
10
|
+
const styleProp = options.styleProp ?? DEFAULT_STYLE_PROP;
|
|
10
11
|
const cssLookup = new Map();
|
|
11
12
|
const cssFileLookup = new Map();
|
|
12
13
|
const targets = [];
|
|
@@ -1449,7 +1450,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1449
1450
|
if (node.name.type !== 'Identifier')
|
|
1450
1451
|
return;
|
|
1451
1452
|
const attrName = node.name.value;
|
|
1452
|
-
if (attrName !==
|
|
1453
|
+
if (attrName !== styleProp) {
|
|
1453
1454
|
let parentTagName = '';
|
|
1454
1455
|
for (const [, val] of jsxOpeningElementMap) {
|
|
1455
1456
|
const found = val.attributes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Universal Plumeria plugin for various build tools",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@rollup/pluginutils": "^5.4.0",
|
|
91
91
|
"unplugin": "^3.0.0",
|
|
92
|
-
"@plumeria/utils": "^
|
|
92
|
+
"@plumeria/utils": "^17.0.0"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@swc/core": "1.15.43",
|