weapp-tailwindcss 5.0.0-next.8 → 5.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 +2 -2
- package/dist/auto-DEHRmEAx.mjs +200 -0
- package/dist/auto-dPpsm6FB.js +238 -0
- package/dist/bundle-state-CnaJxkFY.mjs +413 -0
- package/dist/bundle-state-DgGEhk_z.js +529 -0
- package/dist/bundlers/shared/cache.d.ts +9 -7
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -2
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -3
- package/dist/bundlers/shared/css-imports.d.ts +3 -3
- package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +12 -3
- package/dist/bundlers/shared/generator-css/markers.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
- package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
- package/dist/bundlers/shared/generator-css.d.ts +6 -2
- package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
- package/dist/bundlers/shared/style-requests.d.ts +2 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +13 -1
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +10 -2
- package/dist/bundlers/vite/index.d.ts +5 -2
- package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -5
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -1
- package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
- package/dist/bundlers/vite/source-candidates.d.ts +24 -2
- package/dist/bundlers/vite/source-scan.d.ts +26 -0
- package/dist/bundlers/vite/static-config-content.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +8 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -1
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -8
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
- package/dist/cache/index.d.ts +6 -6
- package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
- package/dist/cli/context.d.ts +1 -11
- package/dist/cli/doctor/types.d.ts +11 -11
- package/dist/cli/vscode-entry.d.ts +3 -3
- package/dist/cli.js +684 -41
- package/dist/cli.mjs +682 -40
- package/dist/context/runtime-package-replacements.d.ts +2 -0
- package/dist/context/style-options.d.ts +3 -0
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/core.js +1 -2
- package/dist/core.mjs +1 -1
- package/dist/css-macro/auto.d.ts +11 -0
- package/dist/css-macro/constants.d.ts +5 -2
- package/dist/css-macro/postcss.d.ts +1 -0
- package/dist/css-macro/postcss.js +7 -46
- package/dist/css-macro/postcss.mjs +2 -46
- package/dist/css-macro.js +16 -7
- package/dist/css-macro.mjs +15 -6
- package/dist/defaults-8xrgzxFY.mjs +151 -0
- package/dist/defaults-zKUH2mDe.js +193 -0
- package/dist/defaults.js +6 -150
- package/dist/defaults.mjs +1 -143
- package/dist/escape.js +10 -2
- package/dist/escape.mjs +10 -2
- package/dist/generator/options.d.ts +11 -6
- package/dist/generator/types.d.ts +3 -3
- package/dist/generator--0-ekuVO.js +92 -0
- package/dist/generator-B76ovqsv.mjs +67 -0
- package/dist/generator.js +12 -12
- package/dist/generator.mjs +2 -1
- package/dist/gulp.js +163 -40
- package/dist/gulp.mjs +155 -32
- package/dist/incremental-runtime-class-set-CN6K_97P.js +2366 -0
- package/dist/incremental-runtime-class-set-x10M9bn_.mjs +2291 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +17 -5
- package/dist/index.mjs +6 -5
- package/dist/js/babel/cache-options.d.ts +3 -0
- package/dist/js/babel/parse.d.ts +7 -4
- package/dist/js/precheck.d.ts +2 -2
- package/dist/js/replacement-cache.d.ts +5 -0
- package/dist/postcss-C7BMYpEF.mjs +169 -0
- package/dist/{postcss-w48mGIhe.mjs → postcss-CR9UCaIK.mjs} +54 -114
- package/dist/postcss-CiYLsqZn.js +192 -0
- package/dist/{postcss-QIXwT40c.js → postcss-hYimKoN_.js} +60 -121
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/precheck-BrNwLG2e.mjs +4716 -0
- package/dist/precheck-DPtJjZmV.js +4842 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/uni-app-x.d.ts +1 -0
- package/dist/presets.js +27 -13
- package/dist/presets.mjs +25 -13
- package/dist/reset.js +1 -1
- package/dist/runtime-registry-DpcR3IHI.js +5496 -0
- package/dist/shared/mpx.d.ts +1 -0
- package/dist/source-candidates-DN1mihlU.mjs +322 -0
- package/dist/source-candidates-DSxme_O2.js +335 -0
- package/dist/tailwindcss/miniprogram.d.ts +1 -5
- package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
- package/dist/tailwindcss/runtime/cache.d.ts +4 -3
- package/dist/tailwindcss/runtime.d.ts +9 -9
- package/dist/tailwindcss/source-scan.d.ts +35 -0
- package/dist/tailwindcss/v3-engine/types.d.ts +19 -14
- package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
- package/dist/tailwindcss/v4/patcher.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
- package/dist/tailwindcss/v4-engine/types.d.ts +18 -5
- package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-DWtPieNE.mjs} +72 -60
- package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-glCm_d3H.js} +81 -69
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +51 -41
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/typedoc-tailwindcss-patch.d.ts +67 -0
- package/dist/types/user-defined-options/general.d.ts +25 -22
- package/dist/types/user-defined-options/important.d.ts +32 -27
- package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
- package/dist/types/user-defined-options/matcher.d.ts +6 -6
- package/dist/unocss/index.d.ts +2 -0
- package/dist/utils/object.d.ts +9 -0
- package/dist/utils/options.d.ts +2 -0
- package/dist/utils/regex.d.ts +1 -0
- package/dist/{utils-BiShvil9.js → utils-D7Ygohep.js} +2 -2
- package/dist/{utils-Btw1iOVV.mjs → utils-DsaS975I.mjs} +1 -1
- package/dist/v3-engine-D3BMLVAN.js +3712 -0
- package/dist/v3-engine-DCxNPBVs.mjs +3417 -0
- package/dist/vite-DOprpdH-.mjs +24493 -0
- package/dist/vite-Ec0uX6kF.js +24507 -0
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5444 -22
- package/dist/weapp-tw-runtime-classset-loader.js +32 -9
- package/dist/{webpack-CNV2dx3Q.js → webpack-Ccohlg3A.js} +341 -96
- package/dist/{webpack-CT6EEENx.mjs → webpack-DFlZcqAU.mjs} +323 -79
- package/dist/webpack.d.ts +1 -3
- package/dist/webpack.js +3 -4
- package/dist/webpack.mjs +2 -2
- package/dist/wxml/utils/codegen/legacy-visitor.d.ts +2 -4
- package/package.json +22 -20
- package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +0 -3
- package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +0 -4
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +0 -8
- package/dist/cache-BVAiJV3J.js +0 -502
- package/dist/cache-CHs4DXui.mjs +0 -434
- package/dist/constants-BoB_6lFw.js +0 -73
- package/dist/constants-E_loJC49.mjs +0 -44
- package/dist/generator-DKkhJbOg.js +0 -1531
- package/dist/generator-UBmfduYg.mjs +0 -1432
- package/dist/generator-css-BIapP56i.mjs +0 -1323
- package/dist/generator-css-Mksw8PgB.js +0 -1362
- package/dist/lightningcss/index.d.ts +0 -8
- package/dist/lightningcss/style-handler/options.d.ts +0 -3
- package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
- package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
- package/dist/lightningcss/style-handler.d.ts +0 -17
- package/dist/precheck-B32p-gLI.js +0 -2736
- package/dist/precheck-B4RH6ZNN.mjs +0 -2622
- package/dist/run-tasks-B50A3pxt.js +0 -128
- package/dist/run-tasks-DdNi-hkk.mjs +0 -91
- package/dist/runtime-patch-CwN5ya72.mjs +0 -71
- package/dist/runtime-patch-D6mBo_KB.js +0 -85
- package/dist/vite-BwgRVgxH.mjs +0 -2405
- package/dist/vite-DyZuiyap.js +0 -2418
- /package/dist/{logger-Bub1jggA.mjs → logger-BNzxZbZj.mjs} +0 -0
- /package/dist/{logger-BRy6XPQ2.js → logger-TlKT3xmR.js} +0 -0
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const require_precheck = require("./precheck-
|
|
6
|
-
const require_utils = require("./utils-
|
|
7
|
-
const require_tailwindcss = require("./tailwindcss-
|
|
8
|
-
const
|
|
1
|
+
const require_chunk = require("./chunk-C5U5_Hdc.js");
|
|
2
|
+
const require_v3_engine = require("./v3-engine-D3BMLVAN.js");
|
|
3
|
+
const require_generator = require("./generator--0-ekuVO.js");
|
|
4
|
+
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-CN6K_97P.js");
|
|
5
|
+
const require_precheck = require("./precheck-DPtJjZmV.js");
|
|
6
|
+
const require_utils = require("./utils-D7Ygohep.js");
|
|
7
|
+
const require_tailwindcss = require("./tailwindcss-glCm_d3H.js");
|
|
8
|
+
const require_bundle_state = require("./bundle-state-DgGEhk_z.js");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
node_fs = require_chunk.__toESM(node_fs);
|
|
9
11
|
let node_module = require("node:module");
|
|
10
12
|
node_module = require_chunk.__toESM(node_module);
|
|
11
|
-
let node_path = require("node:path");
|
|
12
|
-
node_path = require_chunk.__toESM(node_path);
|
|
13
13
|
let node_process = require("node:process");
|
|
14
14
|
node_process = require_chunk.__toESM(node_process);
|
|
15
|
-
let
|
|
16
|
-
|
|
15
|
+
let node_path = require("node:path");
|
|
16
|
+
node_path = require_chunk.__toESM(node_path);
|
|
17
|
+
let micromatch = require("micromatch");
|
|
18
|
+
micromatch = require_chunk.__toESM(micromatch);
|
|
17
19
|
//#region src/shared/tailwindcss-css-redirect.ts
|
|
18
20
|
const moduleWithMutableResolve = node_module.default;
|
|
19
21
|
const patched = /* @__PURE__ */ new WeakSet();
|
|
@@ -34,6 +36,7 @@ function installTailwindcssCssRedirect(pkgDir) {
|
|
|
34
36
|
//#region src/shared/mpx.ts
|
|
35
37
|
const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
36
38
|
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
39
|
+
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
37
40
|
function isMpxStyleResourceQuery(query) {
|
|
38
41
|
if (typeof query !== "string") return false;
|
|
39
42
|
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
@@ -54,19 +57,44 @@ function resolveMpxWebpackPluginDir(compiler) {
|
|
|
54
57
|
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
55
58
|
return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
56
59
|
} catch {}
|
|
57
|
-
|
|
60
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
61
|
+
if (cachedPackageJson) return node_path.default.dirname(cachedPackageJson);
|
|
62
|
+
try {
|
|
63
|
+
return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
64
|
+
} catch {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
function isMpxWebpackPluginRequest(request) {
|
|
60
69
|
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
61
70
|
}
|
|
71
|
+
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
72
|
+
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
73
|
+
return node_path.default.join(mpxWebpackPluginDir, request.slice(22));
|
|
74
|
+
}
|
|
62
75
|
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
76
|
+
const recordLoader = node_path.default.join(pkgDir, "lib/record-loader");
|
|
77
|
+
const styleCompiler = node_path.default.join(pkgDir, "lib/style-compiler/index");
|
|
78
|
+
const stripConditionalLoader = node_path.default.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
63
79
|
if (Array.isArray(alias)) alias.push({
|
|
80
|
+
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
81
|
+
alias: recordLoader
|
|
82
|
+
}, {
|
|
83
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
84
|
+
alias: styleCompiler
|
|
85
|
+
}, {
|
|
86
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
87
|
+
alias: stripConditionalLoader
|
|
88
|
+
}, {
|
|
64
89
|
name: /^@mpxjs\/webpack-plugin\//,
|
|
65
90
|
alias: pkgDir
|
|
66
91
|
});
|
|
67
92
|
else {
|
|
68
93
|
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
69
94
|
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
95
|
+
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
96
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
97
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
70
98
|
}
|
|
71
99
|
}
|
|
72
100
|
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
@@ -75,18 +103,48 @@ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
|
75
103
|
compiler.options.resolveLoader.alias = alias;
|
|
76
104
|
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
77
105
|
}
|
|
106
|
+
function resolveMpxWebpackPluginRequire(compiler) {
|
|
107
|
+
const candidates = [
|
|
108
|
+
compiler?.context,
|
|
109
|
+
compiler?.options?.context,
|
|
110
|
+
node_process.default.cwd()
|
|
111
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
112
|
+
for (const candidate of candidates) try {
|
|
113
|
+
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
114
|
+
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
115
|
+
return projectRequire;
|
|
116
|
+
} catch {}
|
|
117
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
118
|
+
if (cachedPackageJson) return (0, node_module.createRequire)(cachedPackageJson);
|
|
119
|
+
return localRequire;
|
|
120
|
+
}
|
|
121
|
+
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
122
|
+
if (!mpxWebpackPluginDir) return false;
|
|
123
|
+
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
124
|
+
let normalize;
|
|
125
|
+
try {
|
|
126
|
+
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
127
|
+
} catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (typeof normalize.lib !== "function") return false;
|
|
131
|
+
if (normalize.lib.__weappTwPatched) return true;
|
|
132
|
+
const wrappedLib = (file) => node_path.default.join(mpxWebpackPluginDir, "lib", file);
|
|
133
|
+
wrappedLib.__weappTwPatched = true;
|
|
134
|
+
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
135
|
+
normalize.lib = wrappedLib;
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
78
138
|
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
79
139
|
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
80
140
|
compiler.options = compiler.options || {};
|
|
81
141
|
compiler.options.resolve = compiler.options.resolve || {};
|
|
82
142
|
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
83
|
-
|
|
143
|
+
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
144
|
+
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
84
145
|
const alias = compiler.options.resolve.alias ?? {};
|
|
85
146
|
compiler.options.resolve.alias = alias;
|
|
86
147
|
if (Array.isArray(alias)) alias.push({
|
|
87
|
-
name: /^@mpxjs\/webpack-plugin\//,
|
|
88
|
-
alias: mpxWebpackPluginDir
|
|
89
|
-
}, {
|
|
90
148
|
name: "tailwindcss",
|
|
91
149
|
alias: tailwindcssCssEntry
|
|
92
150
|
}, {
|
|
@@ -94,11 +152,10 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
|
94
152
|
alias: tailwindcssCssEntry
|
|
95
153
|
});
|
|
96
154
|
else {
|
|
97
|
-
alias["@mpxjs/webpack-plugin"] = mpxWebpackPluginDir;
|
|
98
|
-
alias["@mpxjs/webpack-plugin$"] = mpxWebpackPluginDir;
|
|
99
155
|
alias.tailwindcss = tailwindcssCssEntry;
|
|
100
156
|
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
101
157
|
}
|
|
158
|
+
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
102
159
|
return tailwindcssCssEntry;
|
|
103
160
|
}
|
|
104
161
|
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
@@ -106,10 +163,11 @@ function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
|
106
163
|
const originalResolve = loaderContext.resolve;
|
|
107
164
|
if (originalResolve.__weappTwPatched) return;
|
|
108
165
|
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
166
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
109
167
|
const wrappedResolve = function(context, request, callback) {
|
|
110
168
|
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
111
169
|
if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
|
|
112
|
-
if (isMpxWebpackPluginRequest(request)) return
|
|
170
|
+
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
113
171
|
return originalResolve.call(this, context, request, callback);
|
|
114
172
|
};
|
|
115
173
|
wrappedResolve.__weappTwPatched = true;
|
|
@@ -145,16 +203,13 @@ function getCacheKey(filename) {
|
|
|
145
203
|
}
|
|
146
204
|
function stripResourceQuery(resource) {
|
|
147
205
|
if (typeof resource !== "string") return resource;
|
|
148
|
-
|
|
149
|
-
if (queryIndex !== -1) return resource.slice(0, queryIndex);
|
|
150
|
-
const hashIndex = resource.indexOf("#");
|
|
151
|
-
if (hashIndex !== -1) return resource.slice(0, hashIndex);
|
|
152
|
-
return resource;
|
|
206
|
+
return require_bundle_state.stripRequestQuery(resource);
|
|
153
207
|
}
|
|
154
208
|
function isCssLikeModuleResource(resource, cssMatcher, appType) {
|
|
155
209
|
if (typeof resource !== "string") return false;
|
|
156
210
|
const normalizedResource = stripResourceQuery(resource);
|
|
157
211
|
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
212
|
+
if (require_bundle_state.isSourceStyleRequest(resource)) return true;
|
|
158
213
|
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
159
214
|
return false;
|
|
160
215
|
}
|
|
@@ -162,6 +217,13 @@ function hasLoaderEntry(entries, target) {
|
|
|
162
217
|
if (!target) return false;
|
|
163
218
|
return entries.some((entry) => entry.loader?.includes?.(target));
|
|
164
219
|
}
|
|
220
|
+
function normalizeWatchPath(file) {
|
|
221
|
+
return node_path.default.resolve(file);
|
|
222
|
+
}
|
|
223
|
+
function isFileInContext(file, context) {
|
|
224
|
+
const relative = node_path.default.relative(normalizeWatchPath(context), normalizeWatchPath(file));
|
|
225
|
+
return relative.length > 0 && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
226
|
+
}
|
|
165
227
|
function toChunkFiles(files) {
|
|
166
228
|
if (!files) return [];
|
|
167
229
|
if (Array.isArray(files)) return files;
|
|
@@ -190,17 +252,38 @@ function createAssetHashByChunkMap(chunks) {
|
|
|
190
252
|
function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
|
|
191
253
|
return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
|
|
192
254
|
}
|
|
193
|
-
function
|
|
194
|
-
|
|
255
|
+
function isWatchFileInRuntimeDependencies(file, dependencies) {
|
|
256
|
+
const normalizedFile = normalizeWatchPath(file);
|
|
257
|
+
for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
|
|
258
|
+
for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
|
|
259
|
+
return false;
|
|
195
260
|
}
|
|
196
261
|
//#endregion
|
|
197
262
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
|
|
263
|
+
function createWebpackSnapshotAssets(assets) {
|
|
264
|
+
return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
|
|
265
|
+
const source = asset.source();
|
|
266
|
+
return [file, {
|
|
267
|
+
fileName: file,
|
|
268
|
+
source: typeof source === "string" ? source : source?.toString() ?? "",
|
|
269
|
+
type: "asset"
|
|
270
|
+
}];
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
function stringifyWebpackSource(source) {
|
|
274
|
+
if (typeof source === "string") return source;
|
|
275
|
+
return source?.toString() ?? "";
|
|
276
|
+
}
|
|
198
277
|
function setupWebpackV5ProcessAssetsHook(options) {
|
|
199
|
-
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, consumeRuntimeRefreshRequirement, debug } = options;
|
|
278
|
+
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
|
|
200
279
|
const { Compilation, sources } = compiler.webpack;
|
|
201
280
|
const { ConcatSource } = sources;
|
|
281
|
+
const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
|
|
202
282
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
203
283
|
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
284
|
+
const bundleBuildState = require_bundle_state.createBundleBuildState();
|
|
285
|
+
const bundleRuntimeClassSetManager = runtimeClassSetManager ?? require_incremental_runtime_class_set.createBundleRuntimeClassSetManager();
|
|
286
|
+
let webpackWatchRuntimeScanInitialized = false;
|
|
204
287
|
compiler.hooks.compilation.tap(require_precheck.pluginName, (compilation) => {
|
|
205
288
|
compilation.hooks.processAssets.tapPromise({
|
|
206
289
|
name: require_precheck.pluginName,
|
|
@@ -209,19 +292,36 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
209
292
|
compilerOptions.onStart();
|
|
210
293
|
debug("start");
|
|
211
294
|
await runtimeState.readyPromise;
|
|
295
|
+
const hmrTimingStartedAt = performance.now();
|
|
212
296
|
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
213
297
|
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
298
|
+
const getCurrentAssetSource = (file) => {
|
|
299
|
+
const asset = compilation.getAsset(file);
|
|
300
|
+
if (!asset) return;
|
|
301
|
+
return stringifyWebpackSource(asset.source.source());
|
|
302
|
+
};
|
|
303
|
+
const updateAssetIfChanged = (file, source, { notifyUpdate = true } = {}) => {
|
|
304
|
+
const nextSource = stringifyWebpackSource(source.source());
|
|
305
|
+
const previousSource = getCurrentAssetSource(file);
|
|
306
|
+
if (previousSource === nextSource) {
|
|
307
|
+
debug("asset unchanged, skip update: %s", file);
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
compilation.updateAsset(file, source);
|
|
311
|
+
if (notifyUpdate) compilerOptions.onUpdate(file, previousSource ?? "", nextSource);
|
|
312
|
+
return true;
|
|
313
|
+
};
|
|
214
314
|
const entries = Object.entries(assets);
|
|
215
315
|
const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
|
|
216
316
|
const outputDir = compilerOutputPath ? node_path.default.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? node_process.default.cwd();
|
|
217
317
|
const jsAssets = /* @__PURE__ */ new Map();
|
|
218
318
|
for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
|
|
219
|
-
const absolute =
|
|
319
|
+
const absolute = require_bundle_state.toAbsoluteOutputPath(file, outputDir);
|
|
220
320
|
jsAssets.set(absolute, file);
|
|
221
321
|
}
|
|
222
322
|
const moduleGraphOptions = {
|
|
223
323
|
resolve(specifier, importer) {
|
|
224
|
-
return
|
|
324
|
+
return require_bundle_state.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
225
325
|
},
|
|
226
326
|
load: (id) => {
|
|
227
327
|
const assetName = jsAssets.get(id);
|
|
@@ -243,12 +343,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
243
343
|
const asset = compilation.getAsset(assetName);
|
|
244
344
|
if (!asset) continue;
|
|
245
345
|
const previousSource = asset.source.source();
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
const source = new ConcatSource(code);
|
|
249
|
-
compilation.updateAsset(assetName, source);
|
|
250
|
-
compilerOptions.onUpdate(assetName, previous, code);
|
|
251
|
-
debug("js linked handle: %s", assetName);
|
|
346
|
+
if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
|
|
347
|
+
if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
|
|
252
348
|
}
|
|
253
349
|
};
|
|
254
350
|
const groupedEntries = require_utils.getGroupedEntries(entries, compilerOptions);
|
|
@@ -261,7 +357,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
261
357
|
const created = {
|
|
262
358
|
isMainChunk,
|
|
263
359
|
postcssOptions: { options: { from: file } },
|
|
264
|
-
majorVersion
|
|
360
|
+
...majorVersion === void 0 ? {} : { majorVersion }
|
|
265
361
|
};
|
|
266
362
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
267
363
|
return created;
|
|
@@ -277,64 +373,92 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
277
373
|
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
278
374
|
return created;
|
|
279
375
|
};
|
|
376
|
+
const finalizeCssAssetSource = (source) => {
|
|
377
|
+
return require_incremental_runtime_class_set.removeTailwindSourceDirectives(require_bundle_state.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
378
|
+
};
|
|
280
379
|
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
281
380
|
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
381
|
+
let runtimeSet;
|
|
382
|
+
const watchMode = isWatchMode?.() === true;
|
|
383
|
+
if (watchMode && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
|
|
384
|
+
const snapshot = require_bundle_state.buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
|
|
385
|
+
if (!webpackWatchRuntimeScanInitialized) {
|
|
386
|
+
for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
392
|
+
await bundleRuntimeClassSetManager.reset();
|
|
393
|
+
runtimeSet = await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
394
|
+
forceRefresh: false,
|
|
395
|
+
forceCollect: true,
|
|
396
|
+
clearCache: false,
|
|
397
|
+
allowEmpty: false
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
require_bundle_state.updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
|
|
401
|
+
webpackWatchRuntimeScanInitialized = true;
|
|
402
|
+
} else {
|
|
403
|
+
if (forceRuntimeRefresh) {
|
|
404
|
+
await bundleRuntimeClassSetManager.reset();
|
|
405
|
+
webpackWatchRuntimeScanInitialized = false;
|
|
406
|
+
}
|
|
407
|
+
runtimeSet = await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
408
|
+
forceRefresh: forceRuntimeRefresh,
|
|
409
|
+
forceCollect: !watchMode || forceRuntimeRefresh,
|
|
410
|
+
clearCache: forceRuntimeRefresh,
|
|
411
|
+
allowEmpty: false
|
|
412
|
+
});
|
|
413
|
+
}
|
|
288
414
|
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
289
415
|
consumeRuntimeRefreshRequirement();
|
|
290
|
-
const runtimeSetHash = compilerOptions.cache.computeHash([
|
|
416
|
+
const runtimeSetHash = compilerOptions.cache.computeHash([require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
|
|
291
417
|
const defaultTemplateHandlerOptions = { runtimeSet };
|
|
292
418
|
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
293
419
|
const tasks = [];
|
|
294
|
-
if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
420
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
295
421
|
const [file, originalSource] = element;
|
|
296
422
|
const rawSource = originalSource.source().toString();
|
|
297
423
|
const cacheKey = file;
|
|
298
424
|
const chunkHash = assetHashByChunk.get(file);
|
|
299
|
-
tasks.push(
|
|
425
|
+
tasks.push(require_incremental_runtime_class_set.processCachedTask({
|
|
300
426
|
cache: compilerOptions.cache,
|
|
301
427
|
cacheKey,
|
|
302
428
|
hashKey: `${file}:asset`,
|
|
303
429
|
rawSource,
|
|
304
430
|
hash: chunkHash,
|
|
305
|
-
applyResult(source) {
|
|
306
|
-
|
|
431
|
+
applyResult(source, { cacheHit }) {
|
|
432
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
307
433
|
},
|
|
308
434
|
onCacheHit() {
|
|
309
435
|
debug("html cache hit: %s", file);
|
|
310
436
|
},
|
|
311
437
|
transform: async () => {
|
|
312
|
-
const
|
|
313
|
-
const source = new ConcatSource(wxml);
|
|
314
|
-
compilerOptions.onUpdate(file, rawSource, wxml);
|
|
438
|
+
const source = new ConcatSource(await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions));
|
|
315
439
|
debug("html handle: %s", file);
|
|
316
440
|
return { result: source };
|
|
317
441
|
}
|
|
318
442
|
}));
|
|
319
443
|
}
|
|
320
444
|
const jsTaskFactories = [];
|
|
321
|
-
if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
445
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
322
446
|
const cacheKey = getCacheKey(file);
|
|
323
447
|
const asset = compilation.getAsset(file);
|
|
324
448
|
if (!asset) continue;
|
|
325
|
-
const absoluteFile =
|
|
449
|
+
const absoluteFile = require_bundle_state.toAbsoluteOutputPath(file, outputDir);
|
|
326
450
|
const initialSource = asset.source.source();
|
|
327
451
|
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
328
452
|
const chunkHash = assetHashByChunk.get(file);
|
|
329
453
|
jsTaskFactories.push(async () => {
|
|
330
|
-
await
|
|
454
|
+
await require_incremental_runtime_class_set.processCachedTask({
|
|
331
455
|
cache: compilerOptions.cache,
|
|
332
456
|
cacheKey,
|
|
333
457
|
hashKey: `${file}:asset`,
|
|
334
458
|
rawSource: initialRawSource,
|
|
335
459
|
hash: chunkHash,
|
|
336
|
-
applyResult(source) {
|
|
337
|
-
|
|
460
|
+
applyResult(source, { cacheHit }) {
|
|
461
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
338
462
|
},
|
|
339
463
|
onCacheHit() {
|
|
340
464
|
debug("js cache hit: %s", file);
|
|
@@ -348,10 +472,12 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
348
472
|
moduleGraph: moduleGraphOptions,
|
|
349
473
|
babelParserOptions: { sourceFilename: absoluteFile }
|
|
350
474
|
};
|
|
351
|
-
if (require_precheck.shouldSkipJsTransform(currentSource,
|
|
475
|
+
if (require_precheck.shouldSkipJsTransform(currentSource, {
|
|
476
|
+
...handlerOptions,
|
|
477
|
+
classNameSet: runtimeSet
|
|
478
|
+
})) return { result: new ConcatSource(currentSource) };
|
|
352
479
|
const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
|
|
353
480
|
const source = new ConcatSource(code);
|
|
354
|
-
compilerOptions.onUpdate(file, currentSource, code);
|
|
355
481
|
debug("js handle: %s", file);
|
|
356
482
|
applyLinkedResults(linked);
|
|
357
483
|
return { result: source };
|
|
@@ -362,16 +488,37 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
362
488
|
if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
|
|
363
489
|
const [file, originalSource] = element;
|
|
364
490
|
const rawSource = originalSource.source().toString();
|
|
491
|
+
if (isWebpackProcessedCssAsset?.(file, rawSource)) {
|
|
492
|
+
const nextCss = finalizeCssAssetSource(rawSource);
|
|
493
|
+
tasks.push(require_incremental_runtime_class_set.processCachedTask({
|
|
494
|
+
cache: compilerOptions.cache,
|
|
495
|
+
cacheKey: file,
|
|
496
|
+
hashKey: `${file}:asset`,
|
|
497
|
+
rawSource,
|
|
498
|
+
hash: createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash),
|
|
499
|
+
applyResult(source, { cacheHit }) {
|
|
500
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
501
|
+
},
|
|
502
|
+
onCacheHit() {
|
|
503
|
+
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
504
|
+
},
|
|
505
|
+
transform: async () => {
|
|
506
|
+
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
507
|
+
return { result: new ConcatSource(nextCss) };
|
|
508
|
+
}
|
|
509
|
+
}));
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
365
512
|
const cacheKey = file;
|
|
366
513
|
const runtimeAwareHash = createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash);
|
|
367
|
-
tasks.push(
|
|
514
|
+
tasks.push(require_incremental_runtime_class_set.processCachedTask({
|
|
368
515
|
cache: compilerOptions.cache,
|
|
369
516
|
cacheKey,
|
|
370
517
|
hashKey: `${file}:asset`,
|
|
371
518
|
rawSource,
|
|
372
519
|
hash: runtimeAwareHash,
|
|
373
|
-
applyResult(source) {
|
|
374
|
-
|
|
520
|
+
applyResult(source, { cacheHit }) {
|
|
521
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
375
522
|
},
|
|
376
523
|
onCacheHit() {
|
|
377
524
|
debug("css cache hit: %s", file);
|
|
@@ -379,7 +526,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
379
526
|
transform: async () => {
|
|
380
527
|
await runtimeState.readyPromise;
|
|
381
528
|
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
382
|
-
const generated = await
|
|
529
|
+
const generated = await require_incremental_runtime_class_set.generateCssByGenerator({
|
|
383
530
|
opts: compilerOptions,
|
|
384
531
|
runtimeState,
|
|
385
532
|
runtime: runtimeSet,
|
|
@@ -390,23 +537,29 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
390
537
|
styleHandler: compilerOptions.styleHandler,
|
|
391
538
|
debug
|
|
392
539
|
});
|
|
393
|
-
const
|
|
394
|
-
const source = new ConcatSource(css);
|
|
395
|
-
compilerOptions.onUpdate(file, rawSource, css);
|
|
540
|
+
const source = new ConcatSource(finalizeCssAssetSource(generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
396
541
|
if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
|
|
397
542
|
else debug("css handle: %s", file);
|
|
398
543
|
return { result: source };
|
|
399
544
|
}
|
|
400
545
|
}));
|
|
401
546
|
}
|
|
402
|
-
|
|
547
|
+
require_bundle_state.pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
403
548
|
await Promise.all(tasks);
|
|
404
549
|
debug("end");
|
|
550
|
+
require_incremental_runtime_class_set.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt);
|
|
405
551
|
compilerOptions.onEnd();
|
|
406
552
|
});
|
|
407
553
|
});
|
|
408
554
|
}
|
|
409
555
|
//#endregion
|
|
556
|
+
//#region src/bundlers/webpack/loaders/runtime-registry.ts
|
|
557
|
+
const runtimeRegistryHolder = globalThis;
|
|
558
|
+
const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
|
|
559
|
+
function setWebpackLoaderRuntime(key, entry) {
|
|
560
|
+
runtimeRegistry.set(key, entry);
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
410
563
|
//#region src/bundlers/webpack/shared/loader-anchors.ts
|
|
411
564
|
const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
412
565
|
const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
|
|
@@ -437,7 +590,7 @@ function createLoaderAnchorFinders(appType) {
|
|
|
437
590
|
//#endregion
|
|
438
591
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
439
592
|
function setupWebpackV5Loaders(options) {
|
|
440
|
-
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, getClassSetInLoader, getRuntimeWatchDependencies, debug } = options;
|
|
593
|
+
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
441
594
|
const isMpxApp = isMpx(appType);
|
|
442
595
|
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
443
596
|
const runtimeClassSetLoader = runtimeLoaderPath ?? node_path.default.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
@@ -446,24 +599,31 @@ function setupWebpackV5Loaders(options) {
|
|
|
446
599
|
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? node_fs.default.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
447
600
|
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
448
601
|
pkgDir: weappTailwindcssPackageDir,
|
|
449
|
-
|
|
450
|
-
|
|
602
|
+
compilerOptions,
|
|
603
|
+
runtimeState,
|
|
604
|
+
...appType === void 0 ? {} : { appType },
|
|
605
|
+
...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
|
|
606
|
+
getRuntimeSet: getRuntimeSetInLoader,
|
|
607
|
+
...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource }
|
|
451
608
|
} : void 0;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
609
|
+
setWebpackLoaderRuntime(runtimeRegistryKey, {
|
|
610
|
+
classSet: {
|
|
611
|
+
getClassSet: getClassSetInLoader,
|
|
612
|
+
getWatchDependencies: getRuntimeWatchDependencies
|
|
613
|
+
},
|
|
614
|
+
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
615
|
+
});
|
|
456
616
|
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
457
|
-
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
617
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
458
618
|
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
459
619
|
const createRuntimeClassSetLoaderEntry = () => ({
|
|
460
620
|
loader: runtimeClassSetLoader,
|
|
461
|
-
options:
|
|
621
|
+
options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
|
|
462
622
|
ident: null,
|
|
463
623
|
type: null
|
|
464
624
|
});
|
|
465
625
|
const createCssImportRewriteLoaderEntry = () => {
|
|
466
|
-
if (!runtimeCssImportRewriteLoader) return null;
|
|
626
|
+
if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
|
|
467
627
|
return {
|
|
468
628
|
loader: runtimeCssImportRewriteLoader,
|
|
469
629
|
options: cssImportRewriteLoaderOptions,
|
|
@@ -480,15 +640,15 @@ function setupWebpackV5Loaders(options) {
|
|
|
480
640
|
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
481
641
|
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
482
642
|
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
483
|
-
if (node_process.default.env
|
|
643
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
484
644
|
rewriteAnchorIdx,
|
|
485
645
|
classSetAnchorIdx
|
|
486
646
|
});
|
|
487
|
-
if (node_process.default.env
|
|
647
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.includes("app.css")) debug("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), {
|
|
488
648
|
rewriteAnchorIdx,
|
|
489
649
|
classSetAnchorIdx
|
|
490
650
|
});
|
|
491
|
-
else if (node_process.default.env
|
|
651
|
+
else if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.endsWith(".css")) debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
492
652
|
rewriteAnchorIdx,
|
|
493
653
|
classSetAnchorIdx
|
|
494
654
|
});
|
|
@@ -521,14 +681,66 @@ function setupWebpackV5Loaders(options) {
|
|
|
521
681
|
}
|
|
522
682
|
//#endregion
|
|
523
683
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
524
|
-
|
|
525
|
-
const
|
|
684
|
+
require_precheck.init_defineProperty();
|
|
685
|
+
const debug = require_v3_engine.createDebug();
|
|
686
|
+
const weappTailwindcssPackageDir = require_bundle_state.resolvePackageDir("weapp-tailwindcss");
|
|
687
|
+
const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
|
|
688
|
+
function normalizeIgnoredList(ignored) {
|
|
689
|
+
if (Array.isArray(ignored)) return ignored.filter((item) => typeof item === "string" || item instanceof RegExp || typeof item === "function");
|
|
690
|
+
if (typeof ignored === "string" || ignored instanceof RegExp || typeof ignored === "function") return [ignored];
|
|
691
|
+
return [];
|
|
692
|
+
}
|
|
693
|
+
function createOutputIgnoredPredicate(ignoredList, ignoredPath) {
|
|
694
|
+
const predicate = (file) => {
|
|
695
|
+
const resolvedFile = node_path.default.resolve(file);
|
|
696
|
+
if (resolvedFile === ignoredPath || resolvedFile.startsWith(`${ignoredPath}${node_path.default.sep}`)) return true;
|
|
697
|
+
const normalizedFile = file.replace(/\\/g, "/");
|
|
698
|
+
return ignoredList.some((item) => {
|
|
699
|
+
if (typeof item === "string") {
|
|
700
|
+
const resolvedItem = node_path.default.resolve(item);
|
|
701
|
+
if (resolvedFile === resolvedItem || resolvedFile.startsWith(`${resolvedItem}${node_path.default.sep}`)) return true;
|
|
702
|
+
return micromatch.default.isMatch(normalizedFile, item);
|
|
703
|
+
}
|
|
704
|
+
if (item instanceof RegExp) return item.test(normalizedFile);
|
|
705
|
+
return item(file);
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
predicate[outputIgnoredPredicatePath] = ignoredPath;
|
|
709
|
+
return predicate;
|
|
710
|
+
}
|
|
711
|
+
function appendIgnoredPath(ignored, ignoredPath) {
|
|
712
|
+
if (typeof ignored === "function" && ignored[outputIgnoredPredicatePath] === ignoredPath) return ignored;
|
|
713
|
+
const ignoredList = normalizeIgnoredList(ignored);
|
|
714
|
+
if (ignoredList.some((item) => typeof item !== "string")) return createOutputIgnoredPredicate(ignoredList, ignoredPath);
|
|
715
|
+
if (ignoredList.some((item) => typeof item === "string" && node_path.default.resolve(item) === ignoredPath)) return ignored;
|
|
716
|
+
return [...ignoredList, ignoredPath];
|
|
717
|
+
}
|
|
718
|
+
function setupWebpackWatchOutputIgnore(compiler) {
|
|
719
|
+
const appendOutputIgnoredPath = (watchOptions) => {
|
|
720
|
+
const outputPath = compiler.outputPath || compiler.options?.output?.path;
|
|
721
|
+
const outputDir = outputPath ? node_path.default.resolve(outputPath) : void 0;
|
|
722
|
+
if (!outputDir) return watchOptions;
|
|
723
|
+
if (watchOptions && typeof watchOptions === "object") {
|
|
724
|
+
watchOptions.ignored = appendIgnoredPath(watchOptions.ignored, outputDir);
|
|
725
|
+
return watchOptions;
|
|
726
|
+
}
|
|
727
|
+
return { ignored: appendIgnoredPath(void 0, outputDir) };
|
|
728
|
+
};
|
|
729
|
+
compiler.options.watchOptions = appendOutputIgnoredPath(compiler.options.watchOptions);
|
|
730
|
+
const syncOutputIgnoredPath = () => {
|
|
731
|
+
const outputPath = compiler.outputPath || compiler.options?.output?.path;
|
|
732
|
+
if (!(outputPath ? node_path.default.resolve(outputPath) : void 0)) return;
|
|
733
|
+
const watchOptions = compiler.watching?.watchOptions;
|
|
734
|
+
if (watchOptions) appendOutputIgnoredPath(watchOptions);
|
|
735
|
+
};
|
|
736
|
+
compiler.hooks.watchRun?.tap(require_precheck.pluginName, syncOutputIgnoredPath);
|
|
737
|
+
}
|
|
526
738
|
/**
|
|
527
|
-
* @name
|
|
739
|
+
* @name WeappTailwindcss
|
|
528
740
|
* @description webpack5 核心转义插件
|
|
529
741
|
* @link https://tw.icebreaker.top/docs/intro
|
|
530
742
|
*/
|
|
531
|
-
var
|
|
743
|
+
var WeappTailwindcss = class {
|
|
532
744
|
constructor(options = {}) {
|
|
533
745
|
require_precheck._defineProperty(this, "options", void 0);
|
|
534
746
|
require_precheck._defineProperty(this, "appType", void 0);
|
|
@@ -543,11 +755,14 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
543
755
|
apply(compiler) {
|
|
544
756
|
compiler.options = compiler.options || {};
|
|
545
757
|
const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
|
|
546
|
-
const disabledOptions =
|
|
547
|
-
const
|
|
758
|
+
const disabledOptions = require_bundle_state.resolvePluginDisabledState(disabled);
|
|
759
|
+
const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
|
|
760
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(this.options.generator);
|
|
761
|
+
const shouldRewriteCssImports = isTailwindcssV4 || generatorOptions.target === "web";
|
|
548
762
|
const isMpxApp = isMpx(this.appType);
|
|
549
763
|
if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
|
|
550
764
|
if (disabledOptions.plugin) return;
|
|
765
|
+
setupWebpackWatchOutputIgnore(compiler);
|
|
551
766
|
const runtimeState = {
|
|
552
767
|
twPatcher: initialTwPatcher,
|
|
553
768
|
readyPromise: require_precheck.createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
@@ -556,13 +771,15 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
556
771
|
let runtimeSetPrepared = false;
|
|
557
772
|
let runtimeSetSignature;
|
|
558
773
|
let runtimeRefreshRequiredForCompilation = false;
|
|
774
|
+
let watchRunObserved = false;
|
|
559
775
|
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
560
776
|
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
777
|
+
const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
561
778
|
let runtimeMetadataPrepared = false;
|
|
562
779
|
const updateRuntimeWatchDependencies = async () => {
|
|
563
780
|
runtimeWatchDependencyFiles.clear();
|
|
564
781
|
runtimeWatchDependencyContexts.clear();
|
|
565
|
-
const tailwindOptions =
|
|
782
|
+
const tailwindOptions = require_v3_engine.resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
566
783
|
if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
|
|
567
784
|
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
|
|
568
785
|
for (const source of tailwindOptions?.v4?.cssSources ?? []) {
|
|
@@ -584,12 +801,24 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
584
801
|
await updateRuntimeWatchDependencies();
|
|
585
802
|
runtimeMetadataPrepared = true;
|
|
586
803
|
};
|
|
587
|
-
const
|
|
588
|
-
|
|
804
|
+
const collectWatchChangedFiles = () => {
|
|
805
|
+
const compilerLike = compiler;
|
|
806
|
+
return new Set([...compilerLike.modifiedFiles ?? [], ...compilerLike.removedFiles ?? []]);
|
|
807
|
+
};
|
|
808
|
+
const hasRuntimeDependencyChanges = (files) => {
|
|
809
|
+
for (const file of files) if (isWatchFileInRuntimeDependencies(file, {
|
|
810
|
+
contexts: runtimeWatchDependencyContexts,
|
|
811
|
+
files: runtimeWatchDependencyFiles
|
|
812
|
+
})) return true;
|
|
813
|
+
return false;
|
|
814
|
+
};
|
|
815
|
+
const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
|
|
816
|
+
if (markWatchRun) watchRunObserved = true;
|
|
817
|
+
const changedFiles = collectWatchChangedFiles();
|
|
818
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges(changedFiles);
|
|
589
819
|
};
|
|
590
820
|
const resetRuntimePreparation = () => {
|
|
591
821
|
runtimeSetPrepared = false;
|
|
592
|
-
runtimeMetadataPrepared = false;
|
|
593
822
|
syncRuntimeRefreshRequirement();
|
|
594
823
|
};
|
|
595
824
|
const registerAutoCssSource = async (source) => {
|
|
@@ -604,21 +833,25 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
604
833
|
});
|
|
605
834
|
debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
|
|
606
835
|
};
|
|
607
|
-
|
|
608
|
-
|
|
836
|
+
const markWebpackProcessedCssSource = (file) => {
|
|
837
|
+
webpackProcessedCssSourceFiles.add(node_path.default.resolve(file));
|
|
838
|
+
};
|
|
839
|
+
compiler.hooks.invalid?.tap?.(require_precheck.pluginName, (fileName) => {
|
|
840
|
+
if (!fileName) return;
|
|
841
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([node_path.default.resolve(fileName)]);
|
|
609
842
|
});
|
|
610
|
-
compiler.hooks.watchRun?.tap?.(require_precheck.pluginName, syncRuntimeRefreshRequirement);
|
|
843
|
+
compiler.hooks.watchRun?.tap?.(require_precheck.pluginName, () => syncRuntimeRefreshRequirement(true));
|
|
611
844
|
if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(require_precheck.pluginName, resetRuntimePreparation);
|
|
612
845
|
else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(require_precheck.pluginName, resetRuntimePreparation);
|
|
613
846
|
async function getClassSetInLoader() {
|
|
614
847
|
if (runtimeSetPrepared) return;
|
|
615
|
-
const signature =
|
|
848
|
+
const signature = require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
616
849
|
const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
|
|
617
850
|
debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
|
|
618
851
|
runtimeSetPrepared = true;
|
|
619
852
|
await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
620
853
|
forceRefresh,
|
|
621
|
-
forceCollect:
|
|
854
|
+
forceCollect: forceRefresh || !watchRunObserved,
|
|
622
855
|
clearCache: forceRefresh,
|
|
623
856
|
allowEmpty: true
|
|
624
857
|
});
|
|
@@ -626,6 +859,10 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
626
859
|
runtimeSetSignature = signature;
|
|
627
860
|
runtimeRefreshRequiredForCompilation = false;
|
|
628
861
|
}
|
|
862
|
+
async function getRuntimeSetInLoader() {
|
|
863
|
+
await getClassSetInLoader();
|
|
864
|
+
return require_precheck.ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
|
|
865
|
+
}
|
|
629
866
|
onLoad();
|
|
630
867
|
setupWebpackV5Loaders({
|
|
631
868
|
compiler,
|
|
@@ -635,7 +872,10 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
635
872
|
shouldRewriteCssImports,
|
|
636
873
|
runtimeLoaderPath,
|
|
637
874
|
registerAutoCssSource,
|
|
875
|
+
runtimeState,
|
|
638
876
|
getClassSetInLoader,
|
|
877
|
+
getRuntimeSetInLoader,
|
|
878
|
+
markWebpackProcessedCssSource,
|
|
639
879
|
getRuntimeWatchDependencies() {
|
|
640
880
|
return {
|
|
641
881
|
files: runtimeWatchDependencyFiles,
|
|
@@ -651,18 +891,23 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
651
891
|
runtimeState,
|
|
652
892
|
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
653
893
|
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
894
|
+
isWebpackProcessedCssAsset(file, rawSource) {
|
|
895
|
+
return webpackProcessedCssSourceFiles.has(node_path.default.resolve(file)) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
|
|
896
|
+
},
|
|
654
897
|
consumeRuntimeRefreshRequirement() {
|
|
655
898
|
runtimeRefreshRequiredForCompilation = false;
|
|
656
899
|
},
|
|
900
|
+
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
901
|
+
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
657
902
|
debug
|
|
658
903
|
});
|
|
659
904
|
}
|
|
660
905
|
};
|
|
661
906
|
//#endregion
|
|
662
|
-
Object.defineProperty(exports, "
|
|
907
|
+
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
663
908
|
enumerable: true,
|
|
664
909
|
get: function() {
|
|
665
|
-
return
|
|
910
|
+
return WeappTailwindcss;
|
|
666
911
|
}
|
|
667
912
|
});
|
|
668
913
|
Object.defineProperty(exports, "weappTailwindcssPackageDir", {
|