weapp-tailwindcss 5.0.13 → 5.1.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.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +16 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +138 -444
- package/dist/cli.mjs +134 -440
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +5 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
- package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
- package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
- package/dist/defaults.d.ts +2 -8
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-6oMJtTDO.js +170 -0
- package/dist/generator-CjzBK7h-.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +87 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +15 -7
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
- package/dist/tailwindcss-dbrbY4cd.js +1528 -0
- package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
- package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
- package/dist/v4-engine-ON_oSLfO.js +2752 -0
- package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
- package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-8PaV1gG3.mjs +2334 -0
- package/dist/webpack-CGgBOx9l.js +2346 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
package/dist/webpack-CfkUkMXG.js
DELETED
|
@@ -1,1196 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
-
const require_v3_engine = require("./v3-engine-2rrgylhn.js");
|
|
3
|
-
const require_generator = require("./generator-CzpArpCL.js");
|
|
4
|
-
const require_precheck = require("./precheck-B0Z8yW7E.js");
|
|
5
|
-
const require_utils = require("./utils-BCa37Wqj.js");
|
|
6
|
-
const require_tailwindcss = require("./tailwindcss-DZEwT3C_.js");
|
|
7
|
-
const require_hmr_timing = require("./hmr-timing-BMftW7Us.js");
|
|
8
|
-
const require_bundle_state = require("./bundle-state-CKWeTEhv.js");
|
|
9
|
-
let node_fs = require("node:fs");
|
|
10
|
-
node_fs = require_chunk.__toESM(node_fs);
|
|
11
|
-
let node_path = require("node:path");
|
|
12
|
-
node_path = require_chunk.__toESM(node_path);
|
|
13
|
-
let node_process = require("node:process");
|
|
14
|
-
node_process = require_chunk.__toESM(node_process);
|
|
15
|
-
let node_module = require("node:module");
|
|
16
|
-
node_module = require_chunk.__toESM(node_module);
|
|
17
|
-
let micromatch = require("micromatch");
|
|
18
|
-
micromatch = require_chunk.__toESM(micromatch);
|
|
19
|
-
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
20
|
-
//#region src/shared/tailwindcss-css-redirect.ts
|
|
21
|
-
const moduleWithMutableResolve = node_module.default;
|
|
22
|
-
const patched = /* @__PURE__ */ new WeakSet();
|
|
23
|
-
function installTailwindcssCssRedirect(pkgDir) {
|
|
24
|
-
const target = node_path.default.join(pkgDir, "index.css");
|
|
25
|
-
const original = moduleWithMutableResolve._resolveFilename;
|
|
26
|
-
if (patched.has(original)) return;
|
|
27
|
-
const replacements = new Set(["tailwindcss", "tailwindcss$"]);
|
|
28
|
-
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
29
|
-
if (replacements.has(request)) return target;
|
|
30
|
-
if (request.startsWith("tailwindcss/")) return node_path.default.join(pkgDir, request.slice(12));
|
|
31
|
-
return original(request, parent, isMain, options);
|
|
32
|
-
};
|
|
33
|
-
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
34
|
-
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/shared/mpx.ts
|
|
38
|
-
const localRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
39
|
-
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
40
|
-
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
41
|
-
function isMpxStyleResourceQuery(query) {
|
|
42
|
-
if (typeof query !== "string") return false;
|
|
43
|
-
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
44
|
-
}
|
|
45
|
-
function isMpx(appType) {
|
|
46
|
-
return appType === "mpx";
|
|
47
|
-
}
|
|
48
|
-
function getTailwindcssCssEntry(pkgDir) {
|
|
49
|
-
return node_path.default.join(pkgDir, "index.css");
|
|
50
|
-
}
|
|
51
|
-
function resolveMpxWebpackPluginDir(compiler) {
|
|
52
|
-
const candidates = [
|
|
53
|
-
compiler?.context,
|
|
54
|
-
compiler?.options?.context,
|
|
55
|
-
node_process.default.cwd()
|
|
56
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
57
|
-
for (const candidate of candidates) try {
|
|
58
|
-
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
59
|
-
return node_path.default.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
60
|
-
} catch {}
|
|
61
|
-
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
62
|
-
if (cachedPackageJson) return node_path.default.dirname(cachedPackageJson);
|
|
63
|
-
try {
|
|
64
|
-
return node_path.default.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
65
|
-
} catch {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function isMpxWebpackPluginRequest(request) {
|
|
70
|
-
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
71
|
-
}
|
|
72
|
-
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
73
|
-
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
74
|
-
return node_path.default.join(mpxWebpackPluginDir, request.slice(22));
|
|
75
|
-
}
|
|
76
|
-
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
77
|
-
const recordLoader = node_path.default.join(pkgDir, "lib/record-loader");
|
|
78
|
-
const styleCompiler = node_path.default.join(pkgDir, "lib/style-compiler/index");
|
|
79
|
-
const stripConditionalLoader = node_path.default.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
80
|
-
if (Array.isArray(alias)) alias.push({
|
|
81
|
-
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
82
|
-
alias: recordLoader
|
|
83
|
-
}, {
|
|
84
|
-
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
85
|
-
alias: styleCompiler
|
|
86
|
-
}, {
|
|
87
|
-
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
88
|
-
alias: stripConditionalLoader
|
|
89
|
-
}, {
|
|
90
|
-
name: /^@mpxjs\/webpack-plugin\//,
|
|
91
|
-
alias: pkgDir
|
|
92
|
-
});
|
|
93
|
-
else {
|
|
94
|
-
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
95
|
-
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
96
|
-
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
97
|
-
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
98
|
-
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
102
|
-
compiler.options.resolveLoader = compiler.options.resolveLoader || {};
|
|
103
|
-
const alias = compiler.options.resolveLoader.alias ?? {};
|
|
104
|
-
compiler.options.resolveLoader.alias = alias;
|
|
105
|
-
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
106
|
-
}
|
|
107
|
-
function resolveMpxWebpackPluginRequire(compiler) {
|
|
108
|
-
const candidates = [
|
|
109
|
-
compiler?.context,
|
|
110
|
-
compiler?.options?.context,
|
|
111
|
-
node_process.default.cwd()
|
|
112
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
113
|
-
for (const candidate of candidates) try {
|
|
114
|
-
const projectRequire = (0, node_module.createRequire)(node_path.default.join(candidate, "package.json"));
|
|
115
|
-
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
116
|
-
return projectRequire;
|
|
117
|
-
} catch {}
|
|
118
|
-
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
119
|
-
if (cachedPackageJson) return (0, node_module.createRequire)(cachedPackageJson);
|
|
120
|
-
return localRequire;
|
|
121
|
-
}
|
|
122
|
-
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
123
|
-
if (!mpxWebpackPluginDir) return false;
|
|
124
|
-
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
125
|
-
let normalize;
|
|
126
|
-
try {
|
|
127
|
-
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
128
|
-
} catch {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
if (typeof normalize.lib !== "function") return false;
|
|
132
|
-
if (normalize.lib.__weappTwPatched) return true;
|
|
133
|
-
const wrappedLib = (file) => node_path.default.join(mpxWebpackPluginDir, "lib", file);
|
|
134
|
-
wrappedLib.__weappTwPatched = true;
|
|
135
|
-
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
136
|
-
normalize.lib = wrappedLib;
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
140
|
-
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
141
|
-
compiler.options = compiler.options || {};
|
|
142
|
-
compiler.options.resolve = compiler.options.resolve || {};
|
|
143
|
-
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
144
|
-
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
145
|
-
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
146
|
-
const alias = compiler.options.resolve.alias ?? {};
|
|
147
|
-
compiler.options.resolve.alias = alias;
|
|
148
|
-
if (Array.isArray(alias)) alias.push({
|
|
149
|
-
name: "tailwindcss",
|
|
150
|
-
alias: tailwindcssCssEntry
|
|
151
|
-
}, {
|
|
152
|
-
name: "tailwindcss$",
|
|
153
|
-
alias: tailwindcssCssEntry
|
|
154
|
-
});
|
|
155
|
-
else {
|
|
156
|
-
alias.tailwindcss = tailwindcssCssEntry;
|
|
157
|
-
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
158
|
-
}
|
|
159
|
-
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
160
|
-
return tailwindcssCssEntry;
|
|
161
|
-
}
|
|
162
|
-
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
163
|
-
if (!enabled || typeof loaderContext.resolve !== "function") return;
|
|
164
|
-
const originalResolve = loaderContext.resolve;
|
|
165
|
-
if (originalResolve.__weappTwPatched) return;
|
|
166
|
-
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
167
|
-
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
168
|
-
const wrappedResolve = function(context, request, callback) {
|
|
169
|
-
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
170
|
-
if (request?.startsWith("tailwindcss/")) return callback(null, node_path.default.join(pkgDir, request.slice(12)));
|
|
171
|
-
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
172
|
-
return originalResolve.call(this, context, request, callback);
|
|
173
|
-
};
|
|
174
|
-
wrappedResolve.__weappTwPatched = true;
|
|
175
|
-
loaderContext.resolve = wrappedResolve;
|
|
176
|
-
}
|
|
177
|
-
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
178
|
-
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
179
|
-
}
|
|
180
|
-
const CSS_EXT_RE = /\.css$/i;
|
|
181
|
-
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
182
|
-
var _compiler$options;
|
|
183
|
-
if (!loader) return;
|
|
184
|
-
const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
|
|
185
|
-
moduleOptions.rules = moduleOptions.rules || [];
|
|
186
|
-
const createRule = (match) => ({
|
|
187
|
-
...match,
|
|
188
|
-
enforce: "pre",
|
|
189
|
-
use: [{
|
|
190
|
-
loader,
|
|
191
|
-
options: loaderOptions
|
|
192
|
-
}]
|
|
193
|
-
});
|
|
194
|
-
moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
|
|
195
|
-
test: CSS_EXT_RE,
|
|
196
|
-
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
|
|
201
|
-
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
|
|
202
|
-
function getCacheKey(filename) {
|
|
203
|
-
return filename;
|
|
204
|
-
}
|
|
205
|
-
function stripResourceQuery(resource) {
|
|
206
|
-
if (typeof resource !== "string") return resource;
|
|
207
|
-
return require_bundle_state.stripRequestQuery(resource);
|
|
208
|
-
}
|
|
209
|
-
function isCssLikeModuleResource(resource, cssMatcher, appType) {
|
|
210
|
-
if (typeof resource !== "string") return false;
|
|
211
|
-
const normalizedResource = stripResourceQuery(resource);
|
|
212
|
-
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
213
|
-
if (require_bundle_state.isSourceStyleRequest(resource)) return true;
|
|
214
|
-
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
function hasLoaderEntry(entries, target) {
|
|
218
|
-
if (!target) return false;
|
|
219
|
-
return entries.some((entry) => entry.loader?.includes?.(target));
|
|
220
|
-
}
|
|
221
|
-
function normalizeWatchPath(file) {
|
|
222
|
-
return node_path.default.resolve(file);
|
|
223
|
-
}
|
|
224
|
-
function isFileInContext(file, context) {
|
|
225
|
-
const relative = node_path.default.relative(normalizeWatchPath(context), normalizeWatchPath(file));
|
|
226
|
-
return relative.length > 0 && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
227
|
-
}
|
|
228
|
-
function toChunkFiles(files) {
|
|
229
|
-
if (!files) return [];
|
|
230
|
-
if (Array.isArray(files)) return files;
|
|
231
|
-
return [...files];
|
|
232
|
-
}
|
|
233
|
-
function createAssetHashByChunkMap(chunks) {
|
|
234
|
-
const partsByFile = /* @__PURE__ */ new Map();
|
|
235
|
-
for (const chunk of chunks) {
|
|
236
|
-
const hash = typeof chunk.hash === "string" ? chunk.hash : void 0;
|
|
237
|
-
if (!hash) continue;
|
|
238
|
-
const chunkId = String(chunk.id ?? chunk.name ?? "");
|
|
239
|
-
for (const file of toChunkFiles(chunk.files)) {
|
|
240
|
-
if (!file) continue;
|
|
241
|
-
let parts = partsByFile.get(file);
|
|
242
|
-
if (!parts) {
|
|
243
|
-
parts = [];
|
|
244
|
-
partsByFile.set(file, parts);
|
|
245
|
-
}
|
|
246
|
-
parts.push(`${chunkId}:${hash}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const hashByFile = /* @__PURE__ */ new Map();
|
|
250
|
-
for (const [file, parts] of partsByFile.entries()) hashByFile.set(file, parts.sort().join("|"));
|
|
251
|
-
return hashByFile;
|
|
252
|
-
}
|
|
253
|
-
function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
|
|
254
|
-
return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
|
|
255
|
-
}
|
|
256
|
-
function isWatchFileInRuntimeDependencies(file, dependencies) {
|
|
257
|
-
const normalizedFile = normalizeWatchPath(file);
|
|
258
|
-
for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
|
|
259
|
-
for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
|
|
264
|
-
function createWebpackSnapshotAssets(assets) {
|
|
265
|
-
return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
|
|
266
|
-
const source = asset.source();
|
|
267
|
-
return [file, {
|
|
268
|
-
fileName: file,
|
|
269
|
-
source: typeof source === "string" ? source : source?.toString() ?? "",
|
|
270
|
-
type: "asset"
|
|
271
|
-
}];
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
function stringifyWebpackSource(source) {
|
|
275
|
-
if (typeof source === "string") return source;
|
|
276
|
-
return source?.toString() ?? "";
|
|
277
|
-
}
|
|
278
|
-
function createWebpackAssetUpdater(options) {
|
|
279
|
-
const getCurrentAssetSource = (file) => {
|
|
280
|
-
const asset = options.compilation.getAsset(file);
|
|
281
|
-
if (!asset) return;
|
|
282
|
-
return stringifyWebpackSource(asset.source.source());
|
|
283
|
-
};
|
|
284
|
-
const updateAssetIfChanged = (file, source, { notifyUpdate = true } = {}) => {
|
|
285
|
-
const nextSource = typeof source === "string" ? source : stringifyWebpackSource(source.source());
|
|
286
|
-
const previousSource = getCurrentAssetSource(file);
|
|
287
|
-
if (previousSource === nextSource) {
|
|
288
|
-
options.debug("asset unchanged, skip update: %s", file);
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
options.compilation.updateAsset(file, typeof source === "string" ? new options.ConcatSource(source) : source);
|
|
292
|
-
if (notifyUpdate) options.onUpdate(file, previousSource ?? "", nextSource);
|
|
293
|
-
return true;
|
|
294
|
-
};
|
|
295
|
-
return {
|
|
296
|
-
getCurrentAssetSource,
|
|
297
|
-
updateAssetIfChanged
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
//#endregion
|
|
301
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
|
|
302
|
-
const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
|
|
303
|
-
function toMb(bytes) {
|
|
304
|
-
return Math.round(bytes / 1024 / 1024);
|
|
305
|
-
}
|
|
306
|
-
function pruneMapToMaxSize(map, maxSize) {
|
|
307
|
-
while (map.size > maxSize) {
|
|
308
|
-
const oldestKey = map.keys().next().value;
|
|
309
|
-
if (oldestKey === void 0) break;
|
|
310
|
-
map.delete(oldestKey);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
|
|
314
|
-
const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
|
|
315
|
-
for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
|
|
316
|
-
for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
|
|
317
|
-
pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
318
|
-
pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
319
|
-
}
|
|
320
|
-
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
321
|
-
return cssHandlerOptions.sourceOptions?.sourceCss ?? rawSource;
|
|
322
|
-
}
|
|
323
|
-
function stripStyleExtension(file) {
|
|
324
|
-
const normalized = file.replace(/[?#].*$/, "");
|
|
325
|
-
const ext = node_path.default.extname(normalized);
|
|
326
|
-
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
327
|
-
}
|
|
328
|
-
function normalizeMatchPath(file) {
|
|
329
|
-
return file.split(node_path.default.sep).join("/");
|
|
330
|
-
}
|
|
331
|
-
function isPathWithinRoot(file, root) {
|
|
332
|
-
const relative = node_path.default.relative(root, file);
|
|
333
|
-
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
334
|
-
}
|
|
335
|
-
function collectWebpackCssMatchBases(file, roots) {
|
|
336
|
-
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
337
|
-
const bases = /* @__PURE__ */ new Set();
|
|
338
|
-
const addBase = (candidate) => {
|
|
339
|
-
const stripped = normalizeMatchPath(stripStyleExtension(candidate));
|
|
340
|
-
if (stripped.length > 0) {
|
|
341
|
-
bases.add(stripped);
|
|
342
|
-
const withoutWorkspaceSegment = stripped.replace(/^(?:src|dist)\//, "");
|
|
343
|
-
if (withoutWorkspaceSegment !== stripped && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
addBase(normalizedFile);
|
|
347
|
-
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => node_path.default.resolve(root));
|
|
348
|
-
if (node_path.default.isAbsolute(normalizedFile)) {
|
|
349
|
-
for (const root of resolvedRoots) if (isPathWithinRoot(normalizedFile, root)) addBase(node_path.default.relative(root, normalizedFile));
|
|
350
|
-
} else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
351
|
-
return bases;
|
|
352
|
-
}
|
|
353
|
-
function scoreWebpackCssSourceFileMatch(outputFile, sourceFile, options) {
|
|
354
|
-
const outputBases = collectWebpackCssMatchBases(outputFile, [options.outputRoot, options.projectRoot]);
|
|
355
|
-
const sourceBases = collectWebpackCssMatchBases(sourceFile, [options.projectRoot]);
|
|
356
|
-
let bestScore = 0;
|
|
357
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
358
|
-
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
359
|
-
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
360
|
-
return bestScore;
|
|
361
|
-
}
|
|
362
|
-
function resolveWebpackMemoryDebugStats(context) {
|
|
363
|
-
if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
364
|
-
const memory = node_process.default.memoryUsage();
|
|
365
|
-
return {
|
|
366
|
-
phase: context.phase,
|
|
367
|
-
process: {
|
|
368
|
-
rssMb: toMb(memory.rss),
|
|
369
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
370
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
371
|
-
externalMb: toMb(memory.external),
|
|
372
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
373
|
-
},
|
|
374
|
-
assets: {
|
|
375
|
-
active: context.activeAssetFiles,
|
|
376
|
-
activeCss: context.activeCssFiles
|
|
377
|
-
},
|
|
378
|
-
processCache: {
|
|
379
|
-
instance: context.cache.instance.size,
|
|
380
|
-
hashMap: context.cache.hashMap.size,
|
|
381
|
-
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
382
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
383
|
-
},
|
|
384
|
-
webpackCss: {
|
|
385
|
-
handlerOptions: context.cssHandlerOptionsCache.size,
|
|
386
|
-
userHandlerOptions: context.cssUserHandlerOptionsCache.size,
|
|
387
|
-
maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
|
|
388
|
-
},
|
|
389
|
-
tailwind: {
|
|
390
|
-
v3: require_v3_engine.getTailwindV3IncrementalGenerateCacheStats(),
|
|
391
|
-
v4: require_v3_engine.getTailwindV4IncrementalGenerateCacheStats()
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
function setupWebpackV5ProcessAssetsHook(options) {
|
|
396
|
-
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, getWebpackCssSources, debug } = options;
|
|
397
|
-
const { Compilation, sources } = compiler.webpack;
|
|
398
|
-
const { ConcatSource } = sources;
|
|
399
|
-
const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
|
|
400
|
-
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
401
|
-
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
402
|
-
const bundleBuildState = require_bundle_state.createBundleBuildState();
|
|
403
|
-
const bundleRuntimeClassSetManager = runtimeClassSetManager ?? require_hmr_timing.createBundleRuntimeClassSetManager();
|
|
404
|
-
let webpackWatchRuntimeScanInitialized = false;
|
|
405
|
-
compiler.hooks.compilation.tap(require_precheck.pluginName, (compilation) => {
|
|
406
|
-
compilation.hooks.processAssets.tapPromise({
|
|
407
|
-
name: require_precheck.pluginName,
|
|
408
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
409
|
-
}, async (assets) => {
|
|
410
|
-
compilerOptions.onStart();
|
|
411
|
-
debug("start");
|
|
412
|
-
await runtimeState.readyPromise;
|
|
413
|
-
const hmrTimingStartedAt = performance.now();
|
|
414
|
-
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
415
|
-
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
416
|
-
const { updateAssetIfChanged } = createWebpackAssetUpdater({
|
|
417
|
-
compilation,
|
|
418
|
-
ConcatSource,
|
|
419
|
-
onUpdate: compilerOptions.onUpdate,
|
|
420
|
-
debug
|
|
421
|
-
});
|
|
422
|
-
const entries = Object.entries(assets);
|
|
423
|
-
const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
|
|
424
|
-
const outputDir = compilerOutputPath ? node_path.default.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? node_process.default.cwd();
|
|
425
|
-
const jsAssets = /* @__PURE__ */ new Map();
|
|
426
|
-
for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
|
|
427
|
-
const absolute = require_bundle_state.toAbsoluteOutputPath(file, outputDir);
|
|
428
|
-
jsAssets.set(absolute, file);
|
|
429
|
-
}
|
|
430
|
-
const moduleGraphOptions = {
|
|
431
|
-
resolve(specifier, importer) {
|
|
432
|
-
return require_bundle_state.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
433
|
-
},
|
|
434
|
-
load: (id) => {
|
|
435
|
-
const assetName = jsAssets.get(id);
|
|
436
|
-
if (!assetName) return;
|
|
437
|
-
const asset = compilation.getAsset(assetName);
|
|
438
|
-
if (!asset) return;
|
|
439
|
-
const source = asset.source.source();
|
|
440
|
-
return typeof source === "string" ? source : source.toString();
|
|
441
|
-
},
|
|
442
|
-
filter(id) {
|
|
443
|
-
return jsAssets.has(id);
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
const applyLinkedResults = (linked) => {
|
|
447
|
-
if (!linked) return;
|
|
448
|
-
for (const [id, { code }] of Object.entries(linked)) {
|
|
449
|
-
const assetName = jsAssets.get(id);
|
|
450
|
-
if (!assetName) continue;
|
|
451
|
-
const asset = compilation.getAsset(assetName);
|
|
452
|
-
if (!asset) continue;
|
|
453
|
-
const previousSource = asset.source.source();
|
|
454
|
-
if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
|
|
455
|
-
if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
const groupedEntries = require_utils.getGroupedEntries(entries, compilerOptions);
|
|
459
|
-
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
460
|
-
const activeProcessHashKeys = /* @__PURE__ */ new Set();
|
|
461
|
-
const rememberProcessCacheKey = (cacheKey, hashKey = cacheKey) => {
|
|
462
|
-
activeProcessCacheKeys.add(cacheKey);
|
|
463
|
-
activeProcessHashKeys.add(hashKey);
|
|
464
|
-
};
|
|
465
|
-
for (const chunk of compilation.chunks) if (chunk.id) activeProcessHashKeys.add(chunk.id);
|
|
466
|
-
const cssSources = new Map([...getWebpackCssSources?.() ?? []].map(([file, css]) => [node_path.default.resolve(file), css]));
|
|
467
|
-
const cssSourceFiles = [...cssSources.keys()].sort();
|
|
468
|
-
const resolveWebpackCssSourceFile = (file) => {
|
|
469
|
-
if (cssSourceFiles.length === 0) return;
|
|
470
|
-
const matches = cssSourceFiles.map((sourceFile) => ({
|
|
471
|
-
sourceFile,
|
|
472
|
-
score: scoreWebpackCssSourceFileMatch(file, sourceFile, {
|
|
473
|
-
outputRoot: outputDir,
|
|
474
|
-
projectRoot: compilerOptions.tailwindcssBasedir
|
|
475
|
-
})
|
|
476
|
-
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
477
|
-
const bestScore = matches[0]?.score ?? 0;
|
|
478
|
-
const bestMatches = matches.filter((match) => match.score === bestScore);
|
|
479
|
-
return bestMatches.length === 1 ? bestMatches[0]?.sourceFile : void 0;
|
|
480
|
-
};
|
|
481
|
-
const getCssHandlerOptions = (file) => {
|
|
482
|
-
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
483
|
-
const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
|
|
484
|
-
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
485
|
-
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
486
|
-
const cacheKey = [
|
|
487
|
-
majorVersion ?? "unknown",
|
|
488
|
-
isMainChunk ? "1" : "0",
|
|
489
|
-
sourceFile ?? "asset",
|
|
490
|
-
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
491
|
-
file
|
|
492
|
-
].join(":");
|
|
493
|
-
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
494
|
-
if (cached) return cached;
|
|
495
|
-
const created = {
|
|
496
|
-
isMainChunk,
|
|
497
|
-
postcssOptions: { options: { from: sourceFile ?? file } },
|
|
498
|
-
sourceOptions: {
|
|
499
|
-
outputRoot: outputDir,
|
|
500
|
-
...sourceCss === void 0 ? {} : { sourceCss },
|
|
501
|
-
...sourceFile === void 0 ? {} : { sourceFile }
|
|
502
|
-
},
|
|
503
|
-
...majorVersion === void 0 ? {} : { majorVersion }
|
|
504
|
-
};
|
|
505
|
-
cssHandlerOptionsCache.set(cacheKey, created);
|
|
506
|
-
return created;
|
|
507
|
-
};
|
|
508
|
-
const getCssUserHandlerOptions = (file) => {
|
|
509
|
-
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
510
|
-
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
511
|
-
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
512
|
-
const cacheKey = [
|
|
513
|
-
majorVersion ?? "unknown",
|
|
514
|
-
sourceFile ?? "asset",
|
|
515
|
-
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
516
|
-
file
|
|
517
|
-
].join(":");
|
|
518
|
-
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
519
|
-
if (cached) return cached;
|
|
520
|
-
const created = {
|
|
521
|
-
...getCssHandlerOptions(file),
|
|
522
|
-
isMainChunk: false
|
|
523
|
-
};
|
|
524
|
-
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
525
|
-
return created;
|
|
526
|
-
};
|
|
527
|
-
const refreshWebpackSourceCandidates = async () => {
|
|
528
|
-
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
529
|
-
if (majorVersion !== 3 && majorVersion !== 4) return;
|
|
530
|
-
const root = compilerOptions.tailwindcssBasedir ?? node_process.default.cwd();
|
|
531
|
-
let sourceScan;
|
|
532
|
-
try {
|
|
533
|
-
sourceScan = await require_v3_engine.resolveViteSourceScanEntries(compilerOptions, runtimeState.twPatcher, {
|
|
534
|
-
root,
|
|
535
|
-
outDir: outputDir
|
|
536
|
-
});
|
|
537
|
-
} catch (error) {
|
|
538
|
-
debug("webpack source candidate scan skipped: %O", error);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const collector = require_hmr_timing.createSourceCandidateCollector({
|
|
542
|
-
bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues,
|
|
543
|
-
extractor: majorVersion === 3 ? require_hmr_timing.createTailwindV3DefaultExtractor() : void 0
|
|
544
|
-
});
|
|
545
|
-
await collector.scanRoot({
|
|
546
|
-
entries: sourceScan?.entries,
|
|
547
|
-
explicit: sourceScan?.explicit,
|
|
548
|
-
root,
|
|
549
|
-
outDir: outputDir
|
|
550
|
-
});
|
|
551
|
-
collector.syncInline(sourceScan?.inlineCandidates);
|
|
552
|
-
const candidates = sourceScan?.entries ? collector.valuesForEntries(sourceScan.entries) : collector.values();
|
|
553
|
-
return {
|
|
554
|
-
candidates,
|
|
555
|
-
getSourceCandidatesForEntries: (entries, options) => collector.valuesForEntries(entries, options),
|
|
556
|
-
signature: compilerOptions.cache.computeHash(JSON.stringify({
|
|
557
|
-
root,
|
|
558
|
-
outDir: outputDir,
|
|
559
|
-
entries: sourceScan?.entries,
|
|
560
|
-
explicit: sourceScan?.explicit ?? false,
|
|
561
|
-
inlineCandidates: sourceScan?.inlineCandidates ? {
|
|
562
|
-
included: [...sourceScan.inlineCandidates.included].sort(),
|
|
563
|
-
excluded: [...sourceScan.inlineCandidates.excluded].sort()
|
|
564
|
-
} : void 0,
|
|
565
|
-
dependencies: [...sourceScan?.dependencies ?? []].sort(),
|
|
566
|
-
candidates: [...candidates].sort()
|
|
567
|
-
})),
|
|
568
|
-
tokenSources: collector.sourcesForEntries(sourceScan?.entries)
|
|
569
|
-
};
|
|
570
|
-
};
|
|
571
|
-
const finalizeCssAssetSource = (source, options = {}) => {
|
|
572
|
-
const styleOptions = require_precheck.resolveStyleOptionsFromContext(compilerOptions);
|
|
573
|
-
let finalized = require_v3_engine.removeTailwindSourceDirectives(require_bundle_state.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
574
|
-
if (isWebGeneratorTarget || options.generatedCss !== true) return finalized;
|
|
575
|
-
try {
|
|
576
|
-
finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: runtimeState.twPatcher.majorVersion === 3 });
|
|
577
|
-
} catch {
|
|
578
|
-
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
|
|
579
|
-
cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
|
|
580
|
-
isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
|
|
581
|
-
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3,
|
|
582
|
-
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
return finalized;
|
|
586
|
-
};
|
|
587
|
-
const finalizeMiniProgramUserCssAssetSource = (source) => {
|
|
588
|
-
const styleOptions = require_precheck.resolveStyleOptionsFromContext(compilerOptions);
|
|
589
|
-
if (isWebGeneratorTarget) return source;
|
|
590
|
-
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(source, {
|
|
591
|
-
cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
|
|
592
|
-
isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
|
|
593
|
-
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3,
|
|
594
|
-
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
595
|
-
});
|
|
596
|
-
};
|
|
597
|
-
const webpackSourceCandidates = groupedEntries.css?.length || require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates() : void 0;
|
|
598
|
-
const cssSourceTraceTokenSources = require_hmr_timing.isCssSourceTraceEnabled(compilerOptions) && webpackSourceCandidates ? require_hmr_timing.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions) : void 0;
|
|
599
|
-
const cssSourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
|
|
600
|
-
const annotateCss = (css) => require_hmr_timing.annotateCssSourceTrace(css, {
|
|
601
|
-
opts: compilerOptions,
|
|
602
|
-
tokenSources: cssSourceTraceTokenSources
|
|
603
|
-
});
|
|
604
|
-
const finalizeTracedCss = (css) => {
|
|
605
|
-
const traced = annotateCss(css);
|
|
606
|
-
if (isWebGeneratorTarget || !require_hmr_timing.isCssSourceTraceEnabled(compilerOptions)) return traced;
|
|
607
|
-
return finalizeMiniProgramUserCssAssetSource(traced);
|
|
608
|
-
};
|
|
609
|
-
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
610
|
-
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
|
|
611
|
-
let runtimeSet;
|
|
612
|
-
const watchMode = isWatchMode?.() === true;
|
|
613
|
-
if (watchMode && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
|
|
614
|
-
const snapshot = require_bundle_state.buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
|
|
615
|
-
if (!webpackWatchRuntimeScanInitialized) {
|
|
616
|
-
for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
|
|
617
|
-
}
|
|
618
|
-
try {
|
|
619
|
-
runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
620
|
-
} catch (error) {
|
|
621
|
-
debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
622
|
-
await bundleRuntimeClassSetManager.reset();
|
|
623
|
-
runtimeSet = await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
624
|
-
forceRefresh: false,
|
|
625
|
-
forceCollect: true,
|
|
626
|
-
clearCache: false,
|
|
627
|
-
allowEmpty: false
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
require_bundle_state.updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
|
|
631
|
-
webpackWatchRuntimeScanInitialized = true;
|
|
632
|
-
} else {
|
|
633
|
-
if (forceRuntimeRefresh) {
|
|
634
|
-
await bundleRuntimeClassSetManager.reset();
|
|
635
|
-
webpackWatchRuntimeScanInitialized = false;
|
|
636
|
-
}
|
|
637
|
-
runtimeSet = await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
638
|
-
forceRefresh: forceRuntimeRefresh,
|
|
639
|
-
forceCollect: !watchMode || forceRuntimeRefresh,
|
|
640
|
-
clearCache: forceRuntimeRefresh,
|
|
641
|
-
allowEmpty: false
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
645
|
-
consumeRuntimeRefreshRequirement();
|
|
646
|
-
const runtimeSetHash = compilerOptions.cache.computeHash([require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
|
|
647
|
-
const defaultTemplateHandlerOptions = { runtimeSet };
|
|
648
|
-
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
649
|
-
const tasks = [];
|
|
650
|
-
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
651
|
-
const [file, originalSource] = element;
|
|
652
|
-
const rawSource = originalSource.source().toString();
|
|
653
|
-
const cacheKey = file;
|
|
654
|
-
const hashKey = `${file}:asset`;
|
|
655
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
656
|
-
const chunkHash = assetHashByChunk.get(file);
|
|
657
|
-
tasks.push(require_hmr_timing.processCachedTask({
|
|
658
|
-
cache: compilerOptions.cache,
|
|
659
|
-
cacheKey,
|
|
660
|
-
hashKey,
|
|
661
|
-
rawSource,
|
|
662
|
-
hash: chunkHash,
|
|
663
|
-
applyResult(source, { cacheHit }) {
|
|
664
|
-
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
665
|
-
},
|
|
666
|
-
onCacheHit() {
|
|
667
|
-
debug("html cache hit: %s", file);
|
|
668
|
-
},
|
|
669
|
-
transform: async () => {
|
|
670
|
-
const source = new ConcatSource(await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions));
|
|
671
|
-
debug("html handle: %s", file);
|
|
672
|
-
return { result: source };
|
|
673
|
-
}
|
|
674
|
-
}));
|
|
675
|
-
}
|
|
676
|
-
const jsTaskFactories = [];
|
|
677
|
-
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
678
|
-
const cacheKey = getCacheKey(file);
|
|
679
|
-
const asset = compilation.getAsset(file);
|
|
680
|
-
if (!asset) continue;
|
|
681
|
-
const hashKey = `${file}:asset`;
|
|
682
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
683
|
-
const absoluteFile = require_bundle_state.toAbsoluteOutputPath(file, outputDir);
|
|
684
|
-
const initialSource = asset.source.source();
|
|
685
|
-
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
686
|
-
const chunkHash = assetHashByChunk.get(file);
|
|
687
|
-
jsTaskFactories.push(async () => {
|
|
688
|
-
await require_hmr_timing.processCachedTask({
|
|
689
|
-
cache: compilerOptions.cache,
|
|
690
|
-
cacheKey,
|
|
691
|
-
hashKey,
|
|
692
|
-
rawSource: initialRawSource,
|
|
693
|
-
hash: chunkHash,
|
|
694
|
-
applyResult(source, { cacheHit }) {
|
|
695
|
-
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
696
|
-
},
|
|
697
|
-
onCacheHit() {
|
|
698
|
-
debug("js cache hit: %s", file);
|
|
699
|
-
},
|
|
700
|
-
transform: async () => {
|
|
701
|
-
const currentSourceValue = compilation.getAsset(file)?.source.source();
|
|
702
|
-
const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
|
|
703
|
-
const handlerOptions = {
|
|
704
|
-
tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
|
|
705
|
-
filename: absoluteFile,
|
|
706
|
-
moduleGraph: moduleGraphOptions,
|
|
707
|
-
babelParserOptions: { sourceFilename: absoluteFile }
|
|
708
|
-
};
|
|
709
|
-
if (require_precheck.shouldSkipJsTransform(currentSource, {
|
|
710
|
-
...handlerOptions,
|
|
711
|
-
classNameSet: runtimeSet
|
|
712
|
-
})) return { result: new ConcatSource(currentSource) };
|
|
713
|
-
const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
|
|
714
|
-
const source = new ConcatSource(code);
|
|
715
|
-
debug("js handle: %s", file);
|
|
716
|
-
applyLinkedResults(linked);
|
|
717
|
-
return { result: source };
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
|
|
723
|
-
const [file, originalSource] = element;
|
|
724
|
-
const rawSource = originalSource.source().toString();
|
|
725
|
-
if (isWebpackProcessedCssAsset?.(file, rawSource)) {
|
|
726
|
-
const nextCss = finalizeCssAssetSource(rawSource, { generatedCss: require_bundle_state.hasBundlerGeneratedCssMarker(rawSource) });
|
|
727
|
-
const hashKey = `${file}:asset`;
|
|
728
|
-
rememberProcessCacheKey(file, hashKey);
|
|
729
|
-
tasks.push(require_hmr_timing.processCachedTask({
|
|
730
|
-
cache: compilerOptions.cache,
|
|
731
|
-
cacheKey: file,
|
|
732
|
-
hashKey,
|
|
733
|
-
rawSource,
|
|
734
|
-
hash: createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), `${runtimeSetHash}:${cssSourceTraceSignature}`),
|
|
735
|
-
applyResult(source, { cacheHit }) {
|
|
736
|
-
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
737
|
-
},
|
|
738
|
-
onCacheHit() {
|
|
739
|
-
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
740
|
-
},
|
|
741
|
-
transform: async () => {
|
|
742
|
-
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
743
|
-
return { result: new ConcatSource(finalizeTracedCss(nextCss)) };
|
|
744
|
-
}
|
|
745
|
-
}));
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
if (isWebGeneratorTarget) continue;
|
|
749
|
-
const cacheKey = file;
|
|
750
|
-
const hashKey = `${file}:asset`;
|
|
751
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
752
|
-
const chunkHash = assetHashByChunk.get(file);
|
|
753
|
-
const cssSourceHash = (() => {
|
|
754
|
-
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
755
|
-
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
756
|
-
return sourceCss === void 0 ? "webpack-css-source:0" : `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}`;
|
|
757
|
-
})();
|
|
758
|
-
const runtimeAwareHash = createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(rawSource), `${runtimeSetHash}:${webpackSourceCandidates?.signature ?? "source-candidates:0"}:${cssSourceTraceSignature}:${cssSourceHash}`);
|
|
759
|
-
tasks.push(require_hmr_timing.processCachedTask({
|
|
760
|
-
cache: compilerOptions.cache,
|
|
761
|
-
cacheKey,
|
|
762
|
-
hashKey,
|
|
763
|
-
rawSource,
|
|
764
|
-
hash: runtimeAwareHash,
|
|
765
|
-
applyResult(source, { cacheHit }) {
|
|
766
|
-
updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
|
|
767
|
-
},
|
|
768
|
-
onCacheHit() {
|
|
769
|
-
debug("css cache hit: %s", file);
|
|
770
|
-
},
|
|
771
|
-
transform: async () => {
|
|
772
|
-
await runtimeState.readyPromise;
|
|
773
|
-
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
774
|
-
const generatorRawSource = resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions);
|
|
775
|
-
if (require_hmr_timing.isPureLocalCssImportWrapper(rawSource)) return { result: new ConcatSource(require_v3_engine.removeTailwindSourceDirectives(require_bundle_state.stripBundlerGeneratedCssMarkers(rawSource), { importFallback: true })) };
|
|
776
|
-
const generated = await require_hmr_timing.generateCssByGenerator({
|
|
777
|
-
opts: compilerOptions,
|
|
778
|
-
runtimeState,
|
|
779
|
-
runtime: runtimeSet,
|
|
780
|
-
rawSource: generatorRawSource,
|
|
781
|
-
file,
|
|
782
|
-
cssHandlerOptions,
|
|
783
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
784
|
-
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
785
|
-
styleHandler: compilerOptions.styleHandler,
|
|
786
|
-
debug
|
|
787
|
-
});
|
|
788
|
-
const source = new ConcatSource(finalizeTracedCss(generated?.css ?? finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false })));
|
|
789
|
-
if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
|
|
790
|
-
else debug("css handle: %s", file);
|
|
791
|
-
return { result: source };
|
|
792
|
-
}
|
|
793
|
-
}));
|
|
794
|
-
}
|
|
795
|
-
require_hmr_timing.pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
796
|
-
await Promise.all(tasks);
|
|
797
|
-
compilerOptions.cache.prune?.({
|
|
798
|
-
cacheKeys: activeProcessCacheKeys,
|
|
799
|
-
hashKeys: activeProcessHashKeys
|
|
800
|
-
});
|
|
801
|
-
const activeCssFiles = new Set(groupedEntries.css?.map(([file]) => file) ?? []);
|
|
802
|
-
pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
|
|
803
|
-
debug("end");
|
|
804
|
-
require_hmr_timing.emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
|
|
805
|
-
activeAssetFiles: entries.length,
|
|
806
|
-
activeCssFiles: activeCssFiles.size,
|
|
807
|
-
activeProcessCacheKeys,
|
|
808
|
-
activeProcessHashKeys,
|
|
809
|
-
cache: compilerOptions.cache,
|
|
810
|
-
cssHandlerOptionsCache,
|
|
811
|
-
cssUserHandlerOptionsCache,
|
|
812
|
-
phase: "processAssets"
|
|
813
|
-
}) });
|
|
814
|
-
compilerOptions.onEnd();
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
//#endregion
|
|
819
|
-
//#region src/bundlers/webpack/loaders/runtime-registry.ts
|
|
820
|
-
const runtimeRegistryHolder = globalThis;
|
|
821
|
-
const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
|
|
822
|
-
function setWebpackLoaderRuntime(key, entry) {
|
|
823
|
-
runtimeRegistry.set(key, entry);
|
|
824
|
-
}
|
|
825
|
-
//#endregion
|
|
826
|
-
//#region src/bundlers/webpack/shared/loader-anchors.ts
|
|
827
|
-
const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
828
|
-
const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
|
|
829
|
-
const MPX_REWRITE_PRECEDENCE_LOADERS = [MPX_STYLE_COMPILER_LOADER, MPX_STRIP_CONDITIONAL_LOADER];
|
|
830
|
-
function createFinder(targets) {
|
|
831
|
-
return (entries) => entries.findIndex((entry) => targets.some((target) => entry?.loader?.includes?.(target)));
|
|
832
|
-
}
|
|
833
|
-
function createPrioritizedFinder(targets) {
|
|
834
|
-
return (entries) => {
|
|
835
|
-
for (const target of targets) {
|
|
836
|
-
const idx = entries.findIndex((entry) => entry?.loader?.includes?.(target));
|
|
837
|
-
if (idx !== -1) return idx;
|
|
838
|
-
}
|
|
839
|
-
return -1;
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
function createLoaderAnchorFinders(appType) {
|
|
843
|
-
if (isMpx(appType)) return {
|
|
844
|
-
findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
|
|
845
|
-
findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
|
|
846
|
-
};
|
|
847
|
-
const fallbackFinder = createFinder(["postcss-loader"]);
|
|
848
|
-
return {
|
|
849
|
-
findRewriteAnchor: fallbackFinder,
|
|
850
|
-
findClassSetAnchor: fallbackFinder
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
//#endregion
|
|
854
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
855
|
-
function setupWebpackV5Loaders(options) {
|
|
856
|
-
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, registerWebpackCssSourceFile, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
857
|
-
const isMpxApp = isMpx(appType);
|
|
858
|
-
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
859
|
-
const runtimeClassSetLoader = runtimeLoaderPath ?? node_path.default.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
860
|
-
const shouldInjectRuntimeClassSetLoader = compilerOptions.generator?.target !== "web";
|
|
861
|
-
const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? node_path.default.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
862
|
-
const runtimeClassSetLoaderExists = node_fs.default.existsSync(runtimeClassSetLoader);
|
|
863
|
-
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? node_fs.default.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
864
|
-
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
865
|
-
pkgDir: weappTailwindcssPackageDir,
|
|
866
|
-
compilerOptions,
|
|
867
|
-
runtimeState,
|
|
868
|
-
...appType === void 0 ? {} : { appType },
|
|
869
|
-
...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
|
|
870
|
-
getRuntimeSet: getRuntimeSetInLoader,
|
|
871
|
-
...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource }
|
|
872
|
-
} : void 0;
|
|
873
|
-
setWebpackLoaderRuntime(runtimeRegistryKey, {
|
|
874
|
-
classSet: {
|
|
875
|
-
getClassSet: getClassSetInLoader,
|
|
876
|
-
getWatchDependencies: getRuntimeWatchDependencies,
|
|
877
|
-
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
|
|
878
|
-
},
|
|
879
|
-
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
880
|
-
});
|
|
881
|
-
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
882
|
-
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
883
|
-
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
884
|
-
const createRuntimeClassSetLoaderEntry = () => ({
|
|
885
|
-
loader: runtimeClassSetLoader,
|
|
886
|
-
options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
|
|
887
|
-
ident: null,
|
|
888
|
-
type: null
|
|
889
|
-
});
|
|
890
|
-
const createCssImportRewriteLoaderEntry = () => {
|
|
891
|
-
if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
|
|
892
|
-
return {
|
|
893
|
-
loader: runtimeCssImportRewriteLoader,
|
|
894
|
-
options: cssImportRewriteLoaderOptions,
|
|
895
|
-
ident: null,
|
|
896
|
-
type: null
|
|
897
|
-
};
|
|
898
|
-
};
|
|
899
|
-
const { NormalModule } = compiler.webpack;
|
|
900
|
-
compiler.hooks.compilation.tap(require_precheck.pluginName, (compilation) => {
|
|
901
|
-
NormalModule.getCompilationHooks(compilation).loader.tap(require_precheck.pluginName, (_loaderContext, module) => {
|
|
902
|
-
if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
|
|
903
|
-
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
|
|
904
|
-
const loaderEntries = module.loaders || [];
|
|
905
|
-
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
906
|
-
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
907
|
-
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
908
|
-
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), {
|
|
909
|
-
rewriteAnchorIdx,
|
|
910
|
-
classSetAnchorIdx
|
|
911
|
-
});
|
|
912
|
-
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), {
|
|
913
|
-
rewriteAnchorIdx,
|
|
914
|
-
classSetAnchorIdx
|
|
915
|
-
});
|
|
916
|
-
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), {
|
|
917
|
-
rewriteAnchorIdx,
|
|
918
|
-
classSetAnchorIdx
|
|
919
|
-
});
|
|
920
|
-
if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
|
|
921
|
-
const anchorlessInsert = (entry, position) => {
|
|
922
|
-
if (position === "after") loaderEntries.push(entry);
|
|
923
|
-
else loaderEntries.unshift(entry);
|
|
924
|
-
};
|
|
925
|
-
if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
|
|
926
|
-
const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
|
|
927
|
-
const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
|
|
928
|
-
if (rewriteLoaderEntry) {
|
|
929
|
-
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
930
|
-
if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
|
|
931
|
-
else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
|
|
932
|
-
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
if (shouldInjectRuntimeClassSetLoader && runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
936
|
-
const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
|
|
937
|
-
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
938
|
-
if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
|
|
939
|
-
else {
|
|
940
|
-
const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
|
|
941
|
-
loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
//#endregion
|
|
948
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
949
|
-
const debug = require_v3_engine.createDebug();
|
|
950
|
-
const weappTailwindcssPackageDir = require_bundle_state.resolvePackageDir("weapp-tailwindcss");
|
|
951
|
-
const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
|
|
952
|
-
function normalizeIgnoredList(ignored) {
|
|
953
|
-
return (Array.isArray(ignored) ? [...ignored] : [ignored]).filter((item) => typeof item === "string" || item instanceof RegExp || typeof item === "function");
|
|
954
|
-
}
|
|
955
|
-
function createOutputIgnoredPredicate(ignoredList, ignoredPath) {
|
|
956
|
-
const predicate = (file) => {
|
|
957
|
-
const resolvedFile = node_path.default.resolve(file);
|
|
958
|
-
if (resolvedFile === ignoredPath || resolvedFile.startsWith(`${ignoredPath}${node_path.default.sep}`)) return true;
|
|
959
|
-
const normalizedFile = file.replace(/\\/g, "/");
|
|
960
|
-
return ignoredList.some((item) => {
|
|
961
|
-
if (typeof item === "string") {
|
|
962
|
-
const resolvedItem = node_path.default.resolve(item);
|
|
963
|
-
if (resolvedFile === resolvedItem || resolvedFile.startsWith(`${resolvedItem}${node_path.default.sep}`)) return true;
|
|
964
|
-
return micromatch.default.isMatch(normalizedFile, item);
|
|
965
|
-
}
|
|
966
|
-
if (item instanceof RegExp) return item.test(normalizedFile);
|
|
967
|
-
return item(file);
|
|
968
|
-
});
|
|
969
|
-
};
|
|
970
|
-
predicate[outputIgnoredPredicatePath] = ignoredPath;
|
|
971
|
-
return predicate;
|
|
972
|
-
}
|
|
973
|
-
function appendIgnoredPath(ignored, ignoredPath) {
|
|
974
|
-
if (typeof ignored === "function" && ignored[outputIgnoredPredicatePath] === ignoredPath) return ignored;
|
|
975
|
-
const ignoredList = normalizeIgnoredList(ignored);
|
|
976
|
-
if (ignoredList.some((item) => typeof item !== "string")) return createOutputIgnoredPredicate(ignoredList, ignoredPath);
|
|
977
|
-
if (ignoredList.some((item) => typeof item === "string" && node_path.default.resolve(item) === ignoredPath)) return ignored;
|
|
978
|
-
return [...ignoredList, ignoredPath];
|
|
979
|
-
}
|
|
980
|
-
function setupWebpackWatchOutputIgnore(compiler) {
|
|
981
|
-
const appendOutputIgnoredPath = (watchOptions) => {
|
|
982
|
-
const outputPath = compiler.outputPath || compiler.options?.output?.path;
|
|
983
|
-
const outputDir = outputPath ? node_path.default.resolve(outputPath) : void 0;
|
|
984
|
-
if (!outputDir) return watchOptions;
|
|
985
|
-
if (watchOptions && typeof watchOptions === "object") {
|
|
986
|
-
const nextIgnored = appendIgnoredPath(watchOptions.ignored, outputDir);
|
|
987
|
-
if (nextIgnored === void 0) delete watchOptions.ignored;
|
|
988
|
-
else watchOptions.ignored = nextIgnored;
|
|
989
|
-
return watchOptions;
|
|
990
|
-
}
|
|
991
|
-
return { ignored: appendIgnoredPath(void 0, outputDir) };
|
|
992
|
-
};
|
|
993
|
-
const compilerWatchOptions = appendOutputIgnoredPath(compiler.options.watchOptions);
|
|
994
|
-
if (compilerWatchOptions) compiler.options.watchOptions = compilerWatchOptions;
|
|
995
|
-
const syncOutputIgnoredPath = () => {
|
|
996
|
-
const outputPath = compiler.outputPath || compiler.options?.output?.path;
|
|
997
|
-
if (!(outputPath ? node_path.default.resolve(outputPath) : void 0)) return;
|
|
998
|
-
const watchOptions = compiler.watching?.watchOptions;
|
|
999
|
-
if (watchOptions) appendOutputIgnoredPath(watchOptions);
|
|
1000
|
-
};
|
|
1001
|
-
compiler.hooks.watchRun?.tap(require_precheck.pluginName, syncOutputIgnoredPath);
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* @name WeappTailwindcss
|
|
1005
|
-
* @description webpack5 核心转义插件
|
|
1006
|
-
* @link https://tw.icebreaker.top/docs/intro
|
|
1007
|
-
*/
|
|
1008
|
-
var WeappTailwindcss = class {
|
|
1009
|
-
constructor(options = {}) {
|
|
1010
|
-
require_precheck._defineProperty(this, "options", void 0);
|
|
1011
|
-
require_precheck._defineProperty(this, "appType", void 0);
|
|
1012
|
-
require_precheck._defineProperty(this, "hasInitialTailwindCssRoots", void 0);
|
|
1013
|
-
this.hasInitialTailwindCssRoots = require_tailwindcss.hasConfiguredTailwindV4CssRoots(options);
|
|
1014
|
-
this.options = require_precheck.getCompilerContext({
|
|
1015
|
-
...options,
|
|
1016
|
-
__internalDeferMissingCssEntriesWarning: true
|
|
1017
|
-
});
|
|
1018
|
-
this.appType = this.options.appType;
|
|
1019
|
-
}
|
|
1020
|
-
apply(compiler) {
|
|
1021
|
-
compiler.options = compiler.options || {};
|
|
1022
|
-
const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
|
|
1023
|
-
const disabledOptions = require_bundle_state.resolvePluginDisabledState(disabled);
|
|
1024
|
-
const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
|
|
1025
|
-
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(this.options.generator);
|
|
1026
|
-
const shouldRewriteCssImports = isTailwindcssV4 || generatorOptions.target === "web";
|
|
1027
|
-
const isMpxApp = isMpx(this.appType);
|
|
1028
|
-
if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
|
|
1029
|
-
if (disabledOptions.plugin) return;
|
|
1030
|
-
setupWebpackWatchOutputIgnore(compiler);
|
|
1031
|
-
const runtimeState = {
|
|
1032
|
-
twPatcher: initialTwPatcher,
|
|
1033
|
-
readyPromise: require_precheck.createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
1034
|
-
refreshTailwindcssPatcher
|
|
1035
|
-
};
|
|
1036
|
-
let runtimeSetPrepared = false;
|
|
1037
|
-
let runtimeSetSignature;
|
|
1038
|
-
let runtimeRefreshRequiredForCompilation = false;
|
|
1039
|
-
let watchRunObserved = false;
|
|
1040
|
-
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
1041
|
-
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
1042
|
-
const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
1043
|
-
const webpackCssSources = /* @__PURE__ */ new Map();
|
|
1044
|
-
let runtimeMetadataPrepared = false;
|
|
1045
|
-
const updateRuntimeWatchDependencies = async () => {
|
|
1046
|
-
runtimeWatchDependencyFiles.clear();
|
|
1047
|
-
runtimeWatchDependencyContexts.clear();
|
|
1048
|
-
const tailwindOptions = require_v3_engine.resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
1049
|
-
if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
|
|
1050
|
-
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
|
|
1051
|
-
for (const source of tailwindOptions?.v4?.cssSources ?? []) {
|
|
1052
|
-
if (source.file) runtimeWatchDependencyFiles.add(source.file);
|
|
1053
|
-
for (const dependency of source.dependencies ?? []) runtimeWatchDependencyFiles.add(dependency);
|
|
1054
|
-
}
|
|
1055
|
-
for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
1056
|
-
if (typeof runtimeState.twPatcher.collectContentTokens !== "function") return;
|
|
1057
|
-
try {
|
|
1058
|
-
const report = await runtimeState.twPatcher.collectContentTokens();
|
|
1059
|
-
for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
|
|
1060
|
-
for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
1061
|
-
} catch (error) {
|
|
1062
|
-
debug("collect runtime watch dependencies failed: %O", error);
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
const ensureRuntimeMetadata = async (force = false) => {
|
|
1066
|
-
if (runtimeMetadataPrepared && !force) return;
|
|
1067
|
-
await updateRuntimeWatchDependencies();
|
|
1068
|
-
runtimeMetadataPrepared = true;
|
|
1069
|
-
};
|
|
1070
|
-
const collectWatchChangedFiles = () => {
|
|
1071
|
-
const compilerLike = compiler;
|
|
1072
|
-
return new Set([...compilerLike.modifiedFiles ?? [], ...compilerLike.removedFiles ?? []]);
|
|
1073
|
-
};
|
|
1074
|
-
const hasRuntimeDependencyChanges = (files) => {
|
|
1075
|
-
for (const file of files) if (isWatchFileInRuntimeDependencies(file, {
|
|
1076
|
-
contexts: runtimeWatchDependencyContexts,
|
|
1077
|
-
files: runtimeWatchDependencyFiles
|
|
1078
|
-
})) return true;
|
|
1079
|
-
return false;
|
|
1080
|
-
};
|
|
1081
|
-
const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
|
|
1082
|
-
if (markWatchRun) watchRunObserved = true;
|
|
1083
|
-
const changedFiles = collectWatchChangedFiles();
|
|
1084
|
-
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges(changedFiles);
|
|
1085
|
-
};
|
|
1086
|
-
const resetRuntimePreparation = () => {
|
|
1087
|
-
runtimeSetPrepared = false;
|
|
1088
|
-
syncRuntimeRefreshRequirement();
|
|
1089
|
-
};
|
|
1090
|
-
const registerAutoCssSource = async (source) => {
|
|
1091
|
-
if ((runtimeState.twPatcher.majorVersion ?? 0) < 4 || !source.file) return;
|
|
1092
|
-
if (!require_tailwindcss.upsertTailwindV4CssSource(this.options, source)) return;
|
|
1093
|
-
runtimeSetPrepared = false;
|
|
1094
|
-
runtimeMetadataPrepared = false;
|
|
1095
|
-
runtimeRefreshRequiredForCompilation = true;
|
|
1096
|
-
await require_precheck.refreshTailwindRuntimeState(runtimeState, {
|
|
1097
|
-
force: true,
|
|
1098
|
-
clearCache: true
|
|
1099
|
-
});
|
|
1100
|
-
debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
|
|
1101
|
-
};
|
|
1102
|
-
const markWebpackProcessedCssSource = (file) => {
|
|
1103
|
-
webpackProcessedCssSourceFiles.add(node_path.default.resolve(file));
|
|
1104
|
-
};
|
|
1105
|
-
const registerWebpackCssSourceFile = (source) => {
|
|
1106
|
-
webpackCssSources.set(node_path.default.resolve(source.file), source.css);
|
|
1107
|
-
};
|
|
1108
|
-
const isWebpackProcessedTailwindEntryAsset = (file) => {
|
|
1109
|
-
if ((runtimeState.twPatcher.majorVersion ?? 0) < 4 || !this.options.mainCssChunkMatcher(file, this.appType) || webpackProcessedCssSourceFiles.size === 0) return false;
|
|
1110
|
-
const tailwindOptions = require_v3_engine.resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
1111
|
-
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (webpackProcessedCssSourceFiles.has(node_path.default.resolve(entry))) return true;
|
|
1112
|
-
for (const source of tailwindOptions?.v4?.cssSources ?? []) if (source.file && webpackProcessedCssSourceFiles.has(node_path.default.resolve(source.file))) return true;
|
|
1113
|
-
return false;
|
|
1114
|
-
};
|
|
1115
|
-
compiler.hooks.invalid?.tap?.(require_precheck.pluginName, (fileName) => {
|
|
1116
|
-
if (!fileName) return;
|
|
1117
|
-
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([node_path.default.resolve(fileName)]);
|
|
1118
|
-
});
|
|
1119
|
-
compiler.hooks.watchRun?.tap?.(require_precheck.pluginName, () => syncRuntimeRefreshRequirement(true));
|
|
1120
|
-
if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(require_precheck.pluginName, resetRuntimePreparation);
|
|
1121
|
-
else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(require_precheck.pluginName, resetRuntimePreparation);
|
|
1122
|
-
async function getClassSetInLoader() {
|
|
1123
|
-
if (runtimeSetPrepared) return;
|
|
1124
|
-
const signature = require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
1125
|
-
const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
|
|
1126
|
-
debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
|
|
1127
|
-
runtimeSetPrepared = true;
|
|
1128
|
-
await require_precheck.ensureRuntimeClassSet(runtimeState, {
|
|
1129
|
-
forceRefresh,
|
|
1130
|
-
forceCollect: forceRefresh || !watchRunObserved,
|
|
1131
|
-
clearCache: forceRefresh,
|
|
1132
|
-
allowEmpty: true
|
|
1133
|
-
});
|
|
1134
|
-
await ensureRuntimeMetadata(forceRefresh);
|
|
1135
|
-
runtimeSetSignature = signature;
|
|
1136
|
-
runtimeRefreshRequiredForCompilation = false;
|
|
1137
|
-
}
|
|
1138
|
-
async function getRuntimeSetInLoader() {
|
|
1139
|
-
await getClassSetInLoader();
|
|
1140
|
-
return require_precheck.ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
|
|
1141
|
-
}
|
|
1142
|
-
onLoad();
|
|
1143
|
-
setupWebpackV5Loaders({
|
|
1144
|
-
compiler,
|
|
1145
|
-
options: this.options,
|
|
1146
|
-
appType: this.appType,
|
|
1147
|
-
weappTailwindcssPackageDir,
|
|
1148
|
-
shouldRewriteCssImports,
|
|
1149
|
-
runtimeLoaderPath,
|
|
1150
|
-
registerAutoCssSource,
|
|
1151
|
-
runtimeState,
|
|
1152
|
-
getClassSetInLoader,
|
|
1153
|
-
getRuntimeSetInLoader,
|
|
1154
|
-
markWebpackProcessedCssSource,
|
|
1155
|
-
registerWebpackCssSourceFile,
|
|
1156
|
-
getRuntimeWatchDependencies() {
|
|
1157
|
-
return {
|
|
1158
|
-
files: runtimeWatchDependencyFiles,
|
|
1159
|
-
contexts: runtimeWatchDependencyContexts
|
|
1160
|
-
};
|
|
1161
|
-
},
|
|
1162
|
-
debug
|
|
1163
|
-
});
|
|
1164
|
-
setupWebpackV5ProcessAssetsHook({
|
|
1165
|
-
compiler,
|
|
1166
|
-
options: this.options,
|
|
1167
|
-
appType: this.appType,
|
|
1168
|
-
runtimeState,
|
|
1169
|
-
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
1170
|
-
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
1171
|
-
isWebpackProcessedCssAsset(file, rawSource) {
|
|
1172
|
-
return webpackProcessedCssSourceFiles.has(node_path.default.resolve(file)) || isWebpackProcessedTailwindEntryAsset(file) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
|
|
1173
|
-
},
|
|
1174
|
-
consumeRuntimeRefreshRequirement() {
|
|
1175
|
-
runtimeRefreshRequiredForCompilation = false;
|
|
1176
|
-
},
|
|
1177
|
-
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
1178
|
-
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
1179
|
-
getWebpackCssSources: () => webpackCssSources,
|
|
1180
|
-
debug
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
|
-
//#endregion
|
|
1185
|
-
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
1186
|
-
enumerable: true,
|
|
1187
|
-
get: function() {
|
|
1188
|
-
return WeappTailwindcss;
|
|
1189
|
-
}
|
|
1190
|
-
});
|
|
1191
|
-
Object.defineProperty(exports, "weappTailwindcssPackageDir", {
|
|
1192
|
-
enumerable: true,
|
|
1193
|
-
get: function() {
|
|
1194
|
-
return weappTailwindcssPackageDir;
|
|
1195
|
-
}
|
|
1196
|
-
});
|