@pikacss/unplugin-pikacss 0.0.46 → 0.0.48
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 +43 -0
- package/dist/esbuild.d.mts +19 -3
- package/dist/esbuild.mjs +18 -5
- package/dist/index.d.mts +40 -3
- package/dist/index.mjs +69 -44
- package/dist/rolldown.d.mts +5743 -3
- package/dist/rolldown.mjs +18 -5
- package/dist/rollup.d.mts +19 -3
- package/dist/rollup.mjs +18 -5
- package/dist/rspack.d.mts +17 -1
- package/dist/rspack.mjs +18 -5
- package/dist/types-237J7YdE.d.mts +130 -0
- package/dist/vite.d.mts +17 -2
- package/dist/vite.mjs +18 -5
- package/dist/webpack.d.mts +17 -1
- package/dist/webpack.mjs +18 -5
- package/package.json +13 -9
- package/dist/types-Cjx5DuB2.d.mts +0 -102
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @pikacss/unplugin-pikacss
|
|
2
|
+
|
|
3
|
+
Universal bundler plugin for PikaCSS. Supports Vite, Webpack, Rspack, Rollup, Rolldown, and esbuild.
|
|
4
|
+
|
|
5
|
+
The Vite entry supports Vite 7 and 8 only.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D @pikacss/unplugin-pikacss
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
When using the `@pikacss/unplugin-pikacss/vite` entry, install Vite 7 or 8.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Vite
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// vite.config.ts
|
|
21
|
+
import pikacss from '@pikacss/unplugin-pikacss/vite'
|
|
22
|
+
import { defineConfig } from 'vite'
|
|
23
|
+
|
|
24
|
+
export default defineConfig({
|
|
25
|
+
plugins: [pikacss()],
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Other bundlers
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import pikacss from '@pikacss/unplugin-pikacss/rollup'
|
|
33
|
+
import pikacss from '@pikacss/unplugin-pikacss/rspack'
|
|
34
|
+
import pikacss from '@pikacss/unplugin-pikacss/webpack'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
See the [full documentation](https://pikacss.com/guide/integrations/vite).
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
package/dist/esbuild.d.mts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-
|
|
2
|
-
import * as unplugin from "unplugin";
|
|
1
|
+
import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-237J7YdE.mjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
3
|
export * from "@pikacss/integration";
|
|
4
4
|
|
|
5
5
|
//#region src/esbuild.d.ts
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* PikaCSS plugin factory for esbuild.
|
|
8
|
+
*
|
|
9
|
+
* Wraps the shared PikaCSS unplugin factory into an esbuild-compatible
|
|
10
|
+
* plugin. Accepts optional {@link PluginOptions} to configure scanning,
|
|
11
|
+
* code generation, and engine settings.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import pikacss from '@pikacss/unplugin-pikacss/esbuild'
|
|
16
|
+
*
|
|
17
|
+
* await esbuild.build({
|
|
18
|
+
* plugins: [pikacss()],
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const _default: (options?: PluginOptions | undefined) => _$unplugin.EsbuildPlugin;
|
|
7
23
|
//#endregion
|
|
8
24
|
export { PluginOptions, ResolvedPluginOptions, _default as default };
|
package/dist/esbuild.mjs
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { unpluginFactory } from "./index.mjs";
|
|
2
2
|
import { createEsbuildPlugin } from "unplugin";
|
|
3
|
-
|
|
4
|
-
export * from "@pikacss/integration"
|
|
5
|
-
|
|
3
|
+
export * from "@pikacss/integration";
|
|
6
4
|
//#region src/esbuild.ts
|
|
5
|
+
/**
|
|
6
|
+
* PikaCSS plugin factory for esbuild.
|
|
7
|
+
*
|
|
8
|
+
* Wraps the shared PikaCSS unplugin factory into an esbuild-compatible
|
|
9
|
+
* plugin. Accepts optional {@link PluginOptions} to configure scanning,
|
|
10
|
+
* code generation, and engine settings.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import pikacss from '@pikacss/unplugin-pikacss/esbuild'
|
|
15
|
+
*
|
|
16
|
+
* await esbuild.build({
|
|
17
|
+
* plugins: [pikacss()],
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
7
21
|
var esbuild_default = createEsbuildPlugin(unpluginFactory);
|
|
8
|
-
|
|
9
22
|
//#endregion
|
|
10
|
-
export { esbuild_default as default };
|
|
23
|
+
export { esbuild_default as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
|
-
import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-
|
|
2
|
-
import * as unplugin from "unplugin";
|
|
1
|
+
import { n as ResolvedPluginOptions, t as PluginOptions } from "./types-237J7YdE.mjs";
|
|
2
|
+
import * as _$unplugin from "unplugin";
|
|
3
3
|
import { UnpluginFactory } from "unplugin";
|
|
4
4
|
export * from "@pikacss/integration";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Factory function that produces the bundler-agnostic PikaCSS plugin hooks.
|
|
9
|
+
*
|
|
10
|
+
* @param options - User-supplied plugin configuration. When `undefined`, all defaults apply.
|
|
11
|
+
* @param meta - Unplugin metadata providing the target bundler framework name.
|
|
12
|
+
* @returns An unplugin hooks object consumed by Vite, webpack, Rollup, esbuild, and Rspack.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This is the core entry-point called by `createUnplugin`. It resolves user options,
|
|
16
|
+
* creates an integration context via `createCtx`, and wires bundler-specific lifecycle
|
|
17
|
+
* hooks (config resolution, dev-server HMR, build transforms, and config file watching).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { unpluginFactory } from '@pikacss/unplugin-pikacss'
|
|
22
|
+
* import { createUnplugin } from 'unplugin'
|
|
23
|
+
*
|
|
24
|
+
* const plugin = createUnplugin(unpluginFactory)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
7
27
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
8
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Pre-built universal bundler plugin for PikaCSS.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Created by passing `unpluginFactory` to `createUnplugin`. Import the bundler-specific
|
|
33
|
+
* sub-path (e.g., `@pikacss/unplugin-pikacss/vite`) for a ready-to-use plugin instance.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // vite.config.ts
|
|
38
|
+
* import pika from '@pikacss/unplugin-pikacss/vite'
|
|
39
|
+
*
|
|
40
|
+
* export default defineConfig({
|
|
41
|
+
* plugins: [pika()],
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare const unpluginPika: _$unplugin.UnpluginInstance<PluginOptions | undefined, boolean>;
|
|
9
46
|
//#endregion
|
|
10
47
|
export { PluginOptions, ResolvedPluginOptions, unpluginPika as default, unpluginPika, unpluginFactory };
|
package/dist/index.mjs
CHANGED
|
@@ -4,14 +4,32 @@ import { createCtx, log } from "@pikacss/integration";
|
|
|
4
4
|
import { resolve } from "pathe";
|
|
5
5
|
import { debounce } from "perfect-debounce";
|
|
6
6
|
import { createUnplugin } from "unplugin";
|
|
7
|
-
|
|
8
|
-
export * from "@pikacss/integration"
|
|
9
|
-
|
|
7
|
+
export * from "@pikacss/integration";
|
|
10
8
|
//#region src/index.ts
|
|
11
9
|
const RE_VIRTUAL_PIKA_CSS_ID = /^pika\.css$/;
|
|
12
10
|
const PLUGIN_NAME = "unplugin-pikacss";
|
|
11
|
+
/**
|
|
12
|
+
* Factory function that produces the bundler-agnostic PikaCSS plugin hooks.
|
|
13
|
+
*
|
|
14
|
+
* @param options - User-supplied plugin configuration. When `undefined`, all defaults apply.
|
|
15
|
+
* @param meta - Unplugin metadata providing the target bundler framework name.
|
|
16
|
+
* @returns An unplugin hooks object consumed by Vite, webpack, Rollup, esbuild, and Rspack.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* This is the core entry-point called by `createUnplugin`. It resolves user options,
|
|
20
|
+
* creates an integration context via `createCtx`, and wires bundler-specific lifecycle
|
|
21
|
+
* hooks (config resolution, dev-server HMR, build transforms, and config file watching).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { unpluginFactory } from '@pikacss/unplugin-pikacss'
|
|
26
|
+
* import { createUnplugin } from 'unplugin'
|
|
27
|
+
*
|
|
28
|
+
* const plugin = createUnplugin(unpluginFactory)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
13
31
|
const unpluginFactory = (options, meta) => {
|
|
14
|
-
const { currentPackageName = "@pikacss/unplugin-pikacss", config: configOrPath, tsCodegen = true, cssCodegen = true, scan = {}, fnName = "pika", transformedFormat = "string", autoCreateConfig = true } = options ?? {};
|
|
32
|
+
const { cwd: userCwd, currentPackageName = "@pikacss/unplugin-pikacss", config: configOrPath, tsCodegen = true, cssCodegen = true, scan = {}, fnName = "pika", transformedFormat = "string", autoCreateConfig = true } = options ?? {};
|
|
15
33
|
log.debug("Creating unplugin factory with options:", options);
|
|
16
34
|
const resolvedOptions = {
|
|
17
35
|
currentPackageName,
|
|
@@ -27,22 +45,27 @@ const unpluginFactory = (options, meta) => {
|
|
|
27
45
|
autoCreateConfig
|
|
28
46
|
};
|
|
29
47
|
log.debug("Resolved plugin options:", resolvedOptions);
|
|
30
|
-
let cwd = resolve(process.cwd());
|
|
31
48
|
let mode = "build";
|
|
32
49
|
const viteServers = [];
|
|
33
50
|
const rspackCompilers = [];
|
|
34
|
-
const farmServers = [];
|
|
35
51
|
const ctx = createCtx({
|
|
36
|
-
cwd,
|
|
52
|
+
cwd: resolve(userCwd ?? process.cwd()),
|
|
37
53
|
...resolvedOptions
|
|
38
54
|
});
|
|
55
|
+
function applyRuntimeContext(nextCwd, nextMode) {
|
|
56
|
+
if (userCwd == null) ctx.cwd = resolve(nextCwd);
|
|
57
|
+
mode = nextMode;
|
|
58
|
+
}
|
|
39
59
|
const debouncedWriteCssCodegenFile = debounce(async () => {
|
|
40
60
|
await ctx.writeCssCodegenFile();
|
|
41
61
|
}, 300);
|
|
42
62
|
const debouncedWriteTsCodegenFile = debounce(async () => {
|
|
43
63
|
await ctx.writeTsCodegenFile();
|
|
44
64
|
}, 300);
|
|
65
|
+
let hooksBound = false;
|
|
45
66
|
function bindHooks() {
|
|
67
|
+
if (hooksBound) return;
|
|
68
|
+
hooksBound = true;
|
|
46
69
|
ctx.hooks.styleUpdated.on(() => {
|
|
47
70
|
log.debug(`Style updated, ${ctx.engine.store.atomicStyleIds.size} atomic styles generated`);
|
|
48
71
|
debouncedWriteCssCodegenFile();
|
|
@@ -53,17 +76,17 @@ const unpluginFactory = (options, meta) => {
|
|
|
53
76
|
});
|
|
54
77
|
}
|
|
55
78
|
let setupPromise = Promise.resolve();
|
|
56
|
-
let
|
|
79
|
+
let lastSetupCwd = null;
|
|
80
|
+
let pendingSetupCwd = null;
|
|
57
81
|
function setup(reload = false) {
|
|
82
|
+
pendingSetupCwd = ctx.cwd;
|
|
58
83
|
setupPromise = setupPromise.then(async () => {
|
|
59
84
|
log.debug("Setting up integration context...");
|
|
60
|
-
const currentSetup = ++setupCounter;
|
|
61
85
|
const moduleIds = Array.from(ctx.usages.keys());
|
|
86
|
+
hooksBound = false;
|
|
62
87
|
await ctx.setup();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
88
|
+
lastSetupCwd = ctx.cwd;
|
|
89
|
+
pendingSetupCwd = null;
|
|
67
90
|
await debouncedWriteCssCodegenFile();
|
|
68
91
|
await debouncedWriteTsCodegenFile();
|
|
69
92
|
bindHooks();
|
|
@@ -87,49 +110,34 @@ const unpluginFactory = (options, meta) => {
|
|
|
87
110
|
compiler.watching.invalidateWithChangesAndRemovals(new Set(moduleIds));
|
|
88
111
|
compiler.watching.invalidate();
|
|
89
112
|
});
|
|
90
|
-
else if (meta.framework === "farm") {
|
|
91
|
-
const promises = [];
|
|
92
|
-
farmServers.forEach((server) => {
|
|
93
|
-
if (server.hmrEngine == null) return;
|
|
94
|
-
promises.push(server.hmrEngine.recompileAndSendResult());
|
|
95
|
-
});
|
|
96
|
-
await Promise.all(promises);
|
|
97
|
-
}
|
|
98
113
|
}
|
|
99
114
|
});
|
|
115
|
+
return setupPromise;
|
|
116
|
+
}
|
|
117
|
+
function ensureSetup(reload = false) {
|
|
118
|
+
if (!reload && (lastSetupCwd === ctx.cwd || pendingSetupCwd === ctx.cwd)) return setupPromise;
|
|
119
|
+
return setup(reload);
|
|
100
120
|
}
|
|
101
121
|
const debouncedSetup = debounce(setup);
|
|
102
|
-
setup();
|
|
103
122
|
return {
|
|
104
123
|
name: PLUGIN_NAME,
|
|
105
124
|
vite: {
|
|
106
125
|
configResolved: (config) => {
|
|
107
|
-
|
|
108
|
-
mode = config.command === "serve" ? "serve" : "build";
|
|
126
|
+
applyRuntimeContext(config.root, config.command === "serve" ? "serve" : "build");
|
|
109
127
|
},
|
|
110
128
|
configureServer(server) {
|
|
111
129
|
viteServers.push(server);
|
|
112
130
|
}
|
|
113
131
|
},
|
|
114
132
|
webpack: (compiler) => {
|
|
115
|
-
|
|
116
|
-
mode = compiler.options.mode === "development" ? "serve" : "build";
|
|
133
|
+
applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
|
|
117
134
|
},
|
|
118
135
|
rspack: (compiler) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
farm: {
|
|
123
|
-
configResolved: (config) => {
|
|
124
|
-
cwd = resolve(config.root || process.cwd());
|
|
125
|
-
mode = config.envMode === "development" ? "serve" : "build";
|
|
126
|
-
},
|
|
127
|
-
configureDevServer(server) {
|
|
128
|
-
farmServers.push(server);
|
|
129
|
-
}
|
|
136
|
+
rspackCompilers.push(compiler);
|
|
137
|
+
applyRuntimeContext(compiler.options.context || process.cwd(), compiler.options.mode === "development" ? "serve" : "build");
|
|
130
138
|
},
|
|
131
139
|
esbuild: { async setup(build) {
|
|
132
|
-
|
|
140
|
+
applyRuntimeContext(build.initialOptions.absWorkingDir || process.cwd(), mode);
|
|
133
141
|
build.onResolve({ filter: RE_VIRTUAL_PIKA_CSS_ID }, (args) => {
|
|
134
142
|
log.debug(`Resolved virtual CSS module: ${args.path} -> ${ctx.cssCodegenFilepath}`);
|
|
135
143
|
return {
|
|
@@ -140,8 +148,8 @@ const unpluginFactory = (options, meta) => {
|
|
|
140
148
|
} },
|
|
141
149
|
async buildStart() {
|
|
142
150
|
log.debug("Plugin buildStart hook triggered");
|
|
143
|
-
log.debug(`Current mode: ${mode}, cwd: ${cwd}`);
|
|
144
|
-
await
|
|
151
|
+
log.debug(`Current mode: ${mode}, cwd: ${ctx.cwd}`);
|
|
152
|
+
await ensureSetup();
|
|
145
153
|
if (mode === "build") {
|
|
146
154
|
log.debug("Running full CSS code generation in build mode");
|
|
147
155
|
await ctx.fullyCssCodegen();
|
|
@@ -153,7 +161,7 @@ const unpluginFactory = (options, meta) => {
|
|
|
153
161
|
},
|
|
154
162
|
resolveId: meta.framework === "esbuild" ? void 0 : async function(id) {
|
|
155
163
|
if (RE_VIRTUAL_PIKA_CSS_ID.test(id)) {
|
|
156
|
-
await
|
|
164
|
+
await ensureSetup();
|
|
157
165
|
log.debug(`Resolved virtual CSS module: ${id} -> ${ctx.cssCodegenFilepath}`);
|
|
158
166
|
return ctx.cssCodegenFilepath;
|
|
159
167
|
}
|
|
@@ -163,7 +171,8 @@ const unpluginFactory = (options, meta) => {
|
|
|
163
171
|
filter: { get id() {
|
|
164
172
|
return ctx.transformFilter;
|
|
165
173
|
} },
|
|
166
|
-
handler(code, id) {
|
|
174
|
+
async handler(code, id) {
|
|
175
|
+
await ensureSetup();
|
|
167
176
|
if (meta.framework === "webpack" && ctx.resolvedConfigPath != null) {
|
|
168
177
|
this.addWatchFile(ctx.resolvedConfigPath);
|
|
169
178
|
log.debug(`Added watch file: ${ctx.resolvedConfigPath}`);
|
|
@@ -179,7 +188,23 @@ const unpluginFactory = (options, meta) => {
|
|
|
179
188
|
}
|
|
180
189
|
};
|
|
181
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Pre-built universal bundler plugin for PikaCSS.
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* Created by passing `unpluginFactory` to `createUnplugin`. Import the bundler-specific
|
|
196
|
+
* sub-path (e.g., `@pikacss/unplugin-pikacss/vite`) for a ready-to-use plugin instance.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* // vite.config.ts
|
|
201
|
+
* import pika from '@pikacss/unplugin-pikacss/vite'
|
|
202
|
+
*
|
|
203
|
+
* export default defineConfig({
|
|
204
|
+
* plugins: [pika()],
|
|
205
|
+
* })
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
182
208
|
const unpluginPika = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
183
|
-
|
|
184
209
|
//#endregion
|
|
185
|
-
export { unpluginPika as default, unpluginPika, unpluginFactory };
|
|
210
|
+
export { unpluginPika as default, unpluginPika, unpluginFactory };
|