weapp-tailwindcss 4.12.0 → 5.0.0-next.10
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 +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/babel/index.d.ts +3 -0
- package/dist/bundle-state-BWqi5ZyX.mjs +343 -0
- package/dist/bundle-state-EUbcdKqo.js +410 -0
- package/dist/bundlers/gulp/index.d.ts +7 -0
- package/dist/bundlers/shared/cache.d.ts +16 -0
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
- package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +3 -0
- package/dist/bundlers/shared/css-imports.d.ts +8 -0
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +13 -0
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
- package/dist/bundlers/shared/generator-css.d.ts +33 -0
- package/dist/bundlers/shared/module-graph.d.ts +5 -0
- package/dist/bundlers/shared/run-tasks.d.ts +2 -0
- package/dist/bundlers/vite/bundle-entries.d.ts +14 -0
- package/dist/bundlers/vite/bundle-state.d.ts +43 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +22 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
- package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +34 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +21 -0
- package/dist/bundlers/vite/index.d.ts +3 -0
- package/dist/bundlers/vite/js-precheck.d.ts +1 -0
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/query.d.ts +15 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +2 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +13 -0
- package/dist/bundlers/vite/runtime-affecting-signature.d.ts +2 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
- package/dist/bundlers/vite/source-candidates.d.ts +18 -0
- package/dist/bundlers/vite/source-scan.d.ts +8 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/vite/utils.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +21 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +20 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +20 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +10 -0
- package/dist/bundlers/webpack/index.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +14 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +11 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +8 -0
- package/dist/cache/index.d.ts +38 -0
- package/dist/cache/md5.d.ts +1 -0
- package/dist/cache-BVAiJV3J.js +502 -0
- package/dist/cache-CHs4DXui.mjs +434 -0
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/cli/context.d.ts +13 -0
- package/dist/cli/doctor/constants.d.ts +7 -0
- package/dist/cli/doctor/types.d.ts +31 -0
- package/dist/cli/doctor.d.ts +4 -0
- package/dist/cli/helpers/options/format.d.ts +2 -0
- package/dist/cli/helpers/options/parse.d.ts +3 -0
- package/dist/cli/helpers/options/resolve.d.ts +1 -0
- package/dist/cli/helpers/options.d.ts +3 -0
- package/dist/cli/helpers.d.ts +4 -0
- package/dist/cli/mount-options.d.ts +4 -0
- package/dist/cli/types.d.ts +15 -0
- package/dist/cli/vscode-entry.d.ts +14 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +1985 -3574
- package/dist/cli.mjs +1962 -3554
- package/dist/constants-BG12WAKw.mjs +44 -0
- package/dist/constants-BeeyfJ9k.js +73 -0
- package/dist/constants.d.ts +12 -0
- package/dist/context/compiler-context-cache.d.ts +3 -0
- package/dist/context/custom-attributes.d.ts +2 -0
- package/dist/context/handlers.d.ts +6 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/logger.d.ts +4 -0
- package/dist/context/tailwindcss/basedir.d.ts +1 -0
- package/dist/context/tailwindcss/rax.d.ts +2 -0
- package/dist/context/tailwindcss.d.ts +4 -0
- package/dist/context/workspace.d.ts +3 -0
- package/dist/core.d.ts +5 -21
- package/dist/core.js +131 -180
- package/dist/core.mjs +129 -180
- package/dist/css-macro/constants.d.ts +14 -0
- package/dist/css-macro/index.d.ts +15 -0
- package/dist/css-macro/postcss.d.ts +3 -7
- package/dist/css-macro/postcss.js +44 -58
- package/dist/css-macro/postcss.mjs +44 -56
- package/dist/css-macro.d.ts +2 -20
- package/dist/css-macro.js +37 -50
- package/dist/css-macro.mjs +33 -47
- package/dist/debug/index.d.ts +5 -0
- package/dist/defaults.d.ts +16 -11
- package/dist/defaults.js +151 -8
- package/dist/defaults.mjs +143 -7
- package/dist/escape.js +31 -54
- package/dist/escape.mjs +18 -25
- package/dist/generator/index.d.ts +11 -0
- package/dist/generator/options.d.ts +16 -0
- package/dist/generator/types.d.ts +20 -0
- package/dist/generator-DKkhJbOg.js +1531 -0
- package/dist/generator-UBmfduYg.mjs +1432 -0
- package/dist/generator.d.ts +1 -0
- package/dist/generator.js +19 -0
- package/dist/generator.mjs +2 -0
- package/dist/gulp.d.ts +4 -24
- package/dist/gulp.js +370 -13
- package/dist/gulp.mjs +362 -13
- package/dist/incremental-runtime-class-set-BYmzQ-_f.js +1555 -0
- package/dist/incremental-runtime-class-set-BgMW6wf2.mjs +1510 -0
- package/dist/index.d.ts +8 -15
- package/dist/index.js +12 -24
- package/dist/index.mjs +6 -24
- package/dist/js/JsTokenUpdater.d.ts +14 -0
- package/dist/js/ModuleGraph.d.ts +18 -0
- package/dist/js/NodePathWalker.d.ts +33 -0
- package/dist/js/babel/parse.d.ts +9 -0
- package/dist/js/babel/process.d.ts +4 -0
- package/dist/js/babel.d.ts +13 -0
- package/dist/js/class-context.d.ts +3 -0
- package/dist/js/evalTransforms.d.ts +7 -0
- package/dist/js/handlers.d.ts +5 -0
- package/dist/js/index.d.ts +5 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/js/module-graph/ignored-exports.d.ts +18 -0
- package/dist/js/module-graph/types.d.ts +17 -0
- package/dist/js/node-path-walker/export-handlers.d.ts +12 -0
- package/dist/js/node-path-walker/import-tokens.d.ts +24 -0
- package/dist/js/precheck.d.ts +2 -0
- package/dist/js/sourceAnalysis.d.ts +17 -0
- package/dist/js/taggedTemplateIgnore.d.ts +13 -0
- package/dist/js/types.d.ts +11 -0
- package/dist/lightningcss/index.d.ts +8 -0
- package/dist/lightningcss/style-handler/options.d.ts +3 -0
- package/dist/lightningcss/style-handler/selector-transform.d.ts +10 -0
- package/dist/lightningcss/style-handler/selector-utils.d.ts +10 -0
- package/dist/lightningcss/style-handler.d.ts +17 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger-CZUxvJJD.mjs +2 -0
- package/dist/logger-EVNB9z7i.js +1 -0
- package/dist/postcss/config-directive.d.ts +1 -0
- package/dist/postcss/context.d.ts +9 -0
- package/dist/postcss/source-files.d.ts +8 -0
- package/dist/postcss/tailwind-version.d.ts +3 -0
- package/dist/postcss-C7efq3hr.mjs +231 -0
- package/dist/postcss-Dg-_lyHS.js +240 -0
- package/dist/postcss-html-transform.d.ts +3 -3
- package/dist/postcss-html-transform.js +7 -10
- package/dist/postcss-html-transform.mjs +3 -6
- package/dist/postcss.d.ts +15 -0
- package/dist/postcss.js +7 -0
- package/dist/postcss.mjs +2 -0
- package/dist/precheck-B32p-gLI.js +2736 -0
- package/dist/precheck-B4RH6ZNN.mjs +2622 -0
- package/dist/presets/hbuilderx.d.ts +4 -0
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/shared.d.ts +10 -0
- package/dist/presets/taro.d.ts +4 -0
- package/dist/presets/uni-app-x.d.ts +16 -0
- package/dist/presets/uni-app.d.ts +4 -0
- package/dist/presets.d.ts +1 -76
- package/dist/presets.js +117 -163
- package/dist/presets.mjs +109 -163
- package/dist/reset/index.d.ts +2 -0
- package/dist/reset.d.ts +2 -4
- package/dist/reset.js +19 -8
- package/dist/reset.mjs +2 -8
- package/dist/runtime-patch-CwN5ya72.mjs +71 -0
- package/dist/runtime-patch-D6mBo_KB.js +85 -0
- package/dist/shared/classname-transform.d.ts +14 -0
- package/dist/shared/mpx.d.ts +7 -0
- package/dist/shared/tailwindcss-css-redirect.d.ts +1 -0
- package/dist/source-scan-BaYvNx-k.js +293 -0
- package/dist/source-scan-cGZxoJqP.mjs +254 -0
- package/dist/tailwindcss/index.d.ts +11 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -0
- package/dist/tailwindcss/patcher-options.d.ts +8 -0
- package/dist/tailwindcss/patcher-resolve.d.ts +4 -0
- package/dist/tailwindcss/patcher.d.ts +12 -0
- package/dist/tailwindcss/remove-unsupported-css.d.ts +2 -0
- package/dist/tailwindcss/runtime/cache.d.ts +11 -0
- package/dist/tailwindcss/runtime-logs.d.ts +3 -0
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +28 -0
- package/dist/tailwindcss/source-scan.d.ts +25 -0
- package/dist/tailwindcss/targets.d.ts +2 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/source.d.ts +5 -0
- package/dist/tailwindcss/v3-engine/types.d.ts +55 -0
- package/dist/tailwindcss/v4/config.d.ts +5 -0
- package/dist/tailwindcss/v4/css-entries.d.ts +7 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/index.d.ts +2 -0
- package/dist/tailwindcss/v4/multi-patcher.d.ts +2 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +2 -0
- package/dist/tailwindcss/v4/patcher.d.ts +15 -0
- package/dist/tailwindcss/v4-engine/candidates.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +7 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v4-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +19 -0
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/tailwindcss-Bu-RWIHx.js +630 -0
- package/dist/tailwindcss-C5IgPlQ0.mjs +579 -0
- package/dist/typedoc.export.d.ts +3 -0
- package/dist/types/base.d.ts +1 -0
- package/dist/types/index.d.ts +97 -0
- package/dist/types/shared.d.ts +10 -0
- package/dist/types/user-defined-options/general.d.ts +29 -0
- package/dist/types/user-defined-options/important.d.ts +37 -0
- package/dist/types/user-defined-options/index.d.ts +11 -0
- package/dist/types/user-defined-options/lifecycle.d.ts +6 -0
- package/dist/types/user-defined-options/matcher.d.ts +9 -0
- package/dist/types.d.ts +1 -150
- package/dist/types.js +0 -1
- package/dist/types.mjs +1 -1
- package/dist/uni-app-x/component-local-style.d.ts +19 -0
- package/dist/uni-app-x/index.d.ts +2 -0
- package/dist/uni-app-x/options.d.ts +12 -0
- package/dist/uni-app-x/style-isolation.d.ts +2 -0
- package/dist/uni-app-x/transform.d.ts +9 -0
- package/dist/uni-app-x/vite.d.ts +36 -0
- package/dist/utils/decode.d.ts +2 -0
- package/dist/utils/disabled.d.ts +5 -0
- package/dist/utils/hbuilderx.d.ts +5 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/nameMatcher.d.ts +4 -0
- package/dist/utils/resolve-package.d.ts +1 -0
- package/dist/utils/uni-platform.d.ts +11 -0
- package/dist/utils-BiShvil9.js +61 -0
- package/dist/utils-Btw1iOVV.mjs +48 -0
- package/dist/vite-BU74SkOi.mjs +2246 -0
- package/dist/vite-CKjx_5c3.js +2261 -0
- package/dist/vite.d.ts +3 -17
- package/dist/vite.js +4 -14
- package/dist/vite.mjs +2 -14
- package/dist/weapp-tw-css-import-rewrite-loader.js +68 -92
- package/dist/weapp-tw-runtime-classset-loader.js +31 -50
- package/dist/webpack-CAk_ITq7.mjs +713 -0
- package/dist/webpack-damWiYqY.js +723 -0
- package/dist/webpack.d.ts +4 -25
- package/dist/webpack.js +6 -17
- package/dist/webpack.mjs +2 -17
- package/dist/wxml/Tokenizer.d.ts +15 -0
- package/dist/wxml/custom-attributes.d.ts +4 -0
- package/dist/wxml/index.d.ts +2 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/tokenizer/types.d.ts +18 -0
- package/dist/wxml/utils/codegen/legacy-rewriter.d.ts +2 -0
- package/dist/wxml/utils/codegen/legacy-visitor.d.ts +8 -0
- package/dist/wxml/utils/codegen.d.ts +2 -0
- package/dist/wxml/utils/custom-template.d.ts +3 -0
- package/dist/wxml/utils/fragment-helpers.d.ts +6 -0
- package/dist/wxml/utils/fragment-updater.d.ts +4 -0
- package/dist/wxml/utils/template-fragments.d.ts +3 -0
- package/dist/wxml/utils.d.ts +8 -0
- package/dist/wxml/whitespace.d.ts +2 -0
- package/generator-placeholder.css +1 -0
- package/package.json +39 -38
- package/dist/chunk-24AGZQVR.js +0 -183
- package/dist/chunk-3VQKDHGP.mjs +0 -179
- package/dist/chunk-4AFQP74Z.js +0 -24
- package/dist/chunk-57SOQCAU.mjs +0 -582
- package/dist/chunk-5ZYHNDEK.mjs +0 -2439
- package/dist/chunk-76S2EME4.mjs +0 -34
- package/dist/chunk-A5PB4KZT.js +0 -138
- package/dist/chunk-DUHYLR2R.js +0 -276
- package/dist/chunk-DYLQ6UOI.js +0 -71
- package/dist/chunk-E7I5TW5K.js +0 -52
- package/dist/chunk-FS2NOOEB.js +0 -292
- package/dist/chunk-HVNGIKLS.js +0 -3930
- package/dist/chunk-JZQBZHN5.js +0 -579
- package/dist/chunk-KGTVD4EP.mjs +0 -3930
- package/dist/chunk-NNOQDMUP.mjs +0 -10
- package/dist/chunk-OF6MFURR.js +0 -34
- package/dist/chunk-OFB2KBRP.js +0 -2442
- package/dist/chunk-OOHJLO5M.mjs +0 -71
- package/dist/chunk-PCDYXXSK.mjs +0 -1515
- package/dist/chunk-RKISS72P.js +0 -7
- package/dist/chunk-RRQZL7FQ.mjs +0 -292
- package/dist/chunk-XAKAD2CR.mjs +0 -138
- package/dist/chunk-XZP3MREK.mjs +0 -276
- package/dist/chunk-ZAA5ZG3D.js +0 -1518
- package/dist/chunk-ZCH4YINE.mjs +0 -52
- package/dist/cli.d.mts +0 -2
- package/dist/core.d.mts +0 -26
- package/dist/css-macro/postcss.d.mts +0 -7
- package/dist/css-macro.d.mts +0 -18
- package/dist/defaults.d.mts +0 -11
- package/dist/gulp.d.mts +0 -24
- package/dist/index-BXrmQelt.d.mts +0 -672
- package/dist/index-BXrmQelt.d.ts +0 -672
- package/dist/index.d.mts +0 -15
- package/dist/postcss-html-transform.d.mts +0 -2
- package/dist/presets.d.mts +0 -76
- package/dist/reset.d.mts +0 -1
- package/dist/types.d.mts +0 -150
- package/dist/vite.d.mts +0 -17
- package/dist/webpack.d.mts +0 -25
- package/dist/webpack4.d.mts +0 -26
- package/dist/webpack4.d.ts +0 -26
- package/dist/webpack4.js +0 -493
- package/dist/webpack4.mjs +0 -495
- package/scripts/postinstall.mjs +0 -59
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
import { c as resolveTailwindcssOptions, n as getRuntimeClassSetSignature } from "./cache-CHs4DXui.mjs";
|
|
2
|
+
import { n as createDebug } from "./runtime-patch-CwN5ya72.mjs";
|
|
3
|
+
import { i as processCachedTask, n as generateCssByGenerator, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-BgMW6wf2.mjs";
|
|
4
|
+
import { _ as ensureRuntimeClassSet, f as pluginName, g as createTailwindRuntimeReadyPromise, n as getCompilerContext, s as _defineProperty, t as shouldSkipJsTransform, v as refreshTailwindRuntimeState } from "./precheck-B4RH6ZNN.mjs";
|
|
5
|
+
import { r as getGroupedEntries } from "./utils-Btw1iOVV.mjs";
|
|
6
|
+
import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C5IgPlQ0.mjs";
|
|
7
|
+
import { c as resolvePluginDisabledState, d as toAbsoluteOutputPath, n as createBundleBuildState, o as pushConcurrentTaskFactories, r as updateBundleBuildState, s as resolvePackageDir, t as buildBundleSnapshot, u as resolveOutputSpecifier } from "./bundle-state-BWqi5ZyX.mjs";
|
|
8
|
+
import Module, { createRequire } from "node:module";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
//#region src/shared/tailwindcss-css-redirect.ts
|
|
14
|
+
const moduleWithMutableResolve = Module;
|
|
15
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
16
|
+
function installTailwindcssCssRedirect(pkgDir) {
|
|
17
|
+
const target = path.join(pkgDir, "index.css");
|
|
18
|
+
const original = moduleWithMutableResolve._resolveFilename;
|
|
19
|
+
if (patched.has(original)) return;
|
|
20
|
+
const replacements = new Set(["tailwindcss", "tailwindcss$"]);
|
|
21
|
+
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
22
|
+
if (replacements.has(request)) return target;
|
|
23
|
+
if (request.startsWith("tailwindcss/")) return path.join(pkgDir, request.slice(12));
|
|
24
|
+
return original(request, parent, isMain, options);
|
|
25
|
+
};
|
|
26
|
+
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
27
|
+
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/shared/mpx.ts
|
|
31
|
+
const localRequire = createRequire(import.meta.url);
|
|
32
|
+
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
33
|
+
function isMpxStyleResourceQuery(query) {
|
|
34
|
+
if (typeof query !== "string") return false;
|
|
35
|
+
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
36
|
+
}
|
|
37
|
+
function isMpx(appType) {
|
|
38
|
+
return appType === "mpx";
|
|
39
|
+
}
|
|
40
|
+
function getTailwindcssCssEntry(pkgDir) {
|
|
41
|
+
return path.join(pkgDir, "index.css");
|
|
42
|
+
}
|
|
43
|
+
function resolveMpxWebpackPluginDir(compiler) {
|
|
44
|
+
const candidates = [
|
|
45
|
+
compiler?.context,
|
|
46
|
+
compiler?.options?.context,
|
|
47
|
+
process.cwd()
|
|
48
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
49
|
+
for (const candidate of candidates) try {
|
|
50
|
+
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
51
|
+
return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
52
|
+
} catch {}
|
|
53
|
+
return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
54
|
+
}
|
|
55
|
+
function isMpxWebpackPluginRequest(request) {
|
|
56
|
+
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
57
|
+
}
|
|
58
|
+
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
59
|
+
if (Array.isArray(alias)) alias.push({
|
|
60
|
+
name: /^@mpxjs\/webpack-plugin\//,
|
|
61
|
+
alias: pkgDir
|
|
62
|
+
});
|
|
63
|
+
else {
|
|
64
|
+
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
65
|
+
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
69
|
+
compiler.options.resolveLoader = compiler.options.resolveLoader || {};
|
|
70
|
+
const alias = compiler.options.resolveLoader.alias ?? {};
|
|
71
|
+
compiler.options.resolveLoader.alias = alias;
|
|
72
|
+
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
73
|
+
}
|
|
74
|
+
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
75
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
76
|
+
compiler.options = compiler.options || {};
|
|
77
|
+
compiler.options.resolve = compiler.options.resolve || {};
|
|
78
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
79
|
+
ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
80
|
+
const alias = compiler.options.resolve.alias ?? {};
|
|
81
|
+
compiler.options.resolve.alias = alias;
|
|
82
|
+
if (Array.isArray(alias)) alias.push({
|
|
83
|
+
name: /^@mpxjs\/webpack-plugin\//,
|
|
84
|
+
alias: mpxWebpackPluginDir
|
|
85
|
+
}, {
|
|
86
|
+
name: "tailwindcss",
|
|
87
|
+
alias: tailwindcssCssEntry
|
|
88
|
+
}, {
|
|
89
|
+
name: "tailwindcss$",
|
|
90
|
+
alias: tailwindcssCssEntry
|
|
91
|
+
});
|
|
92
|
+
else {
|
|
93
|
+
alias["@mpxjs/webpack-plugin"] = mpxWebpackPluginDir;
|
|
94
|
+
alias["@mpxjs/webpack-plugin$"] = mpxWebpackPluginDir;
|
|
95
|
+
alias.tailwindcss = tailwindcssCssEntry;
|
|
96
|
+
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
97
|
+
}
|
|
98
|
+
return tailwindcssCssEntry;
|
|
99
|
+
}
|
|
100
|
+
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
101
|
+
if (!enabled || typeof loaderContext.resolve !== "function") return;
|
|
102
|
+
const originalResolve = loaderContext.resolve;
|
|
103
|
+
if (originalResolve.__weappTwPatched) return;
|
|
104
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
105
|
+
const wrappedResolve = function(context, request, callback) {
|
|
106
|
+
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
107
|
+
if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
|
|
108
|
+
if (isMpxWebpackPluginRequest(request)) return originalResolve.call(this, process.cwd(), request, callback);
|
|
109
|
+
return originalResolve.call(this, context, request, callback);
|
|
110
|
+
};
|
|
111
|
+
wrappedResolve.__weappTwPatched = true;
|
|
112
|
+
loaderContext.resolve = wrappedResolve;
|
|
113
|
+
}
|
|
114
|
+
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
115
|
+
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
116
|
+
}
|
|
117
|
+
const CSS_EXT_RE = /\.css$/i;
|
|
118
|
+
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
119
|
+
var _compiler$options;
|
|
120
|
+
if (!loader) return;
|
|
121
|
+
const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
|
|
122
|
+
moduleOptions.rules = moduleOptions.rules || [];
|
|
123
|
+
const createRule = (match) => ({
|
|
124
|
+
...match,
|
|
125
|
+
enforce: "pre",
|
|
126
|
+
use: [{
|
|
127
|
+
loader,
|
|
128
|
+
options: loaderOptions
|
|
129
|
+
}]
|
|
130
|
+
});
|
|
131
|
+
moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
|
|
132
|
+
test: CSS_EXT_RE,
|
|
133
|
+
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
|
|
138
|
+
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
|
|
139
|
+
function getCacheKey(filename) {
|
|
140
|
+
return filename;
|
|
141
|
+
}
|
|
142
|
+
function stripResourceQuery(resource) {
|
|
143
|
+
if (typeof resource !== "string") return resource;
|
|
144
|
+
const queryIndex = resource.indexOf("?");
|
|
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;
|
|
149
|
+
}
|
|
150
|
+
function isCssLikeModuleResource(resource, cssMatcher, appType) {
|
|
151
|
+
if (typeof resource !== "string") return false;
|
|
152
|
+
const normalizedResource = stripResourceQuery(resource);
|
|
153
|
+
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
154
|
+
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
function hasLoaderEntry(entries, target) {
|
|
158
|
+
if (!target) return false;
|
|
159
|
+
return entries.some((entry) => entry.loader?.includes?.(target));
|
|
160
|
+
}
|
|
161
|
+
function toChunkFiles(files) {
|
|
162
|
+
if (!files) return [];
|
|
163
|
+
if (Array.isArray(files)) return files;
|
|
164
|
+
return [...files];
|
|
165
|
+
}
|
|
166
|
+
function createAssetHashByChunkMap(chunks) {
|
|
167
|
+
const partsByFile = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const chunk of chunks) {
|
|
169
|
+
const hash = typeof chunk.hash === "string" ? chunk.hash : void 0;
|
|
170
|
+
if (!hash) continue;
|
|
171
|
+
const chunkId = String(chunk.id ?? chunk.name ?? "");
|
|
172
|
+
for (const file of toChunkFiles(chunk.files)) {
|
|
173
|
+
if (!file) continue;
|
|
174
|
+
let parts = partsByFile.get(file);
|
|
175
|
+
if (!parts) {
|
|
176
|
+
parts = [];
|
|
177
|
+
partsByFile.set(file, parts);
|
|
178
|
+
}
|
|
179
|
+
parts.push(`${chunkId}:${hash}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const hashByFile = /* @__PURE__ */ new Map();
|
|
183
|
+
for (const [file, parts] of partsByFile.entries()) hashByFile.set(file, parts.sort().join("|"));
|
|
184
|
+
return hashByFile;
|
|
185
|
+
}
|
|
186
|
+
function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
|
|
187
|
+
return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
|
|
188
|
+
}
|
|
189
|
+
function hasWatchChanges(compiler) {
|
|
190
|
+
return (compiler.modifiedFiles?.size ?? 0) > 0 || (compiler.removedFiles?.size ?? 0) > 0;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
|
|
194
|
+
function createWebpackSnapshotAssets(assets) {
|
|
195
|
+
return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
|
|
196
|
+
const source = asset.source();
|
|
197
|
+
return [file, {
|
|
198
|
+
fileName: file,
|
|
199
|
+
source: typeof source === "string" ? source : source?.toString() ?? "",
|
|
200
|
+
type: "asset"
|
|
201
|
+
}];
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
function setupWebpackV5ProcessAssetsHook(options) {
|
|
205
|
+
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
|
|
206
|
+
const { Compilation, sources } = compiler.webpack;
|
|
207
|
+
const { ConcatSource } = sources;
|
|
208
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
209
|
+
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
210
|
+
const bundleBuildState = createBundleBuildState();
|
|
211
|
+
const bundleRuntimeClassSetManager = runtimeClassSetManager ?? createBundleRuntimeClassSetManager();
|
|
212
|
+
let webpackWatchRuntimeScanInitialized = false;
|
|
213
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
214
|
+
compilation.hooks.processAssets.tapPromise({
|
|
215
|
+
name: pluginName,
|
|
216
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
217
|
+
}, async (assets) => {
|
|
218
|
+
compilerOptions.onStart();
|
|
219
|
+
debug("start");
|
|
220
|
+
await runtimeState.readyPromise;
|
|
221
|
+
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
222
|
+
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
223
|
+
const entries = Object.entries(assets);
|
|
224
|
+
const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
|
|
225
|
+
const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
|
|
226
|
+
const jsAssets = /* @__PURE__ */ new Map();
|
|
227
|
+
for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
|
|
228
|
+
const absolute = toAbsoluteOutputPath(file, outputDir);
|
|
229
|
+
jsAssets.set(absolute, file);
|
|
230
|
+
}
|
|
231
|
+
const moduleGraphOptions = {
|
|
232
|
+
resolve(specifier, importer) {
|
|
233
|
+
return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
234
|
+
},
|
|
235
|
+
load: (id) => {
|
|
236
|
+
const assetName = jsAssets.get(id);
|
|
237
|
+
if (!assetName) return;
|
|
238
|
+
const asset = compilation.getAsset(assetName);
|
|
239
|
+
if (!asset) return;
|
|
240
|
+
const source = asset.source.source();
|
|
241
|
+
return typeof source === "string" ? source : source.toString();
|
|
242
|
+
},
|
|
243
|
+
filter(id) {
|
|
244
|
+
return jsAssets.has(id);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const applyLinkedResults = (linked) => {
|
|
248
|
+
if (!linked) return;
|
|
249
|
+
for (const [id, { code }] of Object.entries(linked)) {
|
|
250
|
+
const assetName = jsAssets.get(id);
|
|
251
|
+
if (!assetName) continue;
|
|
252
|
+
const asset = compilation.getAsset(assetName);
|
|
253
|
+
if (!asset) continue;
|
|
254
|
+
const previousSource = asset.source.source();
|
|
255
|
+
const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
|
|
256
|
+
if (previous === code) continue;
|
|
257
|
+
const source = new ConcatSource(code);
|
|
258
|
+
compilation.updateAsset(assetName, source);
|
|
259
|
+
compilerOptions.onUpdate(assetName, previous, code);
|
|
260
|
+
debug("js linked handle: %s", assetName);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const groupedEntries = getGroupedEntries(entries, compilerOptions);
|
|
264
|
+
const getCssHandlerOptions = (file) => {
|
|
265
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
266
|
+
const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
|
|
267
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
|
|
268
|
+
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
269
|
+
if (cached) return cached;
|
|
270
|
+
const created = {
|
|
271
|
+
isMainChunk,
|
|
272
|
+
postcssOptions: { options: { from: file } },
|
|
273
|
+
majorVersion
|
|
274
|
+
};
|
|
275
|
+
cssHandlerOptionsCache.set(cacheKey, created);
|
|
276
|
+
return created;
|
|
277
|
+
};
|
|
278
|
+
const getCssUserHandlerOptions = (file) => {
|
|
279
|
+
const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
|
|
280
|
+
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
281
|
+
if (cached) return cached;
|
|
282
|
+
const created = {
|
|
283
|
+
...getCssHandlerOptions(file),
|
|
284
|
+
isMainChunk: false
|
|
285
|
+
};
|
|
286
|
+
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
287
|
+
return created;
|
|
288
|
+
};
|
|
289
|
+
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
290
|
+
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
|
|
291
|
+
let runtimeSet;
|
|
292
|
+
if (isWatchMode?.() === true && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
|
|
293
|
+
const snapshot = buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
|
|
294
|
+
if (!webpackWatchRuntimeScanInitialized) {
|
|
295
|
+
for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
301
|
+
await bundleRuntimeClassSetManager.reset();
|
|
302
|
+
runtimeSet = await ensureRuntimeClassSet(runtimeState, {
|
|
303
|
+
forceRefresh: false,
|
|
304
|
+
forceCollect: true,
|
|
305
|
+
clearCache: false,
|
|
306
|
+
allowEmpty: false
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
|
|
310
|
+
webpackWatchRuntimeScanInitialized = true;
|
|
311
|
+
} else {
|
|
312
|
+
if (forceRuntimeRefresh) {
|
|
313
|
+
await bundleRuntimeClassSetManager.reset();
|
|
314
|
+
webpackWatchRuntimeScanInitialized = false;
|
|
315
|
+
}
|
|
316
|
+
runtimeSet = await ensureRuntimeClassSet(runtimeState, {
|
|
317
|
+
forceRefresh: forceRuntimeRefresh,
|
|
318
|
+
forceCollect: true,
|
|
319
|
+
clearCache: forceRuntimeRefresh,
|
|
320
|
+
allowEmpty: false
|
|
321
|
+
});
|
|
322
|
+
if (runtimeSet.size === 0) {
|
|
323
|
+
const syncSet = runtimeState.twPatcher.getClassSetSync?.();
|
|
324
|
+
if (syncSet && syncSet.size > 0) runtimeSet = syncSet;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
328
|
+
consumeRuntimeRefreshRequirement();
|
|
329
|
+
const runtimeSetHash = compilerOptions.cache.computeHash([getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
|
|
330
|
+
const defaultTemplateHandlerOptions = { runtimeSet };
|
|
331
|
+
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
332
|
+
const tasks = [];
|
|
333
|
+
if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
334
|
+
const [file, originalSource] = element;
|
|
335
|
+
const rawSource = originalSource.source().toString();
|
|
336
|
+
const cacheKey = file;
|
|
337
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
338
|
+
tasks.push(processCachedTask({
|
|
339
|
+
cache: compilerOptions.cache,
|
|
340
|
+
cacheKey,
|
|
341
|
+
hashKey: `${file}:asset`,
|
|
342
|
+
rawSource,
|
|
343
|
+
hash: chunkHash,
|
|
344
|
+
applyResult(source) {
|
|
345
|
+
compilation.updateAsset(file, source);
|
|
346
|
+
},
|
|
347
|
+
onCacheHit() {
|
|
348
|
+
debug("html cache hit: %s", file);
|
|
349
|
+
},
|
|
350
|
+
transform: async () => {
|
|
351
|
+
const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
|
|
352
|
+
const source = new ConcatSource(wxml);
|
|
353
|
+
compilerOptions.onUpdate(file, rawSource, wxml);
|
|
354
|
+
debug("html handle: %s", file);
|
|
355
|
+
return { result: source };
|
|
356
|
+
}
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
359
|
+
const jsTaskFactories = [];
|
|
360
|
+
if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
361
|
+
const cacheKey = getCacheKey(file);
|
|
362
|
+
const asset = compilation.getAsset(file);
|
|
363
|
+
if (!asset) continue;
|
|
364
|
+
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
365
|
+
const initialSource = asset.source.source();
|
|
366
|
+
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
367
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
368
|
+
jsTaskFactories.push(async () => {
|
|
369
|
+
await processCachedTask({
|
|
370
|
+
cache: compilerOptions.cache,
|
|
371
|
+
cacheKey,
|
|
372
|
+
hashKey: `${file}:asset`,
|
|
373
|
+
rawSource: initialRawSource,
|
|
374
|
+
hash: chunkHash,
|
|
375
|
+
applyResult(source) {
|
|
376
|
+
compilation.updateAsset(file, source);
|
|
377
|
+
},
|
|
378
|
+
onCacheHit() {
|
|
379
|
+
debug("js cache hit: %s", file);
|
|
380
|
+
},
|
|
381
|
+
transform: async () => {
|
|
382
|
+
const currentSourceValue = compilation.getAsset(file)?.source.source();
|
|
383
|
+
const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
|
|
384
|
+
const handlerOptions = {
|
|
385
|
+
tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
|
|
386
|
+
filename: absoluteFile,
|
|
387
|
+
moduleGraph: moduleGraphOptions,
|
|
388
|
+
babelParserOptions: { sourceFilename: absoluteFile }
|
|
389
|
+
};
|
|
390
|
+
if (shouldSkipJsTransform(currentSource, {
|
|
391
|
+
...handlerOptions,
|
|
392
|
+
classNameSet: runtimeSet
|
|
393
|
+
})) return { result: new ConcatSource(currentSource) };
|
|
394
|
+
const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
|
|
395
|
+
const source = new ConcatSource(code);
|
|
396
|
+
compilerOptions.onUpdate(file, currentSource, code);
|
|
397
|
+
debug("js handle: %s", file);
|
|
398
|
+
applyLinkedResults(linked);
|
|
399
|
+
return { result: source };
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
|
|
405
|
+
const [file, originalSource] = element;
|
|
406
|
+
const rawSource = originalSource.source().toString();
|
|
407
|
+
const cacheKey = file;
|
|
408
|
+
const runtimeAwareHash = createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash);
|
|
409
|
+
tasks.push(processCachedTask({
|
|
410
|
+
cache: compilerOptions.cache,
|
|
411
|
+
cacheKey,
|
|
412
|
+
hashKey: `${file}:asset`,
|
|
413
|
+
rawSource,
|
|
414
|
+
hash: runtimeAwareHash,
|
|
415
|
+
applyResult(source) {
|
|
416
|
+
compilation.updateAsset(file, source);
|
|
417
|
+
},
|
|
418
|
+
onCacheHit() {
|
|
419
|
+
debug("css cache hit: %s", file);
|
|
420
|
+
},
|
|
421
|
+
transform: async () => {
|
|
422
|
+
await runtimeState.readyPromise;
|
|
423
|
+
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
424
|
+
const generated = await generateCssByGenerator({
|
|
425
|
+
opts: compilerOptions,
|
|
426
|
+
runtimeState,
|
|
427
|
+
runtime: runtimeSet,
|
|
428
|
+
rawSource,
|
|
429
|
+
file,
|
|
430
|
+
cssHandlerOptions,
|
|
431
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
432
|
+
styleHandler: compilerOptions.styleHandler,
|
|
433
|
+
debug
|
|
434
|
+
});
|
|
435
|
+
const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
|
|
436
|
+
const source = new ConcatSource(css);
|
|
437
|
+
compilerOptions.onUpdate(file, rawSource, css);
|
|
438
|
+
if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
|
|
439
|
+
else debug("css handle: %s", file);
|
|
440
|
+
return { result: source };
|
|
441
|
+
}
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
444
|
+
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
445
|
+
await Promise.all(tasks);
|
|
446
|
+
debug("end");
|
|
447
|
+
compilerOptions.onEnd();
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region ../../node_modules/.pnpm/tsdown@0.22.0_tsx@4.21.0_typescript@6.0.3_unrun@0.2.37_synckit@0.11.12__vue-tsc@3.2.9_typescript@6.0.3_/node_modules/tsdown/esm-shims.js
|
|
453
|
+
const getFilename = () => fileURLToPath(import.meta.url);
|
|
454
|
+
const getDirname = () => path.dirname(getFilename());
|
|
455
|
+
const __dirname = /* @__PURE__ */ getDirname();
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/bundlers/webpack/shared/loader-anchors.ts
|
|
458
|
+
const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
459
|
+
const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
|
|
460
|
+
const MPX_REWRITE_PRECEDENCE_LOADERS = [MPX_STYLE_COMPILER_LOADER, MPX_STRIP_CONDITIONAL_LOADER];
|
|
461
|
+
function createFinder(targets) {
|
|
462
|
+
return (entries) => entries.findIndex((entry) => targets.some((target) => entry?.loader?.includes?.(target)));
|
|
463
|
+
}
|
|
464
|
+
function createPrioritizedFinder(targets) {
|
|
465
|
+
return (entries) => {
|
|
466
|
+
for (const target of targets) {
|
|
467
|
+
const idx = entries.findIndex((entry) => entry?.loader?.includes?.(target));
|
|
468
|
+
if (idx !== -1) return idx;
|
|
469
|
+
}
|
|
470
|
+
return -1;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
function createLoaderAnchorFinders(appType) {
|
|
474
|
+
if (isMpx(appType)) return {
|
|
475
|
+
findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
|
|
476
|
+
findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
|
|
477
|
+
};
|
|
478
|
+
const fallbackFinder = createFinder(["postcss-loader"]);
|
|
479
|
+
return {
|
|
480
|
+
findRewriteAnchor: fallbackFinder,
|
|
481
|
+
findClassSetAnchor: fallbackFinder
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
486
|
+
function setupWebpackV5Loaders(options) {
|
|
487
|
+
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, getClassSetInLoader, getRuntimeWatchDependencies, debug } = options;
|
|
488
|
+
const isMpxApp = isMpx(appType);
|
|
489
|
+
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
490
|
+
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
491
|
+
const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
492
|
+
const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
|
|
493
|
+
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
494
|
+
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
495
|
+
pkgDir: weappTailwindcssPackageDir,
|
|
496
|
+
appType,
|
|
497
|
+
registerCssSource: registerAutoCssSource
|
|
498
|
+
} : void 0;
|
|
499
|
+
const classSetLoaderOptions = {
|
|
500
|
+
getClassSet: getClassSetInLoader,
|
|
501
|
+
getWatchDependencies: getRuntimeWatchDependencies
|
|
502
|
+
};
|
|
503
|
+
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
504
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewrite: runtimeLoaderRewriteOptions } : void 0;
|
|
505
|
+
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
506
|
+
const createRuntimeClassSetLoaderEntry = () => ({
|
|
507
|
+
loader: runtimeClassSetLoader,
|
|
508
|
+
options: classSetLoaderOptions,
|
|
509
|
+
ident: null,
|
|
510
|
+
type: null
|
|
511
|
+
});
|
|
512
|
+
const createCssImportRewriteLoaderEntry = () => {
|
|
513
|
+
if (!runtimeCssImportRewriteLoader) return null;
|
|
514
|
+
return {
|
|
515
|
+
loader: runtimeCssImportRewriteLoader,
|
|
516
|
+
options: cssImportRewriteLoaderOptions,
|
|
517
|
+
ident: null,
|
|
518
|
+
type: null
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
const { NormalModule } = compiler.webpack;
|
|
522
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
523
|
+
NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
|
|
524
|
+
if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
|
|
525
|
+
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
|
|
526
|
+
const loaderEntries = module.loaders || [];
|
|
527
|
+
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
528
|
+
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
529
|
+
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
530
|
+
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), {
|
|
531
|
+
rewriteAnchorIdx,
|
|
532
|
+
classSetAnchorIdx
|
|
533
|
+
});
|
|
534
|
+
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), {
|
|
535
|
+
rewriteAnchorIdx,
|
|
536
|
+
classSetAnchorIdx
|
|
537
|
+
});
|
|
538
|
+
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), {
|
|
539
|
+
rewriteAnchorIdx,
|
|
540
|
+
classSetAnchorIdx
|
|
541
|
+
});
|
|
542
|
+
if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
|
|
543
|
+
const anchorlessInsert = (entry, position) => {
|
|
544
|
+
if (position === "after") loaderEntries.push(entry);
|
|
545
|
+
else loaderEntries.unshift(entry);
|
|
546
|
+
};
|
|
547
|
+
if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
|
|
548
|
+
const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
|
|
549
|
+
const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
|
|
550
|
+
if (rewriteLoaderEntry) {
|
|
551
|
+
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
552
|
+
if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
|
|
553
|
+
else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
|
|
554
|
+
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
558
|
+
const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
|
|
559
|
+
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
560
|
+
if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
|
|
561
|
+
else {
|
|
562
|
+
const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
|
|
563
|
+
loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
571
|
+
const debug = createDebug();
|
|
572
|
+
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
573
|
+
/**
|
|
574
|
+
* @name UnifiedWebpackPluginV5
|
|
575
|
+
* @description webpack5 核心转义插件
|
|
576
|
+
* @link https://tw.icebreaker.top/docs/intro
|
|
577
|
+
*/
|
|
578
|
+
var UnifiedWebpackPluginV5 = class {
|
|
579
|
+
constructor(options = {}) {
|
|
580
|
+
_defineProperty(this, "options", void 0);
|
|
581
|
+
_defineProperty(this, "appType", void 0);
|
|
582
|
+
_defineProperty(this, "hasInitialTailwindCssRoots", void 0);
|
|
583
|
+
this.hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
|
|
584
|
+
this.options = getCompilerContext({
|
|
585
|
+
...options,
|
|
586
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
587
|
+
});
|
|
588
|
+
this.appType = this.options.appType;
|
|
589
|
+
}
|
|
590
|
+
apply(compiler) {
|
|
591
|
+
compiler.options = compiler.options || {};
|
|
592
|
+
const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
|
|
593
|
+
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
594
|
+
const shouldRewriteCssImports = (initialTwPatcher.majorVersion ?? 0) >= 4;
|
|
595
|
+
const isMpxApp = isMpx(this.appType);
|
|
596
|
+
if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
|
|
597
|
+
if (disabledOptions.plugin) return;
|
|
598
|
+
const runtimeState = {
|
|
599
|
+
twPatcher: initialTwPatcher,
|
|
600
|
+
readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
601
|
+
refreshTailwindcssPatcher
|
|
602
|
+
};
|
|
603
|
+
let runtimeSetPrepared = false;
|
|
604
|
+
let runtimeSetSignature;
|
|
605
|
+
let runtimeRefreshRequiredForCompilation = false;
|
|
606
|
+
let watchRunObserved = false;
|
|
607
|
+
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
608
|
+
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
609
|
+
let runtimeMetadataPrepared = false;
|
|
610
|
+
const updateRuntimeWatchDependencies = async () => {
|
|
611
|
+
runtimeWatchDependencyFiles.clear();
|
|
612
|
+
runtimeWatchDependencyContexts.clear();
|
|
613
|
+
const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
614
|
+
if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
|
|
615
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
|
|
616
|
+
for (const source of tailwindOptions?.v4?.cssSources ?? []) {
|
|
617
|
+
if (source.file) runtimeWatchDependencyFiles.add(source.file);
|
|
618
|
+
for (const dependency of source.dependencies ?? []) runtimeWatchDependencyFiles.add(dependency);
|
|
619
|
+
}
|
|
620
|
+
for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
621
|
+
if (typeof runtimeState.twPatcher.collectContentTokens !== "function") return;
|
|
622
|
+
try {
|
|
623
|
+
const report = await runtimeState.twPatcher.collectContentTokens();
|
|
624
|
+
for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
|
|
625
|
+
for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
|
|
626
|
+
} catch (error) {
|
|
627
|
+
debug("collect runtime watch dependencies failed: %O", error);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
const ensureRuntimeMetadata = async (force = false) => {
|
|
631
|
+
if (runtimeMetadataPrepared && !force) return;
|
|
632
|
+
await updateRuntimeWatchDependencies();
|
|
633
|
+
runtimeMetadataPrepared = true;
|
|
634
|
+
};
|
|
635
|
+
const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
|
|
636
|
+
if (markWatchRun) watchRunObserved = true;
|
|
637
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasWatchChanges(compiler);
|
|
638
|
+
};
|
|
639
|
+
const resetRuntimePreparation = () => {
|
|
640
|
+
runtimeSetPrepared = false;
|
|
641
|
+
runtimeMetadataPrepared = false;
|
|
642
|
+
syncRuntimeRefreshRequirement();
|
|
643
|
+
};
|
|
644
|
+
const registerAutoCssSource = async (source) => {
|
|
645
|
+
if (this.hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !source.file) return;
|
|
646
|
+
if (!upsertTailwindV4CssSource(this.options, source)) return;
|
|
647
|
+
runtimeSetPrepared = false;
|
|
648
|
+
runtimeMetadataPrepared = false;
|
|
649
|
+
runtimeRefreshRequiredForCompilation = true;
|
|
650
|
+
await refreshTailwindRuntimeState(runtimeState, {
|
|
651
|
+
force: true,
|
|
652
|
+
clearCache: true
|
|
653
|
+
});
|
|
654
|
+
debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
|
|
655
|
+
};
|
|
656
|
+
compiler.hooks.invalid?.tap?.(pluginName, () => {
|
|
657
|
+
runtimeRefreshRequiredForCompilation = true;
|
|
658
|
+
});
|
|
659
|
+
compiler.hooks.watchRun?.tap?.(pluginName, () => syncRuntimeRefreshRequirement(true));
|
|
660
|
+
if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
|
|
661
|
+
else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(pluginName, resetRuntimePreparation);
|
|
662
|
+
async function getClassSetInLoader() {
|
|
663
|
+
if (runtimeSetPrepared) return;
|
|
664
|
+
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
665
|
+
const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
|
|
666
|
+
debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
|
|
667
|
+
runtimeSetPrepared = true;
|
|
668
|
+
await ensureRuntimeClassSet(runtimeState, {
|
|
669
|
+
forceRefresh,
|
|
670
|
+
forceCollect: forceRefresh || !watchRunObserved,
|
|
671
|
+
clearCache: forceRefresh,
|
|
672
|
+
allowEmpty: true
|
|
673
|
+
});
|
|
674
|
+
await ensureRuntimeMetadata(forceRefresh);
|
|
675
|
+
runtimeSetSignature = signature;
|
|
676
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
677
|
+
}
|
|
678
|
+
onLoad();
|
|
679
|
+
setupWebpackV5Loaders({
|
|
680
|
+
compiler,
|
|
681
|
+
options: this.options,
|
|
682
|
+
appType: this.appType,
|
|
683
|
+
weappTailwindcssPackageDir,
|
|
684
|
+
shouldRewriteCssImports,
|
|
685
|
+
runtimeLoaderPath,
|
|
686
|
+
registerAutoCssSource,
|
|
687
|
+
getClassSetInLoader,
|
|
688
|
+
getRuntimeWatchDependencies() {
|
|
689
|
+
return {
|
|
690
|
+
files: runtimeWatchDependencyFiles,
|
|
691
|
+
contexts: runtimeWatchDependencyContexts
|
|
692
|
+
};
|
|
693
|
+
},
|
|
694
|
+
debug
|
|
695
|
+
});
|
|
696
|
+
setupWebpackV5ProcessAssetsHook({
|
|
697
|
+
compiler,
|
|
698
|
+
options: this.options,
|
|
699
|
+
appType: this.appType,
|
|
700
|
+
runtimeState,
|
|
701
|
+
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
702
|
+
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
703
|
+
consumeRuntimeRefreshRequirement() {
|
|
704
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
705
|
+
},
|
|
706
|
+
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
707
|
+
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
708
|
+
debug
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
//#endregion
|
|
713
|
+
export { weappTailwindcssPackageDir as n, UnifiedWebpackPluginV5 as t };
|