uniwind-plugin-next 1.1.2 → 1.3.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 +21 -11
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +8 -365
- package/dist/index.d.cts +6 -9
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -9
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +8 -336
- package/dist/index.mjs.map +1 -0
- package/dist/postcss/index.cjs +8 -4
- package/dist/postcss/index.d.cts +10 -1
- package/dist/postcss/index.d.cts.map +1 -0
- package/dist/postcss/index.d.mts +11 -1
- package/dist/postcss/index.d.mts.map +1 -0
- package/dist/postcss/index.mjs +17 -19
- package/dist/postcss/index.mjs.map +1 -0
- package/dist/webpack/UniwindWebpackPlugin.cjs +49 -0
- package/dist/webpack/UniwindWebpackPlugin.mjs +48 -0
- package/dist/webpack/UniwindWebpackPlugin.mjs.map +1 -0
- package/dist/webpack/clientDirectiveLoader.js +8 -0
- package/dist/webpack/configInjectionLoader.js +6 -0
- package/dist/webpack/types.d.cts +9 -0
- package/dist/webpack/types.d.cts.map +1 -0
- package/dist/webpack/types.d.mts +9 -0
- package/dist/webpack/types.d.mts.map +1 -0
- package/dist/webpack/uniwind/package.cjs +11 -0
- package/dist/webpack/uniwind/package.mjs +6 -0
- package/dist/webpack/uniwind/package.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/index.cjs +28 -0
- package/dist/webpack/uniwind/src/css/index.mjs +26 -0
- package/dist/webpack/uniwind/src/css/index.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/insets.cjs +87 -0
- package/dist/webpack/uniwind/src/css/insets.mjs +87 -0
- package/dist/webpack/uniwind/src/css/insets.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/themes.cjs +84 -0
- package/dist/webpack/uniwind/src/css/themes.mjs +82 -0
- package/dist/webpack/uniwind/src/css/themes.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/variants.cjs +18 -0
- package/dist/webpack/uniwind/src/css/variants.mjs +18 -0
- package/dist/webpack/uniwind/src/css/variants.mjs.map +1 -0
- package/dist/webpack/uniwind/src/metro/logger.cjs +37 -0
- package/dist/webpack/uniwind/src/metro/logger.mjs +37 -0
- package/dist/webpack/uniwind/src/metro/logger.mjs.map +1 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.cjs +27 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.mjs +26 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.mjs.map +1 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.cjs +6 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.mjs +6 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.mjs.map +1 -0
- package/dist/webpack/util.cjs +6 -0
- package/dist/webpack/util.mjs +6 -0
- package/dist/webpack/util.mjs.map +1 -0
- package/dist/webpack/withUniwindBase.cjs +34 -0
- package/dist/webpack/withUniwindBase.mjs +32 -0
- package/dist/webpack/withUniwindBase.mjs.map +1 -0
- package/package.json +27 -8
- package/dist/chunk-3qlvafw2.mjs +0 -8
- package/dist/clientDirectiveLoader.js +0 -8
- package/dist/configInjectionLoader.js +0 -6
package/README.md
CHANGED
|
@@ -2,18 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
> This is an unofficial plugin, and is not affiliated with Uniwind or Next.js.
|
|
4
4
|
|
|
5
|
-
[Uniwind](https://uniwind.dev/) config plugin for Next.js. Note that only Webpack-based projects are supported, there are no plans to support Turbopack-based projects.
|
|
5
|
+
[Uniwind](https://uniwind.dev/) config plugin for Next.js. Note that only Webpack-based projects are supported, there are no plans to support Turbopack-based projects.
|
|
6
|
+
|
|
7
|
+
## Example
|
|
8
|
+
See a fully working example project here: [Demo](http://uniwind-next.a16n.dev/) ([Source](https://github.com/a16n-dev/uniwind-plugin-next/tree/main/examples/next-16))
|
|
6
9
|
|
|
7
|
-
The implementation of this plugin is based on the official [Uniwind Vite plugin](https://docs.uniwind.dev/quickstart#vite), and aims to match its functionality as closely as possible. All Uniwind features should work as expected - see the limitations section below for any documented differences.
|
|
8
10
|
|
|
9
11
|
## Compatibility
|
|
10
12
|
See the table below for tested versions of `uniwind-plugin-next` and corresponding versions of `uniwind`. Other versions of `uniwind` may work, but are not guaranteed to.
|
|
11
13
|
|
|
12
14
|
Tested on Next `16.1`, but other versions will likely work fine.
|
|
13
15
|
|
|
14
|
-
| uniwind-plugin-next |
|
|
15
|
-
|
|
16
|
-
| `1.
|
|
16
|
+
| Uniwind | uniwind-plugin-next |
|
|
17
|
+
|-----------------|---------------------|
|
|
18
|
+
| `1.2.2`-`1.2.3` | `1.1.0`-`1.2.0` |
|
|
19
|
+
| `1.2.4` | `1.3.0` |
|
|
17
20
|
|
|
18
21
|
## Installation & setup
|
|
19
22
|
This setup guide assumes you already have a next.js project setup with Tailwind v4
|
|
@@ -42,13 +45,24 @@ export default withUniwind(withExpo(nextConfig), {
|
|
|
42
45
|
// See https://docs.uniwind.dev/api/metro-config#configuration-options
|
|
43
46
|
});
|
|
44
47
|
```
|
|
48
|
+
#### Uniwind Pro
|
|
49
|
+
|
|
50
|
+
If you're using the pro version of Uniwind, use `withUniwindPro()` instead of `withUniwind()`.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// next.config.ts
|
|
54
|
+
import { withUniwindPro } from 'uniwind-plugin-next'
|
|
55
|
+
|
|
56
|
+
export default withUniwindPro(withExpo(nextConfig), { ... });
|
|
57
|
+
```
|
|
58
|
+
|
|
45
59
|
|
|
46
60
|
3. Add the postcss plugin
|
|
47
61
|
```js
|
|
48
62
|
const config = {
|
|
49
63
|
plugins: {
|
|
50
|
-
'@tailwindcss/postcss': {},
|
|
51
64
|
'uniwind-plugin-next/postcss': {}, // Add this line
|
|
65
|
+
'@tailwindcss/postcss': {},
|
|
52
66
|
},
|
|
53
67
|
};
|
|
54
68
|
|
|
@@ -80,8 +94,4 @@ return (
|
|
|
80
94
|
|
|
81
95
|
- Be aware that some Uniwind features, such as `withUniwind` and `useResolveClassNames` will not work in a server environment, as they rely on accessing `window` or `document`.
|
|
82
96
|
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
## Known limitations
|
|
86
|
-
|
|
87
|
-
- This plugin uses a much more primitive regex-based postcss plugin for transforming Uniwind CSS functions (`pixelRatio()`, `fontScale()`, `hairlineWidth()`) compared to the official Vite plugin (which uses a full AST parser). As a result, some edge cases may not be handled correctly. If you do not use these functions in your CSS, this will not impact you. If you do run into any issues, please open an issue.
|
|
97
|
+
- Additional code is required to avoid a flash of unstyled content (FOUC). See the example project for reference.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
CHANGED
|
@@ -1,370 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
1
|
+
const require_withUniwindBase = require('./webpack/withUniwindBase.cjs');
|
|
26
2
|
|
|
27
|
-
//#
|
|
28
|
-
let webpack = require("webpack");
|
|
29
|
-
webpack = __toESM(webpack);
|
|
30
|
-
let path = require("path");
|
|
31
|
-
path = __toESM(path);
|
|
32
|
-
let fs = require("fs");
|
|
33
|
-
fs = __toESM(fs);
|
|
34
|
-
let _tailwindcss_node = require("@tailwindcss/node");
|
|
35
|
-
let lightningcss = require("lightningcss");
|
|
36
|
-
|
|
37
|
-
//#region src/webpack/uniwind/src/utils/common.ts
|
|
38
|
-
const uniq = (arr) => Array.from(new Set(arr));
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/webpack/patchFsForWritingUniwindCSSFile.ts
|
|
42
|
-
const uniwindDir = path.default.dirname(require.resolve("uniwind/package.json"));
|
|
43
|
-
/**
|
|
44
|
-
* The contents of the `css` directory is copied direct from the uniwind source code. This makes it easier to keep it in
|
|
45
|
-
* sync with the upstream uniwind package, so we purposefully avoid modifying any code in `css`.
|
|
46
|
-
*
|
|
47
|
-
* However, we do need to patch `buildCSS()` to output the generated `uniwind.css` file into the `uniwind` package directory
|
|
48
|
-
* within node_modules. To do this we temporarily patch `fs.writeFileSync` to redirect all writes of `uniwind.css` to the
|
|
49
|
-
* correct location.
|
|
50
|
-
*
|
|
51
|
-
* Usage:
|
|
52
|
-
* ```ts
|
|
53
|
-
* const unpatchFs = patchFs();
|
|
54
|
-
* await buildCSS(themes, cssEntryFile);
|
|
55
|
-
* unpatchFs();
|
|
56
|
-
*/
|
|
57
|
-
function patchFsForWritingUniwindCSSFile() {
|
|
58
|
-
const originalWriteFileSync = fs.default.writeFileSync;
|
|
59
|
-
fs.default.writeFileSync = function(_path, data, options) {
|
|
60
|
-
let newPath = _path;
|
|
61
|
-
if (typeof newPath === "string" && newPath.endsWith("uniwind.css")) newPath = path.default.join(uniwindDir, "uniwind.css");
|
|
62
|
-
return originalWriteFileSync.call(fs.default, newPath, data, options);
|
|
63
|
-
};
|
|
64
|
-
return function unpatchFs() {
|
|
65
|
-
fs.default.writeFileSync = originalWriteFileSync;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/webpack/uniwind/src/css/insets.ts
|
|
71
|
-
const types = ["m", "p"];
|
|
72
|
-
const sides = [
|
|
73
|
-
"",
|
|
74
|
-
"x",
|
|
75
|
-
"y",
|
|
76
|
-
"t",
|
|
77
|
-
"b",
|
|
78
|
-
"l",
|
|
79
|
-
"r"
|
|
80
|
-
];
|
|
81
|
-
const spacing = "--spacing(--value(integer))";
|
|
82
|
-
const length = "--value([length])";
|
|
83
|
-
const generateCSSForInsets = () => {
|
|
84
|
-
let css = `@utility h-screen-safe {
|
|
85
|
-
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
86
|
-
}\n`;
|
|
87
|
-
const getInsetsForSide = (side) => {
|
|
88
|
-
switch (side) {
|
|
89
|
-
case "t": return ["top"];
|
|
90
|
-
case "b": return ["bottom"];
|
|
91
|
-
case "l": return ["left"];
|
|
92
|
-
case "r": return ["right"];
|
|
93
|
-
case "x": return ["left", "right"];
|
|
94
|
-
case "y": return ["top", "bottom"];
|
|
95
|
-
default: return [
|
|
96
|
-
"top",
|
|
97
|
-
"bottom",
|
|
98
|
-
"left",
|
|
99
|
-
"right"
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
types.forEach((type) => {
|
|
104
|
-
sides.forEach((side) => {
|
|
105
|
-
const styleName = type === "m" ? "margin" : "padding";
|
|
106
|
-
const styles = getInsetsForSide(side).map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
107
|
-
const safeStyles = styles.flatMap((style) => {
|
|
108
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
109
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)];
|
|
110
|
-
});
|
|
111
|
-
const safeOffsetStyles = styles.flatMap((style) => {
|
|
112
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
113
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)];
|
|
114
|
-
});
|
|
115
|
-
css += `
|
|
116
|
-
@utility ${type}${side}-safe {
|
|
117
|
-
${styles.join("\n ")}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@utility ${type}${side}-safe-or-* {
|
|
121
|
-
${safeStyles.join("\n ")}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@utility ${type}${side}-safe-offset-* {
|
|
125
|
-
${safeOffsetStyles.join("\n ")}
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
return css.replaceAll(" ", "").trim() + "\n";
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/webpack/uniwind/src/metro/logger.ts
|
|
135
|
-
const red = "\x1B[91m";
|
|
136
|
-
const yellow = "\x1B[33m";
|
|
137
|
-
const blue = "\x1B[36m";
|
|
138
|
-
const reset = "\x1B[0m";
|
|
139
|
-
var Logger = class Logger {
|
|
140
|
-
static {
|
|
141
|
-
this.debug = false;
|
|
142
|
-
}
|
|
143
|
-
constructor(name$1) {
|
|
144
|
-
this.name = name$1;
|
|
145
|
-
}
|
|
146
|
-
static log(message, meta = "") {
|
|
147
|
-
if (!Logger.debug) return;
|
|
148
|
-
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);
|
|
149
|
-
}
|
|
150
|
-
static error(message, meta = "") {
|
|
151
|
-
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);
|
|
152
|
-
}
|
|
153
|
-
static warn(message, meta = "") {
|
|
154
|
-
if (!Logger.debug) return;
|
|
155
|
-
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);
|
|
156
|
-
}
|
|
157
|
-
log(message) {
|
|
158
|
-
Logger.log(message, `[${this.name} Processor] `);
|
|
159
|
-
}
|
|
160
|
-
error(message) {
|
|
161
|
-
Logger.error(message, `[${this.name} Processor] `);
|
|
162
|
-
}
|
|
163
|
-
warn(message) {
|
|
164
|
-
Logger.warn(message, `[${this.name} Processor] `);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/webpack/uniwind/src/css/themes.ts
|
|
170
|
-
const readFileSafe = (filePath) => {
|
|
171
|
-
try {
|
|
172
|
-
return fs.default.readFileSync(filePath, "utf-8");
|
|
173
|
-
} catch {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const isExcludedDependency = (url) => [
|
|
178
|
-
url.includes("node_modules/tailwindcss"),
|
|
179
|
-
url.includes("node_modules/@tailwindcss"),
|
|
180
|
-
url.includes("node_modules/uniwind")
|
|
181
|
-
].some(Boolean);
|
|
182
|
-
const generateCSSForThemes = async (themes, input) => {
|
|
183
|
-
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
184
|
-
const findVariantsRec = async (cssPath) => {
|
|
185
|
-
const css = readFileSafe(cssPath);
|
|
186
|
-
if (css === null) return;
|
|
187
|
-
const { dependencies } = (0, lightningcss.transform)({
|
|
188
|
-
code: Buffer.from(css),
|
|
189
|
-
filename: "uniwind.css",
|
|
190
|
-
analyzeDependencies: true,
|
|
191
|
-
visitor: { Rule: (rule) => {
|
|
192
|
-
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
193
|
-
const [firstPrelude] = rule.value.prelude;
|
|
194
|
-
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) return;
|
|
195
|
-
const theme = firstPrelude.value.value;
|
|
196
|
-
rule.value.block?.forEach((block) => {
|
|
197
|
-
if (block.type === "dashed-ident") themesVariables[theme]?.add(block.value);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
} }
|
|
201
|
-
});
|
|
202
|
-
if (!Array.isArray(dependencies)) return;
|
|
203
|
-
const importUrls = /* @__PURE__ */ new Set();
|
|
204
|
-
await (0, _tailwindcss_node.compile)(dependencies.filter((dependency) => {
|
|
205
|
-
if (dependency.url.startsWith(".")) {
|
|
206
|
-
importUrls.add(path.default.resolve(path.default.dirname(cssPath), dependency.url));
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return !isExcludedDependency(dependency.url);
|
|
210
|
-
}).map((dependency) => `@import "${dependency.url}";`).join("\n"), {
|
|
211
|
-
base: path.default.resolve(path.default.dirname(cssPath)),
|
|
212
|
-
onDependency: (dependency) => {
|
|
213
|
-
if (isExcludedDependency(dependency)) return;
|
|
214
|
-
importUrls.add(dependency);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
for (const filePath of importUrls) await findVariantsRec(filePath);
|
|
218
|
-
};
|
|
219
|
-
await findVariantsRec(input);
|
|
220
|
-
let hasErrors = false;
|
|
221
|
-
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
222
|
-
Object.values(themesVariables).forEach((variables) => {
|
|
223
|
-
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
224
|
-
variables.forEach((variable) => {
|
|
225
|
-
if (!checkedVariables.has(variable)) {
|
|
226
|
-
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
227
|
-
hasErrors = true;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
if (hasErrors) Logger.error("All themes must have the same variables");
|
|
233
|
-
const variablesCSS = hasVariables ? [
|
|
234
|
-
"",
|
|
235
|
-
"@theme {",
|
|
236
|
-
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
237
|
-
"}"
|
|
238
|
-
] : [];
|
|
239
|
-
return [...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`), ...variablesCSS].join("\n");
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/webpack/uniwind/src/css/variants.ts
|
|
244
|
-
const variants = [
|
|
245
|
-
"ios",
|
|
246
|
-
"android",
|
|
247
|
-
"web",
|
|
248
|
-
"native"
|
|
249
|
-
];
|
|
250
|
-
const generateCSSForVariants = () => {
|
|
251
|
-
let css = "";
|
|
252
|
-
variants.forEach((variant) => {
|
|
253
|
-
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});\n`;
|
|
254
|
-
});
|
|
255
|
-
return css;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region src/webpack/uniwind/src/css/index.ts
|
|
260
|
-
const dirname$1 = typeof __dirname !== "undefined" ? __dirname : __dirname;
|
|
261
|
-
const buildCSS = async (themes, input) => {
|
|
262
|
-
const variants$1 = generateCSSForVariants();
|
|
263
|
-
const insets = generateCSSForInsets();
|
|
264
|
-
const themesCSS = await generateCSSForThemes(themes, input);
|
|
265
|
-
const cssFile = path.default.join(dirname$1, "../../uniwind.css");
|
|
266
|
-
if ((fs.default.existsSync(cssFile) ? fs.default.readFileSync(cssFile, "utf-8") : "") === cssFile) return;
|
|
267
|
-
fs.default.writeFileSync(cssFile, [
|
|
268
|
-
variants$1,
|
|
269
|
-
insets,
|
|
270
|
-
themesCSS
|
|
271
|
-
].join("\n"));
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/webpack/uniwind/package.json
|
|
276
|
-
var name = "uniwind";
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region src/webpack/uniwind/src/utils/buildDtsFile.ts
|
|
280
|
-
const buildDtsFile = (dtsPath, stringifiedThemes) => {
|
|
281
|
-
const oldDtsContent = fs.default.existsSync(dtsPath) ? fs.default.readFileSync(dtsPath, "utf-8") : "";
|
|
282
|
-
const dtsContent = [
|
|
283
|
-
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
|
|
284
|
-
`/// <reference types="${name}/types" />`,
|
|
285
|
-
"",
|
|
286
|
-
`declare module '${name}' {`,
|
|
287
|
-
` export interface UniwindConfig {`,
|
|
288
|
-
` themes: readonly ${stringifiedThemes}`,
|
|
289
|
-
` }`,
|
|
290
|
-
`}`,
|
|
291
|
-
"",
|
|
292
|
-
`export {}`,
|
|
293
|
-
""
|
|
294
|
-
].join("\n");
|
|
295
|
-
if (oldDtsContent === dtsContent) return;
|
|
296
|
-
fs.default.writeFileSync(dtsPath, dtsContent);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/webpack/uniwind/src/utils/stringifyThemes.ts
|
|
301
|
-
const stringifyThemes = (themes = []) => `[${themes.map((theme) => `'${theme}'`).join(", ")}]`;
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/webpack/UniwindWebpackPlugin.ts
|
|
305
|
-
const dirname = typeof __dirname !== "undefined" ? __dirname : __dirname;
|
|
306
|
-
var UniwindWebpackPlugin = class {
|
|
307
|
-
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
308
|
-
this.hasRun = false;
|
|
309
|
-
this.themes = uniq([
|
|
310
|
-
"light",
|
|
311
|
-
"dark",
|
|
312
|
-
...extraThemes ?? []
|
|
313
|
-
]);
|
|
314
|
-
this.dtsFile = dtsFile;
|
|
315
|
-
this.cssEntryFile = cssEntryFile;
|
|
316
|
-
}
|
|
317
|
-
apply(compiler) {
|
|
318
|
-
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
319
|
-
if (this.hasRun) return;
|
|
320
|
-
this.hasRun = true;
|
|
321
|
-
const removePatch = patchFsForWritingUniwindCSSFile();
|
|
322
|
-
await buildCSS(this.themes, this.cssEntryFile);
|
|
323
|
-
removePatch();
|
|
324
|
-
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
325
|
-
});
|
|
326
|
-
compiler.options.module = compiler.options.module || { rules: [] };
|
|
327
|
-
compiler.options.module.rules.push({
|
|
328
|
-
test: /config\.c?js$/,
|
|
329
|
-
include: /uniwind[\/\\]dist/,
|
|
330
|
-
use: [{
|
|
331
|
-
loader: path.default.resolve(dirname, "configInjectionLoader.js"),
|
|
332
|
-
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
333
|
-
}]
|
|
334
|
-
});
|
|
335
|
-
compiler.options.module.rules.push({
|
|
336
|
-
test: /\.js$/,
|
|
337
|
-
exclude: /index\.js$/,
|
|
338
|
-
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
339
|
-
use: [{ loader: path.default.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/webpack/withUniwind.ts
|
|
346
|
-
const { NormalModuleReplacementPlugin } = webpack.default;
|
|
3
|
+
//#region src/index.ts
|
|
347
4
|
function withUniwind(nextConfig = {}, uniwindConfig) {
|
|
348
|
-
return
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
"uniwind",
|
|
353
|
-
"react-native",
|
|
354
|
-
"react-native-web"
|
|
355
|
-
]),
|
|
356
|
-
webpack(config, options) {
|
|
357
|
-
if (!config.plugins) config.plugins = [];
|
|
358
|
-
config.plugins.push(new NormalModuleReplacementPlugin(/^react-native$/, (resource) => {
|
|
359
|
-
if ((resource.context || "").includes(`${path.default.sep}uniwind${path.default.sep}dist${path.default.sep}module${path.default.sep}components${path.default.sep}web`)) resource.request = "react-native-web";
|
|
360
|
-
else resource.request = "uniwind/components/index";
|
|
361
|
-
}));
|
|
362
|
-
config.plugins.push(new UniwindWebpackPlugin(uniwindConfig));
|
|
363
|
-
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, options);
|
|
364
|
-
return config;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
5
|
+
return require_withUniwindBase.withUniwindBase("uniwind", nextConfig, uniwindConfig);
|
|
6
|
+
}
|
|
7
|
+
function withUniwindPro(nextConfig = {}, uniwindConfig) {
|
|
8
|
+
return require_withUniwindBase.withUniwindBase("uniwind-pro", nextConfig, uniwindConfig);
|
|
367
9
|
}
|
|
368
10
|
|
|
369
11
|
//#endregion
|
|
370
|
-
exports.withUniwind = withUniwind;
|
|
12
|
+
exports.withUniwind = withUniwind;
|
|
13
|
+
exports.withUniwindPro = withUniwindPro;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extraThemes?: Array<string>;
|
|
5
|
-
dtsFile?: string;
|
|
6
|
-
};
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/webpack/withUniwind.d.ts
|
|
1
|
+
import { UniwindConfig } from "./webpack/types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
9
4
|
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
5
|
+
declare function withUniwindPro(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
10
6
|
//#endregion
|
|
11
|
-
export { withUniwind };
|
|
7
|
+
export { withUniwind, withUniwindPro };
|
|
8
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,WAAA,6CAEC;iBAKD,cAAA,6CAEC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extraThemes?: Array<string>;
|
|
5
|
-
dtsFile?: string;
|
|
6
|
-
};
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/webpack/withUniwind.d.ts
|
|
1
|
+
import { UniwindConfig } from "./webpack/types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
9
4
|
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
5
|
+
declare function withUniwindPro(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
10
6
|
//#endregion
|
|
11
|
-
export { withUniwind };
|
|
7
|
+
export { withUniwind, withUniwindPro };
|
|
8
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;iBAGgB,WAAA,6CAEC;iBAKD,cAAA,6CAEC"}
|