turbopack-unocss-transform 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/README.md +106 -22
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,57 +1,141 @@
1
1
  # turbopack-unocss-transform
2
2
 
3
- A Turbopack loader for Next.js that applies UnoCSS transformers (like variant-group and attributify-jsx) directly to your TS/JS/TSX/JSX source before CSS generation.
3
+ Turbopack loader for Next.js that applies UnoCSS transformers (`transformerAttributifyJsx`, `transformerVariantGroup`, `transformerDirectives`) to source files.
4
4
 
5
- Actual CSS is produced by `@unocss/postcss`; this loader only transforms source code.
5
+ `@unocss/postcss` handles CSS generation; this loader transforms JS/TS/JSX/TSX source code.
6
+
7
+ ## Requirements
8
+
9
+ | Dependency | Version |
10
+ | ---------- | ------------------------------------------------------------------ |
11
+ | Node.js | **≥23.6.0** (native TypeScript support if you use `uno.config.ts`) |
12
+ | Next.js | ≥15.0.0 |
13
+ | UnoCSS | ≥66.0.0 |
6
14
 
7
15
  ## Installation
8
16
 
9
17
  ```bash
10
- pnpm add -D turbopack-unocss-transform
18
+ pnpm add -D turbopack-unocss-transform @unocss/postcss
11
19
  ```
12
20
 
13
- ## Usage
21
+ ## Setup
14
22
 
15
- ### next.config.ts
23
+ ### 1. next.config.ts
16
24
 
17
25
  ```typescript
18
26
  import type {NextConfig} from "next"
19
27
  import withUnoTransform from "turbopack-unocss-transform"
20
28
 
21
29
  const nextConfig: NextConfig = withUnoTransform({
22
- // your Next.js config
30
+ // your config
23
31
  })
24
32
 
25
33
  export default nextConfig
26
34
  ```
27
35
 
28
- ### postcss.config.mjs
36
+ ### 2. postcss.config.mjs
29
37
 
30
- **Option 1: Import config object**
38
+ > [!IMPORTANT]
39
+ > **Import the config object, not a path string.** Passing a string or without the `configOrPath` setting disables HMR - Turbopack won't detect config changes.
31
40
 
32
- ```js
33
- import unoConfig from "./uno.config"
41
+ ```javascript
42
+ import config from "./uno.config.ts"
34
43
 
35
44
  export default {
36
45
  plugins: [
37
- ["@unocss/postcss", {configOrPath: unoConfig}],
38
- "autoprefixer"
46
+ ["@unocss/postcss", {configOrPath: config}]
39
47
  ]
40
48
  }
41
49
  ```
42
50
 
43
- **Option 2: Pass config path as string**
51
+ ### 3. tsconfig.json
44
52
 
45
- ```js
46
- export default {
47
- plugins: [
48
- ["@unocss/postcss", {configOrPath: "./uno.config.ts"}],
49
- "autoprefixer"
50
- ]
53
+ > [!IMPORTANT]
54
+ > **Required.** Node.js 23+ executes TypeScript natively but requires explicit `.ts` extensions in imports. This flag allows TypeScript to accept them.
55
+
56
+ ```json
57
+ {
58
+ "compilerOptions": {
59
+ "allowImportingTsExtensions": true,
60
+ "noEmit": true
61
+ }
51
62
  }
52
63
  ```
53
64
 
54
- ## Requirements
65
+ ### 4. uno.config.ts
66
+
67
+ > [!WARNING]
68
+ > **All local imports must include `.ts` extension.** PostCSS runs via Node.js worker (not Turbopack), which requires explicit extensions for TypeScript files.
69
+
70
+ ```typescript
71
+ import type {UserConfig} from "@unocss/core"
72
+ import {presetAttributify} from "@unocss/preset-attributify"
73
+ import {presetWind4} from "@unocss/preset-wind4"
74
+ import transformerAttributifyJsx from "@unocss/transformer-attributify-jsx"
75
+ import transformerDirectives from "@unocss/transformer-directives"
76
+ import transformerVariantGroup from "@unocss/transformer-variant-group"
77
+ import theme from "./src/styles/theme/index.ts"
78
+ import preflights from "./src/styles/theme/preflights.ts"
79
+
80
+ export default {
81
+ presets: [presetWind4(), presetAttributify()],
82
+ transformers: [
83
+ transformerAttributifyJsx(),
84
+ transformerDirectives(),
85
+ transformerVariantGroup()
86
+ ],
87
+ theme,
88
+ preflights
89
+ } satisfies UserConfig
90
+ ```
91
+
92
+ > [!CAUTION]
93
+ > **Avoid importing from the `unocss` meta-package.** It re-exports all presets including `@unocss/preset-icons`, which depends on `mlly` that uses dynamic `import(dataURL)` - not supported by Turbopack.
94
+ >
95
+ > This will fail:
96
+ >
97
+ > ```typescript
98
+ > import {defineConfig, presetWind4} from "unocss" // ❌ Pulls in mlly
99
+ > ```
100
+ >
101
+ > Use separate packages instead:
102
+ >
103
+ > ```typescript
104
+ > import {presetWind4} from "@unocss/preset-wind4" // ✅
105
+ > ```
106
+ >
107
+ > You can try the meta-package - it might work in future versions, but this setup was tested with separate packages only.
108
+
109
+ ### 5. Global styles (e.g., global.sass)
110
+
111
+ ```sass
112
+ @unocss all
113
+
114
+ html, body
115
+ @apply text-dark font-sans
116
+ ```
117
+
118
+ ## Why explicit `.ts` extensions?
119
+
120
+ PostCSS config is executed by a **Node.js worker**, not Turbopack. Node.js 23+ runs TypeScript natively but doesn't resolve `.ts` extensions automatically — they must be explicit.
121
+
122
+ Without explicit extensions:
123
+
124
+ ```
125
+ Module not found: Can't resolve './src/styles/theme'
126
+ ```
127
+
128
+ ## HMR behavior
129
+
130
+ | postcss.config.mjs | HMR |
131
+ | -------------------------------------- | -------- |
132
+ | `import config from "./uno.config.ts"` | ✅ Works |
133
+ | `{configOrPath: "./uno.config.ts"}` | ❌ No HMR |
134
+
135
+ When using path string, Turbopack doesn't track `uno.config.ts` as a dependency — changes require `next dev` restart.
136
+
137
+ ## Tested with
55
138
 
56
- - Next.js 15+ with Turbopack
57
- - UnoCSS 0.58+
139
+ - Next.js **16.1.3**
140
+ - UnoCSS **66.5.6**
141
+ - Node.js **23.11.0**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbopack-unocss-transform",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "license": "MIT",
5
5
  "author": "vizet <v@kogita.net>",
6
6
  "description": "A Turbopack loader for Next.js that applies UnoCSS transformers (like variant-group and attributify-jsx) directly to your TS/JS/TSX/JSX source before CSS generation.",