weapp-tailwindcss 5.0.0-next.9 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/auto-DEHRmEAx.mjs +200 -0
- package/dist/auto-dPpsm6FB.js +238 -0
- package/dist/bundle-state-CBF5YX1m.js +529 -0
- package/dist/bundle-state-CQmxxx0R.mjs +413 -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 +11 -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-CvmsIQFI.js +92 -0
- package/dist/generator-DDtsUvkH.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-BffodqHh.js +2366 -0
- package/dist/incremental-runtime-class-set-DArodvWs.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-w48mGIhe.mjs → postcss-BzNYQUOH.mjs} +54 -114
- package/dist/postcss-C7BMYpEF.mjs +169 -0
- package/dist/postcss-CiYLsqZn.js +192 -0
- package/dist/{postcss-QIXwT40c.js → postcss-DE0TOtV9.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-BzYPm-EG.js +4842 -0
- package/dist/precheck-jZvTVXXG.mjs +4716 -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-BuTlMabx.mjs +322 -0
- package/dist/source-candidates-CxoIaS88.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-CCZcu0lr.mjs} +75 -98
- package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-DZckITp1.js} +83 -106
- 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-DGBhUnjn.mjs +3419 -0
- package/dist/v3-engine-M6Aqru5T.js +3714 -0
- package/dist/vite-BBcQIJpD.mjs +24493 -0
- package/dist/vite-DgRkWVPG.js +24507 -0
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5456 -22
- package/dist/weapp-tw-runtime-classset-loader.js +32 -9
- package/dist/{webpack-BzN2ly34.js → webpack-D-gb4ZvO.js} +341 -96
- package/dist/{webpack-DJazm5sT.mjs → webpack-D43aMQzO.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-Bwp3nbrl.js +0 -1381
- package/dist/generator-css-DeLLmp2N.mjs +0 -1342
- 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-By5KQi9s.js +0 -2419
- package/dist/vite-Cyp42bBf.mjs +0 -2406
- /package/dist/{logger-Bub1jggA.mjs → logger-BNzxZbZj.mjs} +0 -0
- /package/dist/{logger-BRy6XPQ2.js → logger-TlKT3xmR.js} +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { r as getGroupedEntries } from "./utils-
|
|
6
|
-
import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-
|
|
7
|
-
import {
|
|
1
|
+
import { b as ensureRuntimeClassSet, d as _defineProperty, f as init_defineProperty, i as pluginName, n as getCompilerContext, t as shouldSkipJsTransform, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-jZvTVXXG.mjs";
|
|
2
|
+
import { B as createDebug, W as resolveTailwindcssOptions, l as getRuntimeClassSetSignature } from "./v3-engine-DGBhUnjn.mjs";
|
|
3
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-DDtsUvkH.mjs";
|
|
4
|
+
import { d as removeTailwindSourceDirectives, i as generateCssByGenerator, r as emitHmrTiming, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-DArodvWs.mjs";
|
|
5
|
+
import { r as getGroupedEntries } from "./utils-DsaS975I.mjs";
|
|
6
|
+
import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-CCZcu0lr.mjs";
|
|
7
|
+
import { _ as stripRequestQuery, b as toAbsoluteOutputPath, d as resolvePluginDisabledState, g as isSourceStyleRequest, l as stripBundlerGeneratedCssMarkers, n as createBundleBuildState, o as pushConcurrentTaskFactories, r as updateBundleBuildState, t as buildBundleSnapshot, u as resolvePackageDir, y as resolveOutputSpecifier } from "./bundle-state-CQmxxx0R.mjs";
|
|
8
8
|
import Module, { createRequire } from "node:module";
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import process from "node:process";
|
|
11
9
|
import fs from "node:fs";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import path from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
|
+
import micromatch from "micromatch";
|
|
13
14
|
//#region src/shared/tailwindcss-css-redirect.ts
|
|
14
15
|
const moduleWithMutableResolve = Module;
|
|
15
16
|
const patched = /* @__PURE__ */ new WeakSet();
|
|
@@ -30,6 +31,7 @@ function installTailwindcssCssRedirect(pkgDir) {
|
|
|
30
31
|
//#region src/shared/mpx.ts
|
|
31
32
|
const localRequire = createRequire(import.meta.url);
|
|
32
33
|
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
34
|
+
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
33
35
|
function isMpxStyleResourceQuery(query) {
|
|
34
36
|
if (typeof query !== "string") return false;
|
|
35
37
|
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
@@ -50,19 +52,44 @@ function resolveMpxWebpackPluginDir(compiler) {
|
|
|
50
52
|
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
51
53
|
return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
52
54
|
} catch {}
|
|
53
|
-
|
|
55
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
56
|
+
if (cachedPackageJson) return path.dirname(cachedPackageJson);
|
|
57
|
+
try {
|
|
58
|
+
return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
59
|
+
} catch {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
54
62
|
}
|
|
55
63
|
function isMpxWebpackPluginRequest(request) {
|
|
56
64
|
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
57
65
|
}
|
|
66
|
+
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
67
|
+
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
68
|
+
return path.join(mpxWebpackPluginDir, request.slice(22));
|
|
69
|
+
}
|
|
58
70
|
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
71
|
+
const recordLoader = path.join(pkgDir, "lib/record-loader");
|
|
72
|
+
const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
|
|
73
|
+
const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
59
74
|
if (Array.isArray(alias)) alias.push({
|
|
75
|
+
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
76
|
+
alias: recordLoader
|
|
77
|
+
}, {
|
|
78
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
79
|
+
alias: styleCompiler
|
|
80
|
+
}, {
|
|
81
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
82
|
+
alias: stripConditionalLoader
|
|
83
|
+
}, {
|
|
60
84
|
name: /^@mpxjs\/webpack-plugin\//,
|
|
61
85
|
alias: pkgDir
|
|
62
86
|
});
|
|
63
87
|
else {
|
|
64
88
|
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
65
89
|
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
90
|
+
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
91
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
92
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
66
93
|
}
|
|
67
94
|
}
|
|
68
95
|
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
@@ -71,18 +98,48 @@ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
|
71
98
|
compiler.options.resolveLoader.alias = alias;
|
|
72
99
|
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
73
100
|
}
|
|
101
|
+
function resolveMpxWebpackPluginRequire(compiler) {
|
|
102
|
+
const candidates = [
|
|
103
|
+
compiler?.context,
|
|
104
|
+
compiler?.options?.context,
|
|
105
|
+
process.cwd()
|
|
106
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
107
|
+
for (const candidate of candidates) try {
|
|
108
|
+
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
109
|
+
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
110
|
+
return projectRequire;
|
|
111
|
+
} catch {}
|
|
112
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
113
|
+
if (cachedPackageJson) return createRequire(cachedPackageJson);
|
|
114
|
+
return localRequire;
|
|
115
|
+
}
|
|
116
|
+
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
117
|
+
if (!mpxWebpackPluginDir) return false;
|
|
118
|
+
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
119
|
+
let normalize;
|
|
120
|
+
try {
|
|
121
|
+
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
122
|
+
} catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (typeof normalize.lib !== "function") return false;
|
|
126
|
+
if (normalize.lib.__weappTwPatched) return true;
|
|
127
|
+
const wrappedLib = (file) => path.join(mpxWebpackPluginDir, "lib", file);
|
|
128
|
+
wrappedLib.__weappTwPatched = true;
|
|
129
|
+
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
130
|
+
normalize.lib = wrappedLib;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
74
133
|
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
75
134
|
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
76
135
|
compiler.options = compiler.options || {};
|
|
77
136
|
compiler.options.resolve = compiler.options.resolve || {};
|
|
78
137
|
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
79
|
-
|
|
138
|
+
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
139
|
+
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
80
140
|
const alias = compiler.options.resolve.alias ?? {};
|
|
81
141
|
compiler.options.resolve.alias = alias;
|
|
82
142
|
if (Array.isArray(alias)) alias.push({
|
|
83
|
-
name: /^@mpxjs\/webpack-plugin\//,
|
|
84
|
-
alias: mpxWebpackPluginDir
|
|
85
|
-
}, {
|
|
86
143
|
name: "tailwindcss",
|
|
87
144
|
alias: tailwindcssCssEntry
|
|
88
145
|
}, {
|
|
@@ -90,11 +147,10 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
|
90
147
|
alias: tailwindcssCssEntry
|
|
91
148
|
});
|
|
92
149
|
else {
|
|
93
|
-
alias["@mpxjs/webpack-plugin"] = mpxWebpackPluginDir;
|
|
94
|
-
alias["@mpxjs/webpack-plugin$"] = mpxWebpackPluginDir;
|
|
95
150
|
alias.tailwindcss = tailwindcssCssEntry;
|
|
96
151
|
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
97
152
|
}
|
|
153
|
+
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
98
154
|
return tailwindcssCssEntry;
|
|
99
155
|
}
|
|
100
156
|
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
@@ -102,10 +158,11 @@ function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
|
102
158
|
const originalResolve = loaderContext.resolve;
|
|
103
159
|
if (originalResolve.__weappTwPatched) return;
|
|
104
160
|
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
161
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
105
162
|
const wrappedResolve = function(context, request, callback) {
|
|
106
163
|
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
107
164
|
if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
|
|
108
|
-
if (isMpxWebpackPluginRequest(request)) return
|
|
165
|
+
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
109
166
|
return originalResolve.call(this, context, request, callback);
|
|
110
167
|
};
|
|
111
168
|
wrappedResolve.__weappTwPatched = true;
|
|
@@ -141,16 +198,13 @@ function getCacheKey(filename) {
|
|
|
141
198
|
}
|
|
142
199
|
function stripResourceQuery(resource) {
|
|
143
200
|
if (typeof resource !== "string") return resource;
|
|
144
|
-
|
|
145
|
-
if (queryIndex !== -1) return resource.slice(0, queryIndex);
|
|
146
|
-
const hashIndex = resource.indexOf("#");
|
|
147
|
-
if (hashIndex !== -1) return resource.slice(0, hashIndex);
|
|
148
|
-
return resource;
|
|
201
|
+
return stripRequestQuery(resource);
|
|
149
202
|
}
|
|
150
203
|
function isCssLikeModuleResource(resource, cssMatcher, appType) {
|
|
151
204
|
if (typeof resource !== "string") return false;
|
|
152
205
|
const normalizedResource = stripResourceQuery(resource);
|
|
153
206
|
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
207
|
+
if (isSourceStyleRequest(resource)) return true;
|
|
154
208
|
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
155
209
|
return false;
|
|
156
210
|
}
|
|
@@ -158,6 +212,13 @@ function hasLoaderEntry(entries, target) {
|
|
|
158
212
|
if (!target) return false;
|
|
159
213
|
return entries.some((entry) => entry.loader?.includes?.(target));
|
|
160
214
|
}
|
|
215
|
+
function normalizeWatchPath(file) {
|
|
216
|
+
return path.resolve(file);
|
|
217
|
+
}
|
|
218
|
+
function isFileInContext(file, context) {
|
|
219
|
+
const relative = path.relative(normalizeWatchPath(context), normalizeWatchPath(file));
|
|
220
|
+
return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
221
|
+
}
|
|
161
222
|
function toChunkFiles(files) {
|
|
162
223
|
if (!files) return [];
|
|
163
224
|
if (Array.isArray(files)) return files;
|
|
@@ -186,17 +247,38 @@ function createAssetHashByChunkMap(chunks) {
|
|
|
186
247
|
function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
|
|
187
248
|
return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
|
|
188
249
|
}
|
|
189
|
-
function
|
|
190
|
-
|
|
250
|
+
function isWatchFileInRuntimeDependencies(file, dependencies) {
|
|
251
|
+
const normalizedFile = normalizeWatchPath(file);
|
|
252
|
+
for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
|
|
253
|
+
for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
|
|
254
|
+
return false;
|
|
191
255
|
}
|
|
192
256
|
//#endregion
|
|
193
257
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
|
|
258
|
+
function createWebpackSnapshotAssets(assets) {
|
|
259
|
+
return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
|
|
260
|
+
const source = asset.source();
|
|
261
|
+
return [file, {
|
|
262
|
+
fileName: file,
|
|
263
|
+
source: typeof source === "string" ? source : source?.toString() ?? "",
|
|
264
|
+
type: "asset"
|
|
265
|
+
}];
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
function stringifyWebpackSource(source) {
|
|
269
|
+
if (typeof source === "string") return source;
|
|
270
|
+
return source?.toString() ?? "";
|
|
271
|
+
}
|
|
194
272
|
function setupWebpackV5ProcessAssetsHook(options) {
|
|
195
|
-
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, consumeRuntimeRefreshRequirement, debug } = options;
|
|
273
|
+
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
|
|
196
274
|
const { Compilation, sources } = compiler.webpack;
|
|
197
275
|
const { ConcatSource } = sources;
|
|
276
|
+
const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
|
|
198
277
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
199
278
|
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
279
|
+
const bundleBuildState = createBundleBuildState();
|
|
280
|
+
const bundleRuntimeClassSetManager = runtimeClassSetManager ?? createBundleRuntimeClassSetManager();
|
|
281
|
+
let webpackWatchRuntimeScanInitialized = false;
|
|
200
282
|
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
201
283
|
compilation.hooks.processAssets.tapPromise({
|
|
202
284
|
name: pluginName,
|
|
@@ -205,8 +287,25 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
205
287
|
compilerOptions.onStart();
|
|
206
288
|
debug("start");
|
|
207
289
|
await runtimeState.readyPromise;
|
|
290
|
+
const hmrTimingStartedAt = performance.now();
|
|
208
291
|
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
209
292
|
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
293
|
+
const getCurrentAssetSource = (file) => {
|
|
294
|
+
const asset = compilation.getAsset(file);
|
|
295
|
+
if (!asset) return;
|
|
296
|
+
return stringifyWebpackSource(asset.source.source());
|
|
297
|
+
};
|
|
298
|
+
const updateAssetIfChanged = (file, source, { notifyUpdate = true } = {}) => {
|
|
299
|
+
const nextSource = stringifyWebpackSource(source.source());
|
|
300
|
+
const previousSource = getCurrentAssetSource(file);
|
|
301
|
+
if (previousSource === nextSource) {
|
|
302
|
+
debug("asset unchanged, skip update: %s", file);
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
compilation.updateAsset(file, source);
|
|
306
|
+
if (notifyUpdate) compilerOptions.onUpdate(file, previousSource ?? "", nextSource);
|
|
307
|
+
return true;
|
|
308
|
+
};
|
|
210
309
|
const entries = Object.entries(assets);
|
|
211
310
|
const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
|
|
212
311
|
const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
|
|
@@ -239,12 +338,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
239
338
|
const asset = compilation.getAsset(assetName);
|
|
240
339
|
if (!asset) continue;
|
|
241
340
|
const previousSource = asset.source.source();
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
const source = new ConcatSource(code);
|
|
245
|
-
compilation.updateAsset(assetName, source);
|
|
246
|
-
compilerOptions.onUpdate(assetName, previous, code);
|
|
247
|
-
debug("js linked handle: %s", assetName);
|
|
341
|
+
if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
|
|
342
|
+
if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
|
|
248
343
|
}
|
|
249
344
|
};
|
|
250
345
|
const groupedEntries = getGroupedEntries(entries, compilerOptions);
|
|
@@ -257,7 +352,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
257
352
|
const created = {
|
|
258
353
|
isMainChunk,
|
|
259
354
|
postcssOptions: { options: { from: file } },
|
|
260
|
-
majorVersion
|
|
355
|
+
...majorVersion === void 0 ? {} : { majorVersion }
|
|
261
356
|
};
|
|
262
357
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
263
358
|
return created;
|
|
@@ -273,21 +368,51 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
273
368
|
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
274
369
|
return created;
|
|
275
370
|
};
|
|
371
|
+
const finalizeCssAssetSource = (source) => {
|
|
372
|
+
return removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
373
|
+
};
|
|
276
374
|
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
277
375
|
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
376
|
+
let runtimeSet;
|
|
377
|
+
const watchMode = isWatchMode?.() === true;
|
|
378
|
+
if (watchMode && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
|
|
379
|
+
const snapshot = buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
|
|
380
|
+
if (!webpackWatchRuntimeScanInitialized) {
|
|
381
|
+
for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
385
|
+
} catch (error) {
|
|
386
|
+
debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
387
|
+
await bundleRuntimeClassSetManager.reset();
|
|
388
|
+
runtimeSet = await ensureRuntimeClassSet(runtimeState, {
|
|
389
|
+
forceRefresh: false,
|
|
390
|
+
forceCollect: true,
|
|
391
|
+
clearCache: false,
|
|
392
|
+
allowEmpty: false
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
|
|
396
|
+
webpackWatchRuntimeScanInitialized = true;
|
|
397
|
+
} else {
|
|
398
|
+
if (forceRuntimeRefresh) {
|
|
399
|
+
await bundleRuntimeClassSetManager.reset();
|
|
400
|
+
webpackWatchRuntimeScanInitialized = false;
|
|
401
|
+
}
|
|
402
|
+
runtimeSet = await ensureRuntimeClassSet(runtimeState, {
|
|
403
|
+
forceRefresh: forceRuntimeRefresh,
|
|
404
|
+
forceCollect: !watchMode || forceRuntimeRefresh,
|
|
405
|
+
clearCache: forceRuntimeRefresh,
|
|
406
|
+
allowEmpty: false
|
|
407
|
+
});
|
|
408
|
+
}
|
|
284
409
|
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
285
410
|
consumeRuntimeRefreshRequirement();
|
|
286
411
|
const runtimeSetHash = compilerOptions.cache.computeHash([getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
|
|
287
412
|
const defaultTemplateHandlerOptions = { runtimeSet };
|
|
288
413
|
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
289
414
|
const tasks = [];
|
|
290
|
-
if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
415
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
291
416
|
const [file, originalSource] = element;
|
|
292
417
|
const rawSource = originalSource.source().toString();
|
|
293
418
|
const cacheKey = file;
|
|
@@ -298,23 +423,21 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
298
423
|
hashKey: `${file}:asset`,
|
|
299
424
|
rawSource,
|
|
300
425
|
hash: chunkHash,
|
|
301
|
-
applyResult(source) {
|
|
302
|
-
|
|
426
|
+
applyResult(source, { cacheHit }) {
|
|
427
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
303
428
|
},
|
|
304
429
|
onCacheHit() {
|
|
305
430
|
debug("html cache hit: %s", file);
|
|
306
431
|
},
|
|
307
432
|
transform: async () => {
|
|
308
|
-
const
|
|
309
|
-
const source = new ConcatSource(wxml);
|
|
310
|
-
compilerOptions.onUpdate(file, rawSource, wxml);
|
|
433
|
+
const source = new ConcatSource(await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions));
|
|
311
434
|
debug("html handle: %s", file);
|
|
312
435
|
return { result: source };
|
|
313
436
|
}
|
|
314
437
|
}));
|
|
315
438
|
}
|
|
316
439
|
const jsTaskFactories = [];
|
|
317
|
-
if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
440
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
318
441
|
const cacheKey = getCacheKey(file);
|
|
319
442
|
const asset = compilation.getAsset(file);
|
|
320
443
|
if (!asset) continue;
|
|
@@ -329,8 +452,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
329
452
|
hashKey: `${file}:asset`,
|
|
330
453
|
rawSource: initialRawSource,
|
|
331
454
|
hash: chunkHash,
|
|
332
|
-
applyResult(source) {
|
|
333
|
-
|
|
455
|
+
applyResult(source, { cacheHit }) {
|
|
456
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
334
457
|
},
|
|
335
458
|
onCacheHit() {
|
|
336
459
|
debug("js cache hit: %s", file);
|
|
@@ -344,10 +467,12 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
344
467
|
moduleGraph: moduleGraphOptions,
|
|
345
468
|
babelParserOptions: { sourceFilename: absoluteFile }
|
|
346
469
|
};
|
|
347
|
-
if (shouldSkipJsTransform(currentSource,
|
|
470
|
+
if (shouldSkipJsTransform(currentSource, {
|
|
471
|
+
...handlerOptions,
|
|
472
|
+
classNameSet: runtimeSet
|
|
473
|
+
})) return { result: new ConcatSource(currentSource) };
|
|
348
474
|
const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
|
|
349
475
|
const source = new ConcatSource(code);
|
|
350
|
-
compilerOptions.onUpdate(file, currentSource, code);
|
|
351
476
|
debug("js handle: %s", file);
|
|
352
477
|
applyLinkedResults(linked);
|
|
353
478
|
return { result: source };
|
|
@@ -358,6 +483,27 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
358
483
|
if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
|
|
359
484
|
const [file, originalSource] = element;
|
|
360
485
|
const rawSource = originalSource.source().toString();
|
|
486
|
+
if (isWebpackProcessedCssAsset?.(file, rawSource)) {
|
|
487
|
+
const nextCss = finalizeCssAssetSource(rawSource);
|
|
488
|
+
tasks.push(processCachedTask({
|
|
489
|
+
cache: compilerOptions.cache,
|
|
490
|
+
cacheKey: file,
|
|
491
|
+
hashKey: `${file}:asset`,
|
|
492
|
+
rawSource,
|
|
493
|
+
hash: createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash),
|
|
494
|
+
applyResult(source, { cacheHit }) {
|
|
495
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
496
|
+
},
|
|
497
|
+
onCacheHit() {
|
|
498
|
+
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
499
|
+
},
|
|
500
|
+
transform: async () => {
|
|
501
|
+
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
502
|
+
return { result: new ConcatSource(nextCss) };
|
|
503
|
+
}
|
|
504
|
+
}));
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
361
507
|
const cacheKey = file;
|
|
362
508
|
const runtimeAwareHash = createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash);
|
|
363
509
|
tasks.push(processCachedTask({
|
|
@@ -366,8 +512,8 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
366
512
|
hashKey: `${file}:asset`,
|
|
367
513
|
rawSource,
|
|
368
514
|
hash: runtimeAwareHash,
|
|
369
|
-
applyResult(source) {
|
|
370
|
-
|
|
515
|
+
applyResult(source, { cacheHit }) {
|
|
516
|
+
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
371
517
|
},
|
|
372
518
|
onCacheHit() {
|
|
373
519
|
debug("css cache hit: %s", file);
|
|
@@ -386,9 +532,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
386
532
|
styleHandler: compilerOptions.styleHandler,
|
|
387
533
|
debug
|
|
388
534
|
});
|
|
389
|
-
const
|
|
390
|
-
const source = new ConcatSource(css);
|
|
391
|
-
compilerOptions.onUpdate(file, rawSource, css);
|
|
535
|
+
const source = new ConcatSource(finalizeCssAssetSource(generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
392
536
|
if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
|
|
393
537
|
else debug("css handle: %s", file);
|
|
394
538
|
return { result: source };
|
|
@@ -398,16 +542,24 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
398
542
|
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
399
543
|
await Promise.all(tasks);
|
|
400
544
|
debug("end");
|
|
545
|
+
emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt);
|
|
401
546
|
compilerOptions.onEnd();
|
|
402
547
|
});
|
|
403
548
|
});
|
|
404
549
|
}
|
|
405
550
|
//#endregion
|
|
406
|
-
//#region ../../node_modules/.pnpm/tsdown@0.22.0_tsx@4.
|
|
551
|
+
//#region ../../node_modules/.pnpm/tsdown@0.22.1_oxc-resolver@11.20.0_tsx@4.22.4_typescript@6.0.3_unrun@0.2.37_synckit@0.1_af1474666acd5eae3876d23fc3fbcf5c/node_modules/tsdown/esm-shims.js
|
|
407
552
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
408
553
|
const getDirname = () => path.dirname(getFilename());
|
|
409
554
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
410
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
|
|
411
563
|
//#region src/bundlers/webpack/shared/loader-anchors.ts
|
|
412
564
|
const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
413
565
|
const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
|
|
@@ -438,7 +590,7 @@ function createLoaderAnchorFinders(appType) {
|
|
|
438
590
|
//#endregion
|
|
439
591
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
440
592
|
function setupWebpackV5Loaders(options) {
|
|
441
|
-
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;
|
|
442
594
|
const isMpxApp = isMpx(appType);
|
|
443
595
|
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
444
596
|
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
@@ -447,24 +599,31 @@ function setupWebpackV5Loaders(options) {
|
|
|
447
599
|
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
448
600
|
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
449
601
|
pkgDir: weappTailwindcssPackageDir,
|
|
450
|
-
|
|
451
|
-
|
|
602
|
+
compilerOptions,
|
|
603
|
+
runtimeState,
|
|
604
|
+
...appType === void 0 ? {} : { appType },
|
|
605
|
+
...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
|
|
606
|
+
getRuntimeSet: getRuntimeSetInLoader,
|
|
607
|
+
...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource }
|
|
452
608
|
} : void 0;
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
609
|
+
setWebpackLoaderRuntime(runtimeRegistryKey, {
|
|
610
|
+
classSet: {
|
|
611
|
+
getClassSet: getClassSetInLoader,
|
|
612
|
+
getWatchDependencies: getRuntimeWatchDependencies
|
|
613
|
+
},
|
|
614
|
+
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
615
|
+
});
|
|
457
616
|
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
458
|
-
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
617
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
459
618
|
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
460
619
|
const createRuntimeClassSetLoaderEntry = () => ({
|
|
461
620
|
loader: runtimeClassSetLoader,
|
|
462
|
-
options:
|
|
621
|
+
options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
|
|
463
622
|
ident: null,
|
|
464
623
|
type: null
|
|
465
624
|
});
|
|
466
625
|
const createCssImportRewriteLoaderEntry = () => {
|
|
467
|
-
if (!runtimeCssImportRewriteLoader) return null;
|
|
626
|
+
if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
|
|
468
627
|
return {
|
|
469
628
|
loader: runtimeCssImportRewriteLoader,
|
|
470
629
|
options: cssImportRewriteLoaderOptions,
|
|
@@ -481,15 +640,15 @@ function setupWebpackV5Loaders(options) {
|
|
|
481
640
|
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
482
641
|
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
483
642
|
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
484
|
-
if (process.env
|
|
643
|
+
if (process.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
485
644
|
rewriteAnchorIdx,
|
|
486
645
|
classSetAnchorIdx
|
|
487
646
|
});
|
|
488
|
-
if (process.env
|
|
647
|
+
if (process.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), {
|
|
489
648
|
rewriteAnchorIdx,
|
|
490
649
|
classSetAnchorIdx
|
|
491
650
|
});
|
|
492
|
-
else if (process.env
|
|
651
|
+
else if (process.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), {
|
|
493
652
|
rewriteAnchorIdx,
|
|
494
653
|
classSetAnchorIdx
|
|
495
654
|
});
|
|
@@ -522,14 +681,66 @@ function setupWebpackV5Loaders(options) {
|
|
|
522
681
|
}
|
|
523
682
|
//#endregion
|
|
524
683
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
684
|
+
init_defineProperty();
|
|
525
685
|
const debug = createDebug();
|
|
526
686
|
const weappTailwindcssPackageDir = 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 = path.resolve(file);
|
|
696
|
+
if (resolvedFile === ignoredPath || resolvedFile.startsWith(`${ignoredPath}${path.sep}`)) return true;
|
|
697
|
+
const normalizedFile = file.replace(/\\/g, "/");
|
|
698
|
+
return ignoredList.some((item) => {
|
|
699
|
+
if (typeof item === "string") {
|
|
700
|
+
const resolvedItem = path.resolve(item);
|
|
701
|
+
if (resolvedFile === resolvedItem || resolvedFile.startsWith(`${resolvedItem}${path.sep}`)) return true;
|
|
702
|
+
return micromatch.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" && path.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 ? path.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 ? path.resolve(outputPath) : void 0)) return;
|
|
733
|
+
const watchOptions = compiler.watching?.watchOptions;
|
|
734
|
+
if (watchOptions) appendOutputIgnoredPath(watchOptions);
|
|
735
|
+
};
|
|
736
|
+
compiler.hooks.watchRun?.tap(pluginName, syncOutputIgnoredPath);
|
|
737
|
+
}
|
|
527
738
|
/**
|
|
528
|
-
* @name
|
|
739
|
+
* @name WeappTailwindcss
|
|
529
740
|
* @description webpack5 核心转义插件
|
|
530
741
|
* @link https://tw.icebreaker.top/docs/intro
|
|
531
742
|
*/
|
|
532
|
-
var
|
|
743
|
+
var WeappTailwindcss = class {
|
|
533
744
|
constructor(options = {}) {
|
|
534
745
|
_defineProperty(this, "options", void 0);
|
|
535
746
|
_defineProperty(this, "appType", void 0);
|
|
@@ -545,10 +756,13 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
545
756
|
compiler.options = compiler.options || {};
|
|
546
757
|
const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
|
|
547
758
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
548
|
-
const
|
|
759
|
+
const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
|
|
760
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(this.options.generator);
|
|
761
|
+
const shouldRewriteCssImports = isTailwindcssV4 || generatorOptions.target === "web";
|
|
549
762
|
const isMpxApp = isMpx(this.appType);
|
|
550
763
|
if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
|
|
551
764
|
if (disabledOptions.plugin) return;
|
|
765
|
+
setupWebpackWatchOutputIgnore(compiler);
|
|
552
766
|
const runtimeState = {
|
|
553
767
|
twPatcher: initialTwPatcher,
|
|
554
768
|
readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
@@ -557,8 +771,10 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
557
771
|
let runtimeSetPrepared = false;
|
|
558
772
|
let runtimeSetSignature;
|
|
559
773
|
let runtimeRefreshRequiredForCompilation = false;
|
|
774
|
+
let watchRunObserved = false;
|
|
560
775
|
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
561
776
|
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
777
|
+
const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
562
778
|
let runtimeMetadataPrepared = false;
|
|
563
779
|
const updateRuntimeWatchDependencies = async () => {
|
|
564
780
|
runtimeWatchDependencyFiles.clear();
|
|
@@ -585,12 +801,24 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
585
801
|
await updateRuntimeWatchDependencies();
|
|
586
802
|
runtimeMetadataPrepared = true;
|
|
587
803
|
};
|
|
588
|
-
const
|
|
589
|
-
|
|
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);
|
|
590
819
|
};
|
|
591
820
|
const resetRuntimePreparation = () => {
|
|
592
821
|
runtimeSetPrepared = false;
|
|
593
|
-
runtimeMetadataPrepared = false;
|
|
594
822
|
syncRuntimeRefreshRequirement();
|
|
595
823
|
};
|
|
596
824
|
const registerAutoCssSource = async (source) => {
|
|
@@ -605,10 +833,14 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
605
833
|
});
|
|
606
834
|
debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
|
|
607
835
|
};
|
|
608
|
-
|
|
609
|
-
|
|
836
|
+
const markWebpackProcessedCssSource = (file) => {
|
|
837
|
+
webpackProcessedCssSourceFiles.add(path.resolve(file));
|
|
838
|
+
};
|
|
839
|
+
compiler.hooks.invalid?.tap?.(pluginName, (fileName) => {
|
|
840
|
+
if (!fileName) return;
|
|
841
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([path.resolve(fileName)]);
|
|
610
842
|
});
|
|
611
|
-
compiler.hooks.watchRun?.tap?.(pluginName, syncRuntimeRefreshRequirement);
|
|
843
|
+
compiler.hooks.watchRun?.tap?.(pluginName, () => syncRuntimeRefreshRequirement(true));
|
|
612
844
|
if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
|
|
613
845
|
else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(pluginName, resetRuntimePreparation);
|
|
614
846
|
async function getClassSetInLoader() {
|
|
@@ -619,7 +851,7 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
619
851
|
runtimeSetPrepared = true;
|
|
620
852
|
await ensureRuntimeClassSet(runtimeState, {
|
|
621
853
|
forceRefresh,
|
|
622
|
-
forceCollect:
|
|
854
|
+
forceCollect: forceRefresh || !watchRunObserved,
|
|
623
855
|
clearCache: forceRefresh,
|
|
624
856
|
allowEmpty: true
|
|
625
857
|
});
|
|
@@ -627,6 +859,10 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
627
859
|
runtimeSetSignature = signature;
|
|
628
860
|
runtimeRefreshRequiredForCompilation = false;
|
|
629
861
|
}
|
|
862
|
+
async function getRuntimeSetInLoader() {
|
|
863
|
+
await getClassSetInLoader();
|
|
864
|
+
return ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
|
|
865
|
+
}
|
|
630
866
|
onLoad();
|
|
631
867
|
setupWebpackV5Loaders({
|
|
632
868
|
compiler,
|
|
@@ -636,7 +872,10 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
636
872
|
shouldRewriteCssImports,
|
|
637
873
|
runtimeLoaderPath,
|
|
638
874
|
registerAutoCssSource,
|
|
875
|
+
runtimeState,
|
|
639
876
|
getClassSetInLoader,
|
|
877
|
+
getRuntimeSetInLoader,
|
|
878
|
+
markWebpackProcessedCssSource,
|
|
640
879
|
getRuntimeWatchDependencies() {
|
|
641
880
|
return {
|
|
642
881
|
files: runtimeWatchDependencyFiles,
|
|
@@ -652,12 +891,17 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
652
891
|
runtimeState,
|
|
653
892
|
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
654
893
|
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
894
|
+
isWebpackProcessedCssAsset(file, rawSource) {
|
|
895
|
+
return webpackProcessedCssSourceFiles.has(path.resolve(file)) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
|
|
896
|
+
},
|
|
655
897
|
consumeRuntimeRefreshRequirement() {
|
|
656
898
|
runtimeRefreshRequiredForCompilation = false;
|
|
657
899
|
},
|
|
900
|
+
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
901
|
+
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
658
902
|
debug
|
|
659
903
|
});
|
|
660
904
|
}
|
|
661
905
|
};
|
|
662
906
|
//#endregion
|
|
663
|
-
export { weappTailwindcssPackageDir as n,
|
|
907
|
+
export { weappTailwindcssPackageDir as n, WeappTailwindcss as t };
|