@fullhuman/purgecss-from-tsx 8.0.0 → 9.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 +6 -4
- package/lib/purgecss-from-tsx.esm.js +1 -0
- package/lib/purgecss-from-tsx.js +1 -0
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install @fullhuman/purgecss-from-tsx --save-dev
|
|
|
15
15
|
### With PurgeCSS
|
|
16
16
|
|
|
17
17
|
```js
|
|
18
|
-
import PurgeCSS from "purgecss";
|
|
18
|
+
import { PurgeCSS } from "purgecss";
|
|
19
19
|
import purgeFromTsx from "@fullhuman/purgecss-from-tsx";
|
|
20
20
|
|
|
21
21
|
const result = await new PurgeCSS().purge({
|
|
@@ -105,10 +105,12 @@ This extractor works in two steps:
|
|
|
105
105
|
|
|
106
106
|
The extractor parses TSX and extracts:
|
|
107
107
|
|
|
108
|
-
1. **Component names** - JSX element names (e.g., `div`, `Header`, `MyComponent`)
|
|
109
|
-
2. **className values** - String values from `className` attributes, split by
|
|
108
|
+
1. **Component names** - JSX element names (e.g., `div`, `Header`, `MyComponent`), including elements inside the value of another attribute (e.g., `icon={<Icon />}`)
|
|
109
|
+
2. **className values** - String values from `className` attributes, split by whitespace
|
|
110
110
|
3. **id values** - String values from `id` attributes
|
|
111
111
|
|
|
112
|
+
When `className` or `id` is an expression, its static parts are extracted the same way as by the [JSX extractor](https://github.com/FullHuman/purgecss/tree/main/packages/purgecss-from-jsx#what-it-extracts): for example, `className={active ? "on" : "off"}` gives `on` and `off`, and ``className={`card ${size}`}`` gives `card`. The TypeScript syntax is stripped first, so `className={"card" as string}` gives `card`.
|
|
113
|
+
|
|
112
114
|
### Example
|
|
113
115
|
|
|
114
116
|
```tsx
|
|
@@ -129,7 +131,7 @@ Extracted selectors: `["article", "card", "card-hover", "featured", "CardHeader"
|
|
|
129
131
|
## Limitations
|
|
130
132
|
|
|
131
133
|
- Only extracts static string values from `className` and `id`
|
|
132
|
-
-
|
|
134
|
+
- Values computed at runtime, like `className={styles.container}` or the `size` of ``className={`btn-${size}`}``, are not extracted
|
|
133
135
|
- For dynamic class names, consider using PurgeCSS's [safelist](https://purgecss.com/safelisting.html) option
|
|
134
136
|
|
|
135
137
|
## License
|
|
@@ -14,6 +14,7 @@ function purgeFromTsx(options) {
|
|
|
14
14
|
return purgeFromJsx(options === null || options === void 0 ? void 0 : options.acornOptions)(ts.transpileModule(content, {
|
|
15
15
|
compilerOptions: {
|
|
16
16
|
jsx: ts.JsxEmit.Preserve,
|
|
17
|
+
module: ts.ModuleKind.CommonJS,
|
|
17
18
|
...options === null || options === void 0 ? void 0 : options.tsOptions,
|
|
18
19
|
},
|
|
19
20
|
}).outputText);
|
package/lib/purgecss-from-tsx.js
CHANGED
|
@@ -35,6 +35,7 @@ function purgeFromTsx(options) {
|
|
|
35
35
|
return purgeFromJsx(options === null || options === void 0 ? void 0 : options.acornOptions)(ts__namespace.transpileModule(content, {
|
|
36
36
|
compilerOptions: {
|
|
37
37
|
jsx: ts__namespace.JsxEmit.Preserve,
|
|
38
|
+
module: ts__namespace.ModuleKind.CommonJS,
|
|
38
39
|
...options === null || options === void 0 ? void 0 : options.tsOptions,
|
|
39
40
|
},
|
|
40
41
|
}).outputText);
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullhuman/purgecss-from-tsx",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "TSX extractor for PurgeCSS",
|
|
5
5
|
"author": "Ffloriel",
|
|
6
6
|
"homepage": "https://github.com/FullHuman/purgecss#readme",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.12.0"
|
|
10
|
+
},
|
|
8
11
|
"main": "./lib/purgecss-from-tsx.js",
|
|
9
12
|
"module": "./lib/purgecss-from-tsx.esm.js",
|
|
10
13
|
"types": "./lib/purgecss-from-tsx.d.ts",
|
|
@@ -19,21 +22,20 @@
|
|
|
19
22
|
"type": "git",
|
|
20
23
|
"url": "git+https://github.com/FullHuman/purgecss.git"
|
|
21
24
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "ts-node build.ts",
|
|
24
|
-
"test": "jest"
|
|
25
|
-
},
|
|
26
25
|
"bugs": {
|
|
27
26
|
"url": "https://github.com/FullHuman/purgecss/issues"
|
|
28
27
|
},
|
|
29
28
|
"dependencies": {
|
|
30
|
-
"@fullhuman/purgecss-from-jsx": "^
|
|
31
|
-
"acorn": "^8.
|
|
32
|
-
"typescript": "^
|
|
29
|
+
"@fullhuman/purgecss-from-jsx": "^9.0.0",
|
|
30
|
+
"acorn": "^8.19.0",
|
|
31
|
+
"typescript": "^6.0.3"
|
|
33
32
|
},
|
|
34
33
|
"publishConfig": {
|
|
35
34
|
"access": "public",
|
|
36
35
|
"registry": "https://registry.npmjs.org/"
|
|
37
36
|
},
|
|
38
|
-
"
|
|
39
|
-
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "ts-node build.ts",
|
|
39
|
+
"test": "jest"
|
|
40
|
+
}
|
|
41
|
+
}
|