@pandacss/webpack 2.0.0-beta.9
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/LICENSE.md +21 -0
- package/dist/css-loader.cjs +34 -0
- package/dist/css-loader.d.cts +17 -0
- package/dist/css-loader.d.ts +17 -0
- package/dist/css-loader.js +13 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +68 -0
- package/dist/next.cjs +107 -0
- package/dist/next.d.cts +19 -0
- package/dist/next.d.ts +19 -0
- package/dist/next.js +80 -0
- package/package.json +66 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Chakra Systems Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/css-loader.ts
|
|
21
|
+
var css_loader_exports = {};
|
|
22
|
+
__export(css_loader_exports, {
|
|
23
|
+
default: () => pandaCssLoader
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(css_loader_exports);
|
|
26
|
+
function pandaCssLoader(source) {
|
|
27
|
+
const driver = this.getOptions().getDriver();
|
|
28
|
+
if (!driver || !driver.compiler.hasLayerDeclaration(source)) return source;
|
|
29
|
+
for (const file of driver.scan()) this.addDependency(file);
|
|
30
|
+
if (driver.configPath) this.addDependency(driver.configPath);
|
|
31
|
+
const { css } = driver.cssgen({ emitLayerDeclaration: false });
|
|
32
|
+
return `${source}
|
|
33
|
+
${css}`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Driver } from '@pandacss/compiler';
|
|
2
|
+
import { LoaderContext } from 'webpack';
|
|
3
|
+
|
|
4
|
+
/** Options the plugin passes to this loader — a live handle to the driver. */
|
|
5
|
+
interface PandaCssLoaderOptions {
|
|
6
|
+
getDriver: () => Driver | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `pre` loader for `.css` files. When a stylesheet declares Panda layers
|
|
10
|
+
* (`@layer reset, base, …;`), append the generated CSS in-memory — the webpack
|
|
11
|
+
* analog of the Vite plugin's `.css` transform. No file is written to disk.
|
|
12
|
+
* Registers every source file (and the config) as a dependency so webpack
|
|
13
|
+
* rebuilds this stylesheet when they change.
|
|
14
|
+
*/
|
|
15
|
+
declare function pandaCssLoader(this: LoaderContext<PandaCssLoaderOptions>, source: string): string;
|
|
16
|
+
|
|
17
|
+
export { type PandaCssLoaderOptions, pandaCssLoader as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Driver } from '@pandacss/compiler';
|
|
2
|
+
import { LoaderContext } from 'webpack';
|
|
3
|
+
|
|
4
|
+
/** Options the plugin passes to this loader — a live handle to the driver. */
|
|
5
|
+
interface PandaCssLoaderOptions {
|
|
6
|
+
getDriver: () => Driver | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `pre` loader for `.css` files. When a stylesheet declares Panda layers
|
|
10
|
+
* (`@layer reset, base, …;`), append the generated CSS in-memory — the webpack
|
|
11
|
+
* analog of the Vite plugin's `.css` transform. No file is written to disk.
|
|
12
|
+
* Registers every source file (and the config) as a dependency so webpack
|
|
13
|
+
* rebuilds this stylesheet when they change.
|
|
14
|
+
*/
|
|
15
|
+
declare function pandaCssLoader(this: LoaderContext<PandaCssLoaderOptions>, source: string): string;
|
|
16
|
+
|
|
17
|
+
export { type PandaCssLoaderOptions, pandaCssLoader as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/css-loader.ts
|
|
2
|
+
function pandaCssLoader(source) {
|
|
3
|
+
const driver = this.getOptions().getDriver();
|
|
4
|
+
if (!driver || !driver.compiler.hasLayerDeclaration(source)) return source;
|
|
5
|
+
for (const file of driver.scan()) this.addDependency(file);
|
|
6
|
+
if (driver.configPath) this.addDependency(driver.configPath);
|
|
7
|
+
const { css } = driver.cssgen({ emitLayerDeclaration: false });
|
|
8
|
+
return `${source}
|
|
9
|
+
${css}`;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
pandaCssLoader as default
|
|
13
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
PandaWebpackPlugin: () => PandaWebpackPlugin,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_compiler = require("@pandacss/compiler");
|
|
28
|
+
var import_transformer = require("@pandacss/transformer");
|
|
29
|
+
var NAME = "PandaWebpackPlugin";
|
|
30
|
+
var PandaWebpackPlugin = class {
|
|
31
|
+
#options;
|
|
32
|
+
#driver;
|
|
33
|
+
#ready;
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.#options = options;
|
|
36
|
+
}
|
|
37
|
+
#build(cwd) {
|
|
38
|
+
if (!this.#ready) {
|
|
39
|
+
this.#ready = (async () => {
|
|
40
|
+
const driver = await (0, import_compiler.createNodeDriver)({ cwd, configPath: this.#options.configPath });
|
|
41
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
42
|
+
driver.parseFiles();
|
|
43
|
+
this.#driver = driver;
|
|
44
|
+
})();
|
|
45
|
+
}
|
|
46
|
+
return this.#ready;
|
|
47
|
+
}
|
|
48
|
+
/** Watch-mode incremental sync: fold changed files into the driver before this
|
|
49
|
+
* rebuild's modules (including the layer-declaring CSS) are read. The driver
|
|
50
|
+
* re-reads changed files through its own fs. */
|
|
51
|
+
async #sync(cwd, changed) {
|
|
52
|
+
await this.#build(cwd);
|
|
53
|
+
const driver = this.#driver;
|
|
54
|
+
let configChanged = false;
|
|
55
|
+
for (const file of changed) {
|
|
56
|
+
if (driver.isConfigFile(file)) {
|
|
57
|
+
configChanged = true;
|
|
58
|
+
} else if (driver.isSourceFile(file)) {
|
|
59
|
+
driver.applyChange({ path: file, kind: "change" });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (configChanged) {
|
|
63
|
+
const diff = await driver.reload();
|
|
64
|
+
if (diff.hasChanged) {
|
|
65
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
66
|
+
driver.parseFiles();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
apply(compiler) {
|
|
71
|
+
const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
|
|
72
|
+
const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
|
|
73
|
+
import_transformer.pandaTransformer.webpack({
|
|
74
|
+
exclude: [/node_modules/],
|
|
75
|
+
...transformerOptions,
|
|
76
|
+
getCompiler: () => this.#driver?.compiler
|
|
77
|
+
}).apply(compiler);
|
|
78
|
+
const options = { getDriver: () => this.#driver };
|
|
79
|
+
compiler.options.module.rules.push({
|
|
80
|
+
test: /\.css$/,
|
|
81
|
+
exclude: /node_modules/,
|
|
82
|
+
enforce: "pre",
|
|
83
|
+
use: [{ loader: "@pandacss/webpack/css-loader", options }]
|
|
84
|
+
});
|
|
85
|
+
compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
|
|
86
|
+
compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var index_default = PandaWebpackPlugin;
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
PandaWebpackPlugin
|
|
93
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PandaTransformerOptions } from '@pandacss/transformer';
|
|
2
|
+
import { Compiler } from 'webpack';
|
|
3
|
+
|
|
4
|
+
interface PandaWebpackPluginOptions extends PandaTransformerOptions {
|
|
5
|
+
/** Project root. Defaults to the webpack compiler `context`. */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Explicit config file (relative to `cwd`); otherwise discovered upward. */
|
|
8
|
+
configPath?: string;
|
|
9
|
+
/** Where codegen artifacts are written. Defaults to the config `outdir`. */
|
|
10
|
+
outdir?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* webpack plugin for Panda CSS. Runs codegen and rewrites source via the native
|
|
14
|
+
* transform loader (shared `@pandacss/transformer` unplugin, which also resolves
|
|
15
|
+
* the `@pandacss-internal/css` runtime module). Generated CSS is injected
|
|
16
|
+
* in-memory into any stylesheet that declares Panda layers — no file is written.
|
|
17
|
+
*/
|
|
18
|
+
declare class PandaWebpackPlugin {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options?: PandaWebpackPluginOptions);
|
|
21
|
+
apply(compiler: Compiler): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { PandaWebpackPlugin, type PandaWebpackPluginOptions, PandaWebpackPlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PandaTransformerOptions } from '@pandacss/transformer';
|
|
2
|
+
import { Compiler } from 'webpack';
|
|
3
|
+
|
|
4
|
+
interface PandaWebpackPluginOptions extends PandaTransformerOptions {
|
|
5
|
+
/** Project root. Defaults to the webpack compiler `context`. */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Explicit config file (relative to `cwd`); otherwise discovered upward. */
|
|
8
|
+
configPath?: string;
|
|
9
|
+
/** Where codegen artifacts are written. Defaults to the config `outdir`. */
|
|
10
|
+
outdir?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* webpack plugin for Panda CSS. Runs codegen and rewrites source via the native
|
|
14
|
+
* transform loader (shared `@pandacss/transformer` unplugin, which also resolves
|
|
15
|
+
* the `@pandacss-internal/css` runtime module). Generated CSS is injected
|
|
16
|
+
* in-memory into any stylesheet that declares Panda layers — no file is written.
|
|
17
|
+
*/
|
|
18
|
+
declare class PandaWebpackPlugin {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options?: PandaWebpackPluginOptions);
|
|
21
|
+
apply(compiler: Compiler): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { PandaWebpackPlugin, type PandaWebpackPluginOptions, PandaWebpackPlugin as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createNodeDriver } from "@pandacss/compiler";
|
|
3
|
+
import { pandaTransformer } from "@pandacss/transformer";
|
|
4
|
+
var NAME = "PandaWebpackPlugin";
|
|
5
|
+
var PandaWebpackPlugin = class {
|
|
6
|
+
#options;
|
|
7
|
+
#driver;
|
|
8
|
+
#ready;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.#options = options;
|
|
11
|
+
}
|
|
12
|
+
#build(cwd) {
|
|
13
|
+
if (!this.#ready) {
|
|
14
|
+
this.#ready = (async () => {
|
|
15
|
+
const driver = await createNodeDriver({ cwd, configPath: this.#options.configPath });
|
|
16
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
17
|
+
driver.parseFiles();
|
|
18
|
+
this.#driver = driver;
|
|
19
|
+
})();
|
|
20
|
+
}
|
|
21
|
+
return this.#ready;
|
|
22
|
+
}
|
|
23
|
+
/** Watch-mode incremental sync: fold changed files into the driver before this
|
|
24
|
+
* rebuild's modules (including the layer-declaring CSS) are read. The driver
|
|
25
|
+
* re-reads changed files through its own fs. */
|
|
26
|
+
async #sync(cwd, changed) {
|
|
27
|
+
await this.#build(cwd);
|
|
28
|
+
const driver = this.#driver;
|
|
29
|
+
let configChanged = false;
|
|
30
|
+
for (const file of changed) {
|
|
31
|
+
if (driver.isConfigFile(file)) {
|
|
32
|
+
configChanged = true;
|
|
33
|
+
} else if (driver.isSourceFile(file)) {
|
|
34
|
+
driver.applyChange({ path: file, kind: "change" });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (configChanged) {
|
|
38
|
+
const diff = await driver.reload();
|
|
39
|
+
if (diff.hasChanged) {
|
|
40
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
41
|
+
driver.parseFiles();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
apply(compiler) {
|
|
46
|
+
const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
|
|
47
|
+
const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
|
|
48
|
+
pandaTransformer.webpack({
|
|
49
|
+
exclude: [/node_modules/],
|
|
50
|
+
...transformerOptions,
|
|
51
|
+
getCompiler: () => this.#driver?.compiler
|
|
52
|
+
}).apply(compiler);
|
|
53
|
+
const options = { getDriver: () => this.#driver };
|
|
54
|
+
compiler.options.module.rules.push({
|
|
55
|
+
test: /\.css$/,
|
|
56
|
+
exclude: /node_modules/,
|
|
57
|
+
enforce: "pre",
|
|
58
|
+
use: [{ loader: "@pandacss/webpack/css-loader", options }]
|
|
59
|
+
});
|
|
60
|
+
compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
|
|
61
|
+
compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var index_default = PandaWebpackPlugin;
|
|
65
|
+
export {
|
|
66
|
+
PandaWebpackPlugin,
|
|
67
|
+
index_default as default
|
|
68
|
+
};
|
package/dist/next.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/next.ts
|
|
21
|
+
var next_exports = {};
|
|
22
|
+
__export(next_exports, {
|
|
23
|
+
default: () => next_default,
|
|
24
|
+
withPandaCss: () => withPandaCss
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(next_exports);
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var import_compiler = require("@pandacss/compiler");
|
|
30
|
+
var import_transformer = require("@pandacss/transformer");
|
|
31
|
+
var NAME = "PandaWebpackPlugin";
|
|
32
|
+
var PandaWebpackPlugin = class {
|
|
33
|
+
#options;
|
|
34
|
+
#driver;
|
|
35
|
+
#ready;
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.#options = options;
|
|
38
|
+
}
|
|
39
|
+
#build(cwd) {
|
|
40
|
+
if (!this.#ready) {
|
|
41
|
+
this.#ready = (async () => {
|
|
42
|
+
const driver = await (0, import_compiler.createNodeDriver)({ cwd, configPath: this.#options.configPath });
|
|
43
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
44
|
+
driver.parseFiles();
|
|
45
|
+
this.#driver = driver;
|
|
46
|
+
})();
|
|
47
|
+
}
|
|
48
|
+
return this.#ready;
|
|
49
|
+
}
|
|
50
|
+
/** Watch-mode incremental sync: fold changed files into the driver before this
|
|
51
|
+
* rebuild's modules (including the layer-declaring CSS) are read. The driver
|
|
52
|
+
* re-reads changed files through its own fs. */
|
|
53
|
+
async #sync(cwd, changed) {
|
|
54
|
+
await this.#build(cwd);
|
|
55
|
+
const driver = this.#driver;
|
|
56
|
+
let configChanged = false;
|
|
57
|
+
for (const file of changed) {
|
|
58
|
+
if (driver.isConfigFile(file)) {
|
|
59
|
+
configChanged = true;
|
|
60
|
+
} else if (driver.isSourceFile(file)) {
|
|
61
|
+
driver.applyChange({ path: file, kind: "change" });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (configChanged) {
|
|
65
|
+
const diff = await driver.reload();
|
|
66
|
+
if (diff.hasChanged) {
|
|
67
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
68
|
+
driver.parseFiles();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
apply(compiler) {
|
|
73
|
+
const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
|
|
74
|
+
const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
|
|
75
|
+
import_transformer.pandaTransformer.webpack({
|
|
76
|
+
exclude: [/node_modules/],
|
|
77
|
+
...transformerOptions,
|
|
78
|
+
getCompiler: () => this.#driver?.compiler
|
|
79
|
+
}).apply(compiler);
|
|
80
|
+
const options = { getDriver: () => this.#driver };
|
|
81
|
+
compiler.options.module.rules.push({
|
|
82
|
+
test: /\.css$/,
|
|
83
|
+
exclude: /node_modules/,
|
|
84
|
+
enforce: "pre",
|
|
85
|
+
use: [{ loader: "@pandacss/webpack/css-loader", options }]
|
|
86
|
+
});
|
|
87
|
+
compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
|
|
88
|
+
compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/next.ts
|
|
93
|
+
function withPandaCss(nextConfig = {}, pandaOptions = {}) {
|
|
94
|
+
const plugin = new PandaWebpackPlugin(pandaOptions);
|
|
95
|
+
return {
|
|
96
|
+
...nextConfig,
|
|
97
|
+
webpack(config, context) {
|
|
98
|
+
config.plugins.push(plugin);
|
|
99
|
+
return typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var next_default = withPandaCss;
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
withPandaCss
|
|
107
|
+
});
|
package/dist/next.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PandaWebpackPluginOptions } from './index.cjs';
|
|
2
|
+
import '@pandacss/transformer';
|
|
3
|
+
import 'webpack';
|
|
4
|
+
|
|
5
|
+
type WebpackConfig = {
|
|
6
|
+
plugins: unknown[];
|
|
7
|
+
};
|
|
8
|
+
type NextConfig = {
|
|
9
|
+
webpack?: (config: WebpackConfig, context: unknown) => WebpackConfig;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a Next.js config to run Panda's webpack transform. Composes with any
|
|
14
|
+
* existing `webpack` function. Only affects the webpack build — Turbopack needs
|
|
15
|
+
* its own integration.
|
|
16
|
+
*/
|
|
17
|
+
declare function withPandaCss(nextConfig?: NextConfig, pandaOptions?: PandaWebpackPluginOptions): NextConfig;
|
|
18
|
+
|
|
19
|
+
export { withPandaCss as default, withPandaCss };
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PandaWebpackPluginOptions } from './index.js';
|
|
2
|
+
import '@pandacss/transformer';
|
|
3
|
+
import 'webpack';
|
|
4
|
+
|
|
5
|
+
type WebpackConfig = {
|
|
6
|
+
plugins: unknown[];
|
|
7
|
+
};
|
|
8
|
+
type NextConfig = {
|
|
9
|
+
webpack?: (config: WebpackConfig, context: unknown) => WebpackConfig;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a Next.js config to run Panda's webpack transform. Composes with any
|
|
14
|
+
* existing `webpack` function. Only affects the webpack build — Turbopack needs
|
|
15
|
+
* its own integration.
|
|
16
|
+
*/
|
|
17
|
+
declare function withPandaCss(nextConfig?: NextConfig, pandaOptions?: PandaWebpackPluginOptions): NextConfig;
|
|
18
|
+
|
|
19
|
+
export { withPandaCss as default, withPandaCss };
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createNodeDriver } from "@pandacss/compiler";
|
|
3
|
+
import { pandaTransformer } from "@pandacss/transformer";
|
|
4
|
+
var NAME = "PandaWebpackPlugin";
|
|
5
|
+
var PandaWebpackPlugin = class {
|
|
6
|
+
#options;
|
|
7
|
+
#driver;
|
|
8
|
+
#ready;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.#options = options;
|
|
11
|
+
}
|
|
12
|
+
#build(cwd) {
|
|
13
|
+
if (!this.#ready) {
|
|
14
|
+
this.#ready = (async () => {
|
|
15
|
+
const driver = await createNodeDriver({ cwd, configPath: this.#options.configPath });
|
|
16
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
17
|
+
driver.parseFiles();
|
|
18
|
+
this.#driver = driver;
|
|
19
|
+
})();
|
|
20
|
+
}
|
|
21
|
+
return this.#ready;
|
|
22
|
+
}
|
|
23
|
+
/** Watch-mode incremental sync: fold changed files into the driver before this
|
|
24
|
+
* rebuild's modules (including the layer-declaring CSS) are read. The driver
|
|
25
|
+
* re-reads changed files through its own fs. */
|
|
26
|
+
async #sync(cwd, changed) {
|
|
27
|
+
await this.#build(cwd);
|
|
28
|
+
const driver = this.#driver;
|
|
29
|
+
let configChanged = false;
|
|
30
|
+
for (const file of changed) {
|
|
31
|
+
if (driver.isConfigFile(file)) {
|
|
32
|
+
configChanged = true;
|
|
33
|
+
} else if (driver.isSourceFile(file)) {
|
|
34
|
+
driver.applyChange({ path: file, kind: "change" });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (configChanged) {
|
|
38
|
+
const diff = await driver.reload();
|
|
39
|
+
if (diff.hasChanged) {
|
|
40
|
+
driver.codegen({ cwd, outdir: this.#options.outdir });
|
|
41
|
+
driver.parseFiles();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
apply(compiler) {
|
|
46
|
+
const cwd = this.#options.cwd ?? compiler.context ?? process.cwd();
|
|
47
|
+
const { cwd: _cwd, configPath: _configPath, outdir: _outdir, ...transformerOptions } = this.#options;
|
|
48
|
+
pandaTransformer.webpack({
|
|
49
|
+
exclude: [/node_modules/],
|
|
50
|
+
...transformerOptions,
|
|
51
|
+
getCompiler: () => this.#driver?.compiler
|
|
52
|
+
}).apply(compiler);
|
|
53
|
+
const options = { getDriver: () => this.#driver };
|
|
54
|
+
compiler.options.module.rules.push({
|
|
55
|
+
test: /\.css$/,
|
|
56
|
+
exclude: /node_modules/,
|
|
57
|
+
enforce: "pre",
|
|
58
|
+
use: [{ loader: "@pandacss/webpack/css-loader", options }]
|
|
59
|
+
});
|
|
60
|
+
compiler.hooks.beforeCompile.tapPromise(NAME, () => this.#build(cwd));
|
|
61
|
+
compiler.hooks.watchRun.tapPromise(NAME, (c) => this.#sync(cwd, c.modifiedFiles ?? []));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/next.ts
|
|
66
|
+
function withPandaCss(nextConfig = {}, pandaOptions = {}) {
|
|
67
|
+
const plugin = new PandaWebpackPlugin(pandaOptions);
|
|
68
|
+
return {
|
|
69
|
+
...nextConfig,
|
|
70
|
+
webpack(config, context) {
|
|
71
|
+
config.plugins.push(plugin);
|
|
72
|
+
return typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var next_default = withPandaCss;
|
|
77
|
+
export {
|
|
78
|
+
next_default as default,
|
|
79
|
+
withPandaCss
|
|
80
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pandacss/webpack",
|
|
3
|
+
"version": "2.0.0-beta.9",
|
|
4
|
+
"description": "webpack plugin for Panda CSS (Next.js compatible)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"author": "Segun Adebayo <joseshegs@gmail.com>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./next": {
|
|
17
|
+
"source": "./src/next.ts",
|
|
18
|
+
"types": "./dist/next.d.ts",
|
|
19
|
+
"default": "./dist/next.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./css-loader": {
|
|
23
|
+
"source": "./src/css-loader.ts",
|
|
24
|
+
"types": "./dist/css-loader.d.ts",
|
|
25
|
+
"default": "./dist/css-loader.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"homepage": "https://panda-css.com",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/chakra-ui/panda.git",
|
|
33
|
+
"directory": "packages/webpack"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@pandacss/compiler": "2.0.0-beta.9",
|
|
43
|
+
"@pandacss/compiler-shared": "2.0.0-beta.9",
|
|
44
|
+
"@pandacss/transformer": "2.0.0-beta.9"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"webpack": ">=5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"webpack": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"webpack": "5.102.1"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=22"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup src/index.ts src/next.ts src/css-loader.ts --format=cjs,esm --platform=node --dts --no-splitting",
|
|
62
|
+
"build:fast": "tsup src/index.ts src/next.ts src/css-loader.ts --format=cjs,esm --platform=node --no-dts --no-splitting",
|
|
63
|
+
"dev": "pnpm build:fast --watch src",
|
|
64
|
+
"test": "vitest run"
|
|
65
|
+
}
|
|
66
|
+
}
|