weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.7
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/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 +1 -2
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +11 -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 +12 -22
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- 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 +2 -1
- package/dist/bundlers/vite/index.d.ts +1 -1
- 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/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
- package/dist/cache-DPN5yKSX.js +497 -0
- package/dist/cache-nq0_XJoS.mjs +429 -0
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli.js +108 -598
- package/dist/cli.mjs +119 -608
- package/dist/constants.d.ts +1 -2
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.d.ts +1 -0
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +33 -14
- package/dist/defaults.mjs +30 -15
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
- package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
- package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +29 -28
- package/dist/gulp.mjs +25 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/logger-BRy6XPQ2.js +1 -0
- package/dist/logger-Bub1jggA.mjs +2 -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-BtAP6sQO.mjs +288 -0
- package/dist/postcss-WsXlC7A-.js +298 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -276
- package/dist/postcss.mjs +1 -269
- package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
- package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
- package/dist/presets.js +6 -4
- package/dist/presets.mjs +4 -2
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
- package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
- package/dist/runtime-patch-qwuisukL.js +85 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +2 -3
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +2 -1
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
- package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +2 -9
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +0 -2
- package/dist/types/user-defined-options/important.d.ts +3 -3
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
- package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
- package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +23 -35
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/js/syntax.d.ts +0 -10
- package/dist/loader-anchors-1MumTAtA.mjs +0 -205
- package/dist/loader-anchors-TrFvT6g1.js +0 -273
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
- /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
- /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
- /package/dist/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
- /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +0 -0
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { o as
|
|
5
|
-
import {
|
|
6
|
-
import { i as
|
|
7
|
-
import { a as
|
|
1
|
+
import { c as resolveTailwindcssOptions, l as findNearestPackageRoot, n as getRuntimeClassSetSignature, s as findTailwindConfig } from "./cache-nq0_XJoS.mjs";
|
|
2
|
+
import { n as createDebug } from "./runtime-patch-pGdCqAEu.mjs";
|
|
3
|
+
import { d as filterUnsupportedMiniProgramTailwindV4Candidates, f as loadTailwindV4DesignSystem, i as normalizeWeappTailwindcssGeneratorOptions, s as resolveTailwindV4SourceFromPatcher } from "./generator-CzfdCZyd.mjs";
|
|
4
|
+
import { a as analyzeSource, c as isClassContextLiteralPath, d as traverse$1, g as createTailwindRuntimeReadyPromise, h as collectRuntimeClassSet, i as createAttributeMatcher, l as replaceWxml, m as toCustomAttributesEntities, n as getCompilerContext, o as JsTokenUpdater, p as vitePluginName, r as generateCode, s as _defineProperty, t as shouldSkipJsTransform, u as babelParse, v as refreshTailwindRuntimeState } from "./precheck-DlrmwCc-.mjs";
|
|
5
|
+
import { o as resolveUniUtsPlatform } from "./utils-BJjKRQgf.mjs";
|
|
6
|
+
import { i as resolveUniAppXOptions, r as isUniAppXEnabled } from "./tailwindcss-BIJ185GB.mjs";
|
|
7
|
+
import { a as processCachedTask, i as hasTailwindGeneratedCssMarkers, n as validateCandidatesByGenerator, r as hasTailwindSourceDirectives, t as generateCssByGenerator } from "./generator-css-B938WI9a.mjs";
|
|
8
|
+
import { a as resolveOutputSpecifier, i as normalizeOutputPathKey, n as resolvePackageDir, o as toAbsoluteOutputPath, r as resolvePluginDisabledState, t as pushConcurrentTaskFactories } from "./run-tasks-DdNi-hkk.mjs";
|
|
9
|
+
import { t as logger$1 } from "./logger-Bub1jggA.mjs";
|
|
8
10
|
import path from "node:path";
|
|
9
11
|
import process from "node:process";
|
|
12
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
13
|
+
import { cleanUrl as cleanUrl$1, ensurePosix } from "@weapp-tailwindcss/shared";
|
|
10
14
|
import { extractRawCandidatesWithPositions, extractValidCandidates } from "tailwindcss-patch";
|
|
11
|
-
import { Buffer } from "node:buffer";
|
|
12
15
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { Buffer } from "node:buffer";
|
|
13
17
|
import { readFile } from "node:fs/promises";
|
|
14
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
15
|
-
import { cleanUrl as cleanUrl$1, ensurePosix } from "@weapp-tailwindcss/shared";
|
|
16
18
|
import MagicString from "magic-string";
|
|
17
19
|
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
18
20
|
import { Parser } from "htmlparser2";
|
|
19
21
|
import fg from "fast-glob";
|
|
20
22
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
21
|
-
import postcssrc from "postcss-load-config";
|
|
22
23
|
import { NodeTypes } from "@vue/compiler-dom";
|
|
23
24
|
import { parse } from "@vue/compiler-sfc";
|
|
24
25
|
import { parse as parse$1 } from "comment-json";
|
|
26
|
+
import postcssrc from "postcss-load-config";
|
|
25
27
|
//#region src/uni-app-x/component-local-style.ts
|
|
26
28
|
const EXPRESSION_WRAPPER_PREFIX = "(\n";
|
|
27
29
|
const EXPRESSION_WRAPPER_SUFFIX = "\n)";
|
|
@@ -61,8 +63,8 @@ var UniAppXComponentLocalStyleCollector = class {
|
|
|
61
63
|
constructor(fileId, runtimeSet) {
|
|
62
64
|
this.fileId = fileId;
|
|
63
65
|
this.runtimeSet = runtimeSet;
|
|
64
|
-
this
|
|
65
|
-
this
|
|
66
|
+
_defineProperty(this, "aliasByUtility", /* @__PURE__ */ new Map());
|
|
67
|
+
_defineProperty(this, "aliasByLookup", /* @__PURE__ */ new Map());
|
|
66
68
|
}
|
|
67
69
|
ensureAlias(utility) {
|
|
68
70
|
const cached = this.aliasByUtility.get(utility);
|
|
@@ -419,14 +421,14 @@ function createUniAppXPlugins(options) {
|
|
|
419
421
|
const cssPlugins = [{
|
|
420
422
|
name: "weapp-tailwindcss:uni-app-x:css",
|
|
421
423
|
async transform(code, id) {
|
|
422
|
-
await runtimeState.
|
|
424
|
+
await runtimeState.readyPromise;
|
|
423
425
|
return transformStyle(code, id);
|
|
424
426
|
}
|
|
425
427
|
}, {
|
|
426
428
|
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
427
429
|
enforce: "pre",
|
|
428
430
|
async transform(code, id) {
|
|
429
|
-
await runtimeState.
|
|
431
|
+
await runtimeState.readyPromise;
|
|
430
432
|
const { query } = parseVueRequest(id);
|
|
431
433
|
const lang = query.lang;
|
|
432
434
|
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
@@ -504,6 +506,22 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
504
506
|
}
|
|
505
507
|
//#endregion
|
|
506
508
|
//#region src/bundlers/vite/css-finalizer.ts
|
|
509
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
510
|
+
const candidate = error;
|
|
511
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
512
|
+
}
|
|
513
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
514
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
515
|
+
for (const dependency of dependencies ?? []) try {
|
|
516
|
+
ctx.addWatchFile(dependency);
|
|
517
|
+
} catch (error) {
|
|
518
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
519
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
throw error;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
507
525
|
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
508
526
|
return {
|
|
509
527
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
@@ -516,7 +534,7 @@ function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
|
516
534
|
return processed && shouldFinalizeProcessedCssAsset(opts, file);
|
|
517
535
|
}
|
|
518
536
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
519
|
-
return
|
|
537
|
+
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
520
538
|
}
|
|
521
539
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
522
540
|
return {
|
|
@@ -528,7 +546,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
528
546
|
if (getResolvedConfig()?.command !== "build") return;
|
|
529
547
|
const entries = Object.entries(bundle).filter(([, output]) => output.type === "asset" && opts.cssMatcher(output.fileName) && (!isCssAssetProcessed(output, output.fileName) || shouldFinalizeProcessedCssAsset(opts, output.fileName)));
|
|
530
548
|
if (entries.length === 0) return;
|
|
531
|
-
await runtimeState.
|
|
549
|
+
await runtimeState.readyPromise;
|
|
532
550
|
await waitForSourceCandidateSyncs?.();
|
|
533
551
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
534
552
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
@@ -555,6 +573,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
555
573
|
}) : void 0;
|
|
556
574
|
const nextCss = generated?.css ?? (await opts.styleHandler(rawSource, cssHandlerOptions)).css;
|
|
557
575
|
if (generated) {
|
|
576
|
+
registerGeneratorDependencies$1(this, generated.dependencies);
|
|
558
577
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
559
578
|
recordCssAssetResult?.(file, nextCss);
|
|
560
579
|
if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, rawSource);
|
|
@@ -818,7 +837,160 @@ function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
|
|
|
818
837
|
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
819
838
|
}
|
|
820
839
|
//#endregion
|
|
821
|
-
//#region src/bundlers/vite/generate-bundle.ts
|
|
840
|
+
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
841
|
+
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
842
|
+
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
843
|
+
function isArbitraryValueCandidate(candidate) {
|
|
844
|
+
return candidate.includes("[") && candidate.includes("]");
|
|
845
|
+
}
|
|
846
|
+
function collectUnescapedDynamicCandidates(source) {
|
|
847
|
+
const matches = /* @__PURE__ */ new Set();
|
|
848
|
+
for (const expression of source.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
849
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
850
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
851
|
+
while (quoted !== null) {
|
|
852
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
853
|
+
for (const candidate of splitCode(literal, true)) {
|
|
854
|
+
const normalized = candidate.trim();
|
|
855
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
856
|
+
matches.add(normalized);
|
|
857
|
+
}
|
|
858
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return [...matches];
|
|
862
|
+
}
|
|
863
|
+
function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
864
|
+
if (candidates.has("container")) return candidates;
|
|
865
|
+
if (!sourceCandidates.has("container")) return candidates;
|
|
866
|
+
return new Set([...candidates, "container"]);
|
|
867
|
+
}
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region src/bundlers/vite/generate-bundle/css-handler-options.ts
|
|
870
|
+
function createCssHandlerOptionsCache(options) {
|
|
871
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
872
|
+
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
873
|
+
const getCssHandlerOptions = (file) => {
|
|
874
|
+
const majorVersion = options.getMajorVersion();
|
|
875
|
+
const isMainChunk = options.mainCssChunkMatcher(file, options.appType);
|
|
876
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
|
|
877
|
+
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
878
|
+
if (cached) return cached;
|
|
879
|
+
const created = {
|
|
880
|
+
isMainChunk,
|
|
881
|
+
postcssOptions: { options: { from: file } },
|
|
882
|
+
majorVersion
|
|
883
|
+
};
|
|
884
|
+
cssHandlerOptionsCache.set(cacheKey, created);
|
|
885
|
+
return created;
|
|
886
|
+
};
|
|
887
|
+
const getCssUserHandlerOptions = (file) => {
|
|
888
|
+
const cacheKey = `${options.getMajorVersion() ?? "unknown"}:${file}`;
|
|
889
|
+
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
890
|
+
if (cached) return cached;
|
|
891
|
+
const created = {
|
|
892
|
+
...getCssHandlerOptions(file),
|
|
893
|
+
isMainChunk: false
|
|
894
|
+
};
|
|
895
|
+
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
896
|
+
return created;
|
|
897
|
+
};
|
|
898
|
+
return {
|
|
899
|
+
getCssHandlerOptions,
|
|
900
|
+
getCssUserHandlerOptions
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
//#endregion
|
|
904
|
+
//#region src/bundlers/vite/generate-bundle/css-share-scope.ts
|
|
905
|
+
const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
|
|
906
|
+
const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
|
|
907
|
+
const CSS_IMPORT_RE = /@import\b/i;
|
|
908
|
+
function isPathIndependentCssUrl(value) {
|
|
909
|
+
const normalized = value.trim();
|
|
910
|
+
return normalized.length > 0 && CSS_PATH_INDEPENDENT_URL_RE.test(normalized);
|
|
911
|
+
}
|
|
912
|
+
function hasPathDependentCssUrl(rawSource) {
|
|
913
|
+
CSS_URL_FUNCTION_RE.lastIndex = 0;
|
|
914
|
+
let match = CSS_URL_FUNCTION_RE.exec(rawSource);
|
|
915
|
+
while (match !== null) {
|
|
916
|
+
if (!isPathIndependentCssUrl(match[1] ?? match[2] ?? match[3] ?? "")) return true;
|
|
917
|
+
match = CSS_URL_FUNCTION_RE.exec(rawSource);
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
function createCssTransformShareScope(file, rawSource) {
|
|
922
|
+
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${normalizeOutputPathKey(path.dirname(file))}`;
|
|
923
|
+
return "global";
|
|
924
|
+
}
|
|
925
|
+
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
926
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${normalizeOutputPathKey(file)}`;
|
|
927
|
+
return createCssTransformShareScope(file, rawSource);
|
|
928
|
+
}
|
|
929
|
+
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
930
|
+
return `${runtimeSignature}:${generatorCandidateSignature}`;
|
|
931
|
+
}
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region src/bundlers/vite/generate-bundle/dirty-state.ts
|
|
934
|
+
function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
935
|
+
const currentFileSet = new Set(currentBundleFiles);
|
|
936
|
+
for (const file of previousBundleFiles) if (!currentFileSet.has(file)) return true;
|
|
937
|
+
return false;
|
|
938
|
+
}
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
941
|
+
function createJsEntryResolver(jsEntries) {
|
|
942
|
+
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
943
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(normalizeOutputPathKey(id), entry);
|
|
944
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(normalizeOutputPathKey(id));
|
|
945
|
+
}
|
|
946
|
+
//#endregion
|
|
947
|
+
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
948
|
+
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
949
|
+
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
950
|
+
}
|
|
951
|
+
function createJsHandlerOptionsFactory(options) {
|
|
952
|
+
return (absoluteFilename, extra) => ({
|
|
953
|
+
...extra,
|
|
954
|
+
filename: absoluteFilename,
|
|
955
|
+
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
956
|
+
moduleGraph: options.moduleGraph,
|
|
957
|
+
babelParserOptions: {
|
|
958
|
+
...extra?.babelParserOptions ?? {},
|
|
959
|
+
sourceFilename: absoluteFilename
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
965
|
+
function createLinkedUpdateHelpers(options) {
|
|
966
|
+
const pendingLinkedUpdates = [];
|
|
967
|
+
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
968
|
+
options.onUpdate(fileName, previous, next);
|
|
969
|
+
options.debug("js linked handle: %s", fileName);
|
|
970
|
+
};
|
|
971
|
+
const scheduleLinkedApply = (entry, code) => {
|
|
972
|
+
pendingLinkedUpdates.push(() => {
|
|
973
|
+
if (entry.output.type === "chunk") entry.output.code = code;
|
|
974
|
+
else entry.output.source = code;
|
|
975
|
+
});
|
|
976
|
+
};
|
|
977
|
+
const applyLinkedUpdates = (linked) => {
|
|
978
|
+
applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
979
|
+
};
|
|
980
|
+
return {
|
|
981
|
+
applyLinkedUpdates,
|
|
982
|
+
pendingLinkedUpdates
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
986
|
+
if (!linked || !linkedSet) return;
|
|
987
|
+
for (const id of Object.keys(linked)) {
|
|
988
|
+
const linkedEntry = getJsEntry(id);
|
|
989
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region src/bundlers/vite/generate-bundle/metrics.ts
|
|
822
994
|
function formatDebugFileList(files, limit = 8) {
|
|
823
995
|
if (files.size === 0) return "-";
|
|
824
996
|
const sorted = [...files].sort();
|
|
@@ -844,9 +1016,6 @@ function createEmptyMetrics() {
|
|
|
844
1016
|
function measureElapsed(start) {
|
|
845
1017
|
return performance.now() - start;
|
|
846
1018
|
}
|
|
847
|
-
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
848
|
-
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
849
|
-
}
|
|
850
1019
|
function formatCacheHitRate(metric) {
|
|
851
1020
|
if (metric.total === 0) return "0.00%";
|
|
852
1021
|
return `${(metric.cacheHits / metric.total * 100).toFixed(2)}%`;
|
|
@@ -854,6 +1023,50 @@ function formatCacheHitRate(metric) {
|
|
|
854
1023
|
function formatMs(value) {
|
|
855
1024
|
return value.toFixed(2);
|
|
856
1025
|
}
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/bundlers/vite/generate-bundle/process-plan.ts
|
|
1028
|
+
function logBundleProcessPlan(options) {
|
|
1029
|
+
const { debug, snapshot, useIncrementalMode, iteration } = options;
|
|
1030
|
+
const { processFiles } = snapshot;
|
|
1031
|
+
if (useIncrementalMode) {
|
|
1032
|
+
debug("dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]", iteration, snapshot.changedByType.html.size, formatDebugFileList(snapshot.changedByType.html), snapshot.changedByType.js.size, formatDebugFileList(snapshot.changedByType.js), snapshot.changedByType.css.size, formatDebugFileList(snapshot.changedByType.css), snapshot.changedByType.other.size, formatDebugFileList(snapshot.changedByType.other));
|
|
1033
|
+
debug("process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]", iteration, processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
1037
|
+
}
|
|
1038
|
+
//#endregion
|
|
1039
|
+
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
1040
|
+
function createReplayCssAsset(fileName, source) {
|
|
1041
|
+
return {
|
|
1042
|
+
type: "asset",
|
|
1043
|
+
fileName,
|
|
1044
|
+
name: void 0,
|
|
1045
|
+
source,
|
|
1046
|
+
needsCodeReference: false,
|
|
1047
|
+
names: [],
|
|
1048
|
+
originalFileName: null,
|
|
1049
|
+
originalFileNames: []
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
1053
|
+
const candidate = error;
|
|
1054
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
1055
|
+
}
|
|
1056
|
+
function registerGeneratorDependencies(ctx, dependencies) {
|
|
1057
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
1058
|
+
for (const dependency of dependencies ?? []) try {
|
|
1059
|
+
ctx.addWatchFile(dependency);
|
|
1060
|
+
} catch (error) {
|
|
1061
|
+
if (isAddWatchFileInvalidRollupPhaseError(error)) {
|
|
1062
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
throw error;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
//#endregion
|
|
1069
|
+
//#region src/bundlers/vite/generate-bundle/signatures.ts
|
|
857
1070
|
function summarizeStringDiff(previous, next) {
|
|
858
1071
|
if (previous === next) return "same";
|
|
859
1072
|
const previousLength = previous.length;
|
|
@@ -900,111 +1113,22 @@ function getSnapshotHash(snapshotMap, file, fallback) {
|
|
|
900
1113
|
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
901
1114
|
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
902
1115
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
const CSS_IMPORT_RE = /@import\b/i;
|
|
906
|
-
function isPathIndependentCssUrl(value) {
|
|
907
|
-
const normalized = value.trim();
|
|
908
|
-
return normalized.length > 0 && CSS_PATH_INDEPENDENT_URL_RE.test(normalized);
|
|
909
|
-
}
|
|
910
|
-
function hasPathDependentCssUrl(rawSource) {
|
|
911
|
-
CSS_URL_FUNCTION_RE.lastIndex = 0;
|
|
912
|
-
let match = CSS_URL_FUNCTION_RE.exec(rawSource);
|
|
913
|
-
while (match !== null) {
|
|
914
|
-
if (!isPathIndependentCssUrl(match[1] ?? match[2] ?? match[3] ?? "")) return true;
|
|
915
|
-
match = CSS_URL_FUNCTION_RE.exec(rawSource);
|
|
916
|
-
}
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
function createCssTransformShareScope(file, rawSource) {
|
|
920
|
-
if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${normalizeOutputPathKey(path.dirname(file))}`;
|
|
921
|
-
return "global";
|
|
922
|
-
}
|
|
923
|
-
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
924
|
-
if (normalizeWeappTailwindcssGeneratorOptions(opts.generator).mode === "force" && opts.mainCssChunkMatcher(file, opts.appType)) return `main:${normalizeOutputPathKey(file)}`;
|
|
925
|
-
return createCssTransformShareScope(file, rawSource);
|
|
926
|
-
}
|
|
927
|
-
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
928
|
-
return `${runtimeSignature}:${generatorCandidateSignature}`;
|
|
929
|
-
}
|
|
930
|
-
function createReplayCssAsset(fileName, source) {
|
|
931
|
-
return {
|
|
932
|
-
type: "asset",
|
|
933
|
-
fileName,
|
|
934
|
-
name: void 0,
|
|
935
|
-
source,
|
|
936
|
-
needsCodeReference: false,
|
|
937
|
-
names: [],
|
|
938
|
-
originalFileName: null,
|
|
939
|
-
originalFileNames: []
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
943
|
-
const currentFileSet = new Set(currentBundleFiles);
|
|
944
|
-
for (const file of previousBundleFiles) if (!currentFileSet.has(file)) return true;
|
|
945
|
-
return false;
|
|
946
|
-
}
|
|
947
|
-
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
948
|
-
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
949
|
-
function isArbitraryValueCandidate(candidate) {
|
|
950
|
-
return candidate.includes("[") && candidate.includes("]");
|
|
951
|
-
}
|
|
952
|
-
function collectUnescapedDynamicCandidates(source) {
|
|
953
|
-
const matches = /* @__PURE__ */ new Set();
|
|
954
|
-
for (const expression of source.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
955
|
-
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
956
|
-
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
957
|
-
while (quoted !== null) {
|
|
958
|
-
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
959
|
-
for (const candidate of splitCode(literal, true)) {
|
|
960
|
-
const normalized = candidate.trim();
|
|
961
|
-
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
962
|
-
matches.add(normalized);
|
|
963
|
-
}
|
|
964
|
-
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
return [...matches];
|
|
968
|
-
}
|
|
969
|
-
function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
970
|
-
if (candidates.has("container")) return candidates;
|
|
971
|
-
if (!sourceCandidates.has("container")) return candidates;
|
|
972
|
-
return new Set([...candidates, "container"]);
|
|
973
|
-
}
|
|
1116
|
+
//#endregion
|
|
1117
|
+
//#region src/bundlers/vite/generate-bundle.ts
|
|
974
1118
|
function createGenerateBundleHook(context) {
|
|
975
1119
|
const state = createBundleBuildState();
|
|
976
|
-
const
|
|
977
|
-
|
|
1120
|
+
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
1121
|
+
appType: context.opts.appType,
|
|
1122
|
+
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
1123
|
+
getMajorVersion: () => context.runtimeState.twPatcher.majorVersion
|
|
1124
|
+
});
|
|
978
1125
|
return async function generateBundle(_opt, bundle) {
|
|
1126
|
+
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
979
1127
|
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, recordCssAssetResult, getSourceCandidates, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSources, getRememberedMainCssSignature, setRememberedMainCssSignature, recordGeneratorCandidates } = context;
|
|
980
|
-
const {
|
|
1128
|
+
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
981
1129
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
982
|
-
const getCssHandlerOptions
|
|
983
|
-
|
|
984
|
-
const isMainChunk = mainCssChunkMatcher(file, appType);
|
|
985
|
-
const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
|
|
986
|
-
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
987
|
-
if (cached) return cached;
|
|
988
|
-
const created = {
|
|
989
|
-
isMainChunk,
|
|
990
|
-
postcssOptions: { options: { from: file } },
|
|
991
|
-
majorVersion
|
|
992
|
-
};
|
|
993
|
-
cssHandlerOptionsCache.set(cacheKey, created);
|
|
994
|
-
return created;
|
|
995
|
-
};
|
|
996
|
-
const getCssUserHandlerOptions = (file) => {
|
|
997
|
-
const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
|
|
998
|
-
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
999
|
-
if (cached) return cached;
|
|
1000
|
-
const created = {
|
|
1001
|
-
...getCssHandlerOptions(file),
|
|
1002
|
-
isMainChunk: false
|
|
1003
|
-
};
|
|
1004
|
-
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
1005
|
-
return created;
|
|
1006
|
-
};
|
|
1007
|
-
await runtimeState.patchPromise;
|
|
1130
|
+
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
1131
|
+
await runtimeState.readyPromise;
|
|
1008
1132
|
debug("start");
|
|
1009
1133
|
onStart();
|
|
1010
1134
|
const metrics = createEmptyMetrics();
|
|
@@ -1021,52 +1145,56 @@ function createGenerateBundleHook(context) {
|
|
|
1021
1145
|
const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
|
|
1022
1146
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
1023
1147
|
const processFiles = snapshot.processFiles;
|
|
1024
|
-
|
|
1025
|
-
debug
|
|
1026
|
-
|
|
1027
|
-
|
|
1148
|
+
logBundleProcessPlan({
|
|
1149
|
+
debug,
|
|
1150
|
+
snapshot,
|
|
1151
|
+
useIncrementalMode,
|
|
1152
|
+
iteration: state.iteration + 1
|
|
1153
|
+
});
|
|
1028
1154
|
const jsEntries = snapshot.jsEntries;
|
|
1029
|
-
const
|
|
1030
|
-
for (const [id, entry] of jsEntries) normalizedJsEntries.set(normalizeOutputPathKey(id), entry);
|
|
1031
|
-
const getJsEntry = (id) => jsEntries.get(id) ?? normalizedJsEntries.get(normalizeOutputPathKey(id));
|
|
1155
|
+
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
1032
1156
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
1033
1157
|
const runtimeStart = performance.now();
|
|
1034
1158
|
const runtime = useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
1035
1159
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
1036
1160
|
await waitForSourceCandidateSyncs?.();
|
|
1037
1161
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
1038
|
-
const collectedGeneratorCandidates =
|
|
1162
|
+
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
1039
1163
|
const generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates);
|
|
1040
1164
|
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
1041
1165
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
1042
|
-
|
|
1166
|
+
let transformRuntime = runtime;
|
|
1167
|
+
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size > 0) {
|
|
1168
|
+
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
1169
|
+
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
1170
|
+
if (mainCssEntry) {
|
|
1171
|
+
const validatedRuntime = await validateCandidatesByGenerator({
|
|
1172
|
+
opts,
|
|
1173
|
+
runtimeState,
|
|
1174
|
+
candidates: generatorRuntime,
|
|
1175
|
+
rawSource: mainCssEntry.source,
|
|
1176
|
+
file: mainCssEntry.file,
|
|
1177
|
+
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
1178
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
1179
|
+
styleHandler,
|
|
1180
|
+
debug
|
|
1181
|
+
});
|
|
1182
|
+
if (validatedRuntime.size > 0) transformRuntime = new Set([...runtime, ...validatedRuntime]);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
1043
1186
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
1044
1187
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
1045
|
-
debug("get runtimeSet, class count: %d", runtime.size);
|
|
1188
|
+
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
1046
1189
|
const runtimeSignature = getRuntimeClassSetSignature(runtimeState.twPatcher) ?? "runtime:missing";
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
else entry.output.source = code;
|
|
1056
|
-
});
|
|
1057
|
-
};
|
|
1058
|
-
const applyLinkedUpdates = (linked) => {
|
|
1059
|
-
applyLinkedResults(linked, jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
1060
|
-
};
|
|
1061
|
-
const createHandlerOptions = (absoluteFilename, extra) => ({
|
|
1062
|
-
...extra,
|
|
1063
|
-
filename: absoluteFilename,
|
|
1064
|
-
tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
|
|
1065
|
-
moduleGraph: moduleGraphOptions,
|
|
1066
|
-
babelParserOptions: {
|
|
1067
|
-
...extra?.babelParserOptions ?? {},
|
|
1068
|
-
sourceFilename: absoluteFilename
|
|
1069
|
-
}
|
|
1190
|
+
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
1191
|
+
jsEntries,
|
|
1192
|
+
onUpdate,
|
|
1193
|
+
debug
|
|
1194
|
+
});
|
|
1195
|
+
const createHandlerOptions = createJsHandlerOptionsFactory({
|
|
1196
|
+
getMajorVersion: () => runtimeState.twPatcher.majorVersion,
|
|
1197
|
+
moduleGraph: moduleGraphOptions
|
|
1070
1198
|
});
|
|
1071
1199
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
1072
1200
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
@@ -1144,7 +1272,7 @@ function createGenerateBundleHook(context) {
|
|
|
1144
1272
|
}
|
|
1145
1273
|
const runTransform = async () => {
|
|
1146
1274
|
const start = performance.now();
|
|
1147
|
-
await runtimeState.
|
|
1275
|
+
await runtimeState.readyPromise;
|
|
1148
1276
|
const generated = await generateCssByGenerator({
|
|
1149
1277
|
opts,
|
|
1150
1278
|
runtimeState,
|
|
@@ -1157,6 +1285,7 @@ function createGenerateBundleHook(context) {
|
|
|
1157
1285
|
debug
|
|
1158
1286
|
});
|
|
1159
1287
|
if (generated) {
|
|
1288
|
+
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
1160
1289
|
if (debugCssDiff) debug("css diff %s: %s", file, summarizeStringDiff(rawSource, generated.css));
|
|
1161
1290
|
debug("css generated result: %s bytes=%d", file, generated.css.length);
|
|
1162
1291
|
recordCssAssetResult?.(file, generated.css);
|
|
@@ -1214,15 +1343,12 @@ function createGenerateBundleHook(context) {
|
|
|
1214
1343
|
metrics.js.transformed++;
|
|
1215
1344
|
return { result: rawSource };
|
|
1216
1345
|
}
|
|
1217
|
-
const { code, linked } = await jsHandler(rawSource,
|
|
1346
|
+
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
1218
1347
|
metrics.js.elapsed += measureElapsed(start);
|
|
1219
1348
|
metrics.js.transformed++;
|
|
1220
1349
|
onUpdate(file, rawSource, code);
|
|
1221
1350
|
debug("js handle: %s", file);
|
|
1222
|
-
|
|
1223
|
-
const linkedEntry = getJsEntry(id);
|
|
1224
|
-
if (linkedEntry && linkedSet) linkedSet.add(linkedEntry.fileName);
|
|
1225
|
-
}
|
|
1351
|
+
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
1226
1352
|
applyLinkedUpdates(linked);
|
|
1227
1353
|
return { result: code };
|
|
1228
1354
|
}
|
|
@@ -1233,10 +1359,7 @@ function createGenerateBundleHook(context) {
|
|
|
1233
1359
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
1234
1360
|
const baseApplyLinkedUpdates = applyLinkedUpdates;
|
|
1235
1361
|
const wrappedApplyLinkedUpdates = (linked) => {
|
|
1236
|
-
|
|
1237
|
-
const linkedEntry = getJsEntry(id);
|
|
1238
|
-
if (linkedEntry && linkedSet) linkedSet.add(linkedEntry.fileName);
|
|
1239
|
-
}
|
|
1362
|
+
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
1240
1363
|
baseApplyLinkedUpdates(linked);
|
|
1241
1364
|
};
|
|
1242
1365
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
@@ -1247,7 +1370,7 @@ function createGenerateBundleHook(context) {
|
|
|
1247
1370
|
debug,
|
|
1248
1371
|
jsHandler,
|
|
1249
1372
|
onUpdate,
|
|
1250
|
-
runtimeSet:
|
|
1373
|
+
runtimeSet: transformRuntime,
|
|
1251
1374
|
applyLinkedResults: wrappedApplyLinkedUpdates,
|
|
1252
1375
|
uniAppX
|
|
1253
1376
|
});
|
|
@@ -1280,7 +1403,7 @@ function createGenerateBundleHook(context) {
|
|
|
1280
1403
|
}
|
|
1281
1404
|
}
|
|
1282
1405
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature);
|
|
1283
|
-
if (useIncrementalMode
|
|
1406
|
+
if (useIncrementalMode) for (const [file, rawSource] of getRememberedMainCssSources?.() ?? []) {
|
|
1284
1407
|
if (bundleFiles.includes(file) || getRememberedMainCssSignature?.(file) === cssRuntimeSignature) continue;
|
|
1285
1408
|
tasks.push((async () => {
|
|
1286
1409
|
const start = performance.now();
|
|
@@ -1299,6 +1422,7 @@ function createGenerateBundleHook(context) {
|
|
|
1299
1422
|
const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
|
|
1300
1423
|
setRememberedMainCssSignature?.(file, cssRuntimeSignature);
|
|
1301
1424
|
if (generated) {
|
|
1425
|
+
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
1302
1426
|
recordCssAssetResult?.(file, generated.css);
|
|
1303
1427
|
debug("css replay generated result: %s bytes=%d", file, css.length);
|
|
1304
1428
|
}
|
|
@@ -1326,21 +1450,248 @@ function createGenerateBundleHook(context) {
|
|
|
1326
1450
|
};
|
|
1327
1451
|
}
|
|
1328
1452
|
//#endregion
|
|
1329
|
-
//#region src/bundlers/vite/
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1342
|
-
function
|
|
1343
|
-
|
|
1453
|
+
//#region src/bundlers/vite/official-tailwind-plugins.ts
|
|
1454
|
+
const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
|
|
1455
|
+
function getPostcssPluginName(plugin) {
|
|
1456
|
+
if (!plugin) return;
|
|
1457
|
+
if (typeof plugin === "function" && "postcss" in plugin) try {
|
|
1458
|
+
return getPostcssPluginName(plugin());
|
|
1459
|
+
} catch {
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
if (typeof plugin !== "object" || !("postcssPlugin" in plugin)) return;
|
|
1463
|
+
const { postcssPlugin } = plugin;
|
|
1464
|
+
return typeof postcssPlugin === "string" ? postcssPlugin : void 0;
|
|
1465
|
+
}
|
|
1466
|
+
function isTailwindPostcssPlugin(plugin) {
|
|
1467
|
+
const name = getPostcssPluginName(plugin);
|
|
1468
|
+
return typeof name === "string" && tailwindPostcssPluginNames.has(name);
|
|
1469
|
+
}
|
|
1470
|
+
function removeTailwindPostcssPlugins(plugins) {
|
|
1471
|
+
let removed = 0;
|
|
1472
|
+
for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindPostcssPlugin(plugins[i])) {
|
|
1473
|
+
plugins.splice(i, 1);
|
|
1474
|
+
removed++;
|
|
1475
|
+
}
|
|
1476
|
+
return removed;
|
|
1477
|
+
}
|
|
1478
|
+
function isTailwindVitePlugin(plugin) {
|
|
1479
|
+
if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
|
|
1480
|
+
const { name } = plugin;
|
|
1481
|
+
return typeof name === "string" && name.startsWith("@tailwindcss/vite");
|
|
1482
|
+
}
|
|
1483
|
+
function removeTailwindVitePlugins(plugins) {
|
|
1484
|
+
let removed = 0;
|
|
1485
|
+
for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindVitePlugin(plugins[i])) {
|
|
1486
|
+
plugins.splice(i, 1);
|
|
1487
|
+
removed++;
|
|
1488
|
+
}
|
|
1489
|
+
return removed;
|
|
1490
|
+
}
|
|
1491
|
+
function disableTailwindVitePlugin(plugin) {
|
|
1492
|
+
if (!isTailwindVitePlugin(plugin)) return false;
|
|
1493
|
+
const mutablePlugin = plugin;
|
|
1494
|
+
for (const hook of [
|
|
1495
|
+
"configResolved",
|
|
1496
|
+
"configureServer",
|
|
1497
|
+
"transform",
|
|
1498
|
+
"hotUpdate",
|
|
1499
|
+
"handleHotUpdate"
|
|
1500
|
+
]) delete mutablePlugin[hook];
|
|
1501
|
+
return true;
|
|
1502
|
+
}
|
|
1503
|
+
function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
1504
|
+
let removed = 0;
|
|
1505
|
+
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
1506
|
+
const plugin = plugins[i];
|
|
1507
|
+
if (Array.isArray(plugin)) {
|
|
1508
|
+
removed += disableAndRemoveTailwindVitePlugins(plugin);
|
|
1509
|
+
if (plugin.length === 0) plugins.splice(i, 1);
|
|
1510
|
+
continue;
|
|
1511
|
+
}
|
|
1512
|
+
if (disableTailwindVitePlugin(plugin)) {
|
|
1513
|
+
plugins.splice(i, 1);
|
|
1514
|
+
removed++;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
return removed;
|
|
1518
|
+
}
|
|
1519
|
+
//#endregion
|
|
1520
|
+
//#region src/bundlers/vite/postcss-config.ts
|
|
1521
|
+
async function resolveFilteredPostcssConfig(root) {
|
|
1522
|
+
try {
|
|
1523
|
+
const loaded = await postcssrc({}, root);
|
|
1524
|
+
const plugins = Array.isArray(loaded.plugins) ? [...loaded.plugins] : [];
|
|
1525
|
+
const removed = removeTailwindPostcssPlugins(plugins);
|
|
1526
|
+
if (removed === 0) return;
|
|
1527
|
+
return {
|
|
1528
|
+
options: loaded.options,
|
|
1529
|
+
plugins,
|
|
1530
|
+
removed
|
|
1531
|
+
};
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
if ((error instanceof Error ? error.message : String(error)).includes("No PostCSS Config found")) return;
|
|
1534
|
+
throw error;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
//#endregion
|
|
1538
|
+
//#region src/bundlers/vite/resolve-app-type.ts
|
|
1539
|
+
const PACKAGE_JSON_FILE$1 = "package.json";
|
|
1540
|
+
const MPX_SCRIPT_RE = /\bmpx(?:-cli-service)?\b/u;
|
|
1541
|
+
const TARO_SCRIPT_RE = /\btaro\b/u;
|
|
1542
|
+
const TAILWINDCSS_VITE_MARKERS = [["src/app.mpx", "mpx"], ["app.mpx", "mpx"]];
|
|
1543
|
+
function resolveDependencyNames(pkg) {
|
|
1544
|
+
return new Set([
|
|
1545
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
1546
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
1547
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
1548
|
+
...Object.keys(pkg.optionalDependencies ?? {})
|
|
1549
|
+
]);
|
|
1550
|
+
}
|
|
1551
|
+
function hasScriptMatch(pkg, pattern) {
|
|
1552
|
+
return Object.values(pkg.scripts ?? {}).some((script) => pattern.test(script));
|
|
1553
|
+
}
|
|
1554
|
+
function resolveAppTypeFromPackageJson(pkg) {
|
|
1555
|
+
const dependencyNames = resolveDependencyNames(pkg);
|
|
1556
|
+
if (dependencyNames.has("weapp-vite") || [...dependencyNames].some((name) => name.startsWith("@weapp-vite/"))) return "weapp-vite";
|
|
1557
|
+
if ([...dependencyNames].some((name) => name.startsWith("@mpxjs/")) || hasScriptMatch(pkg, MPX_SCRIPT_RE)) return "mpx";
|
|
1558
|
+
if ([...dependencyNames].some((name) => name.startsWith("@tarojs/")) || hasScriptMatch(pkg, TARO_SCRIPT_RE)) return "taro";
|
|
1559
|
+
if (dependencyNames.has("@dcloudio/vite-plugin-uni")) return "uni-app-vite";
|
|
1560
|
+
if (dependencyNames.has("@dcloudio/vue-cli-plugin-uni") || dependencyNames.has("@dcloudio/uni-app") || Object.hasOwn(pkg, "uni-app")) return "uni-app";
|
|
1561
|
+
}
|
|
1562
|
+
function tryReadUniAppManifest(root) {
|
|
1563
|
+
const manifestPath = path.join(root, "manifest.json");
|
|
1564
|
+
if (!existsSync(manifestPath)) return;
|
|
1565
|
+
try {
|
|
1566
|
+
return JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
1567
|
+
} catch {}
|
|
1568
|
+
}
|
|
1569
|
+
function tryReadPackageJson(root) {
|
|
1570
|
+
const packageJsonPath = path.join(root, PACKAGE_JSON_FILE$1);
|
|
1571
|
+
if (!existsSync(packageJsonPath)) return;
|
|
1572
|
+
try {
|
|
1573
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
1574
|
+
} catch {}
|
|
1575
|
+
}
|
|
1576
|
+
function resolveAppTypeFromMarkers(root) {
|
|
1577
|
+
for (const [relativePath, appType] of TAILWINDCSS_VITE_MARKERS) if (existsSync(path.join(root, relativePath))) return appType;
|
|
1578
|
+
}
|
|
1579
|
+
function resolveImplicitAppTypeFromViteRoot(root) {
|
|
1580
|
+
const resolvedRoot = path.resolve(root);
|
|
1581
|
+
if (!existsSync(resolvedRoot)) return;
|
|
1582
|
+
const markerDetected = resolveAppTypeFromMarkers(resolvedRoot);
|
|
1583
|
+
if (markerDetected) return markerDetected;
|
|
1584
|
+
let current = resolvedRoot;
|
|
1585
|
+
while (true) {
|
|
1586
|
+
const manifest = tryReadUniAppManifest(current);
|
|
1587
|
+
if (manifest && Object.hasOwn(manifest, "uni-app-x")) return "uni-app-x";
|
|
1588
|
+
const pkg = tryReadPackageJson(current);
|
|
1589
|
+
if (pkg) {
|
|
1590
|
+
const detected = resolveAppTypeFromPackageJson(pkg);
|
|
1591
|
+
if (detected) return detected;
|
|
1592
|
+
}
|
|
1593
|
+
const parent = path.dirname(current);
|
|
1594
|
+
if (parent === current) break;
|
|
1595
|
+
current = parent;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
//#endregion
|
|
1599
|
+
//#region src/bundlers/shared/css-imports.ts
|
|
1600
|
+
const tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
|
|
1601
|
+
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
1602
|
+
function normalizeTailwindcssSpecifier(specifier) {
|
|
1603
|
+
if (specifier === "tailwindcss$") return "tailwindcss";
|
|
1604
|
+
return specifier;
|
|
1605
|
+
}
|
|
1606
|
+
function getTailwindcssSubpath(specifier) {
|
|
1607
|
+
if (specifier === "tailwindcss") return "index.css";
|
|
1608
|
+
return specifier.slice(12);
|
|
1609
|
+
}
|
|
1610
|
+
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
1611
|
+
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
1612
|
+
if (!tailwindcssImportRE.test(normalized)) return null;
|
|
1613
|
+
if (normalized === "tailwindcss") return options?.rootImport ?? "weapp-tailwindcss/index.css";
|
|
1614
|
+
return (options?.join ?? path.join)(pkgDir, getTailwindcssSubpath(normalized));
|
|
1615
|
+
}
|
|
1616
|
+
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
1617
|
+
let hasReplacements = false;
|
|
1618
|
+
const rewritten = code.replace(tailwindcssCssImportStatementRE, (full, prefix, quote, specifier, suffix) => {
|
|
1619
|
+
const replacement = resolveTailwindcssImport(specifier, pkgDir, options);
|
|
1620
|
+
if (!replacement) return full;
|
|
1621
|
+
hasReplacements = true;
|
|
1622
|
+
return `${prefix}${quote}${replacement}${suffix}`;
|
|
1623
|
+
});
|
|
1624
|
+
return hasReplacements ? rewritten : void 0;
|
|
1625
|
+
}
|
|
1626
|
+
//#endregion
|
|
1627
|
+
//#region src/bundlers/vite/rewrite-css-imports.ts
|
|
1628
|
+
function joinPosixPath(base, subpath) {
|
|
1629
|
+
if (base.endsWith("/")) return `${base}${subpath}`;
|
|
1630
|
+
return `${base}/${subpath}`;
|
|
1631
|
+
}
|
|
1632
|
+
function isCssLikeImporter(importer) {
|
|
1633
|
+
if (!importer) return false;
|
|
1634
|
+
const normalized = cleanUrl$1(importer);
|
|
1635
|
+
return isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
1636
|
+
}
|
|
1637
|
+
function stripTailwindConfigDirectives(code) {
|
|
1638
|
+
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
1639
|
+
}
|
|
1640
|
+
function createRewriteCssImportsPlugins(options) {
|
|
1641
|
+
if (!options.shouldRewrite) return [];
|
|
1642
|
+
const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
|
|
1643
|
+
const resolveAppType = () => getAppType?.() ?? appType;
|
|
1644
|
+
return [{
|
|
1645
|
+
name: `${vitePluginName}:rewrite-css-imports`,
|
|
1646
|
+
enforce: "pre",
|
|
1647
|
+
resolveId: {
|
|
1648
|
+
order: "pre",
|
|
1649
|
+
handler(id, importer) {
|
|
1650
|
+
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
|
|
1651
|
+
join: joinPosixPath,
|
|
1652
|
+
appType: resolveAppType(),
|
|
1653
|
+
rootImport
|
|
1654
|
+
});
|
|
1655
|
+
if (!replacement) return null;
|
|
1656
|
+
if (importer && !isCssLikeImporter(importer)) return null;
|
|
1657
|
+
return replacement;
|
|
1658
|
+
}
|
|
1659
|
+
},
|
|
1660
|
+
transform: {
|
|
1661
|
+
order: "pre",
|
|
1662
|
+
handler(code, id) {
|
|
1663
|
+
if (!isCSSRequest(id)) return null;
|
|
1664
|
+
const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
|
|
1665
|
+
join: joinPosixPath,
|
|
1666
|
+
appType: resolveAppType(),
|
|
1667
|
+
rootImport
|
|
1668
|
+
});
|
|
1669
|
+
const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ?? code) : rewritten;
|
|
1670
|
+
if (!nextCode || nextCode === code) return null;
|
|
1671
|
+
return {
|
|
1672
|
+
code: nextCode,
|
|
1673
|
+
map: null
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
}];
|
|
1678
|
+
}
|
|
1679
|
+
//#endregion
|
|
1680
|
+
//#region src/bundlers/vite/incremental-runtime-class-set.ts
|
|
1681
|
+
const debug$1 = createDebug("[vite:runtime-set] ");
|
|
1682
|
+
const EXTENSION_DOT_PREFIX_RE = /^\./;
|
|
1683
|
+
function createExtractOptions(context, source) {
|
|
1684
|
+
return {
|
|
1685
|
+
cwd: context.projectRoot,
|
|
1686
|
+
base: context.base,
|
|
1687
|
+
baseFallbacks: context.baseFallbacks,
|
|
1688
|
+
css: context.css,
|
|
1689
|
+
content: source,
|
|
1690
|
+
extension: "html"
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
function createRuntimeEntries(snapshot) {
|
|
1694
|
+
return snapshot.entries.filter((entry) => entry.type === "html" || entry.type === "js");
|
|
1344
1695
|
}
|
|
1345
1696
|
function collectChangedRuntimeFiles(snapshot) {
|
|
1346
1697
|
return new Set([...snapshot.runtimeAffectingChangedByType.html, ...snapshot.runtimeAffectingChangedByType.js]);
|
|
@@ -1490,114 +1841,111 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
1490
1841
|
};
|
|
1491
1842
|
}
|
|
1492
1843
|
//#endregion
|
|
1493
|
-
//#region src/bundlers/vite/
|
|
1494
|
-
|
|
1495
|
-
const
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
function
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
if (
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1844
|
+
//#region src/bundlers/vite/runtime-class-set.ts
|
|
1845
|
+
function createViteRuntimeClassSet(options) {
|
|
1846
|
+
const { opts, initialTwPatcher, refreshTailwindcssPatcher, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
1847
|
+
const runtimeState = {
|
|
1848
|
+
twPatcher: initialTwPatcher,
|
|
1849
|
+
readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
1850
|
+
refreshTailwindcssPatcher
|
|
1851
|
+
};
|
|
1852
|
+
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
|
|
1853
|
+
let runtimeSet;
|
|
1854
|
+
let runtimeSetPromise;
|
|
1855
|
+
let runtimeRefreshSignature;
|
|
1856
|
+
let runtimeRefreshOptionsKey;
|
|
1857
|
+
function resolveRuntimeRefreshOptions() {
|
|
1858
|
+
const configPath = resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
|
|
1859
|
+
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
1860
|
+
const optionsKey = JSON.stringify({
|
|
1861
|
+
appType: opts.appType,
|
|
1862
|
+
uniAppX: uniAppXEnabled,
|
|
1863
|
+
customAttributesEntities,
|
|
1864
|
+
disabledDefaultTemplateHandler,
|
|
1865
|
+
configPath
|
|
1866
|
+
});
|
|
1867
|
+
const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
|
|
1868
|
+
runtimeRefreshSignature = signature;
|
|
1869
|
+
runtimeRefreshOptionsKey = optionsKey;
|
|
1870
|
+
return {
|
|
1871
|
+
changed,
|
|
1872
|
+
signature,
|
|
1873
|
+
optionsKey
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
async function refreshRuntimeState(force) {
|
|
1877
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
1878
|
+
const refreshed = await refreshTailwindRuntimeState(runtimeState, {
|
|
1879
|
+
force: force || invalidation.changed,
|
|
1880
|
+
clearCache: force || invalidation.changed
|
|
1881
|
+
});
|
|
1882
|
+
if (invalidation.changed) debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
|
|
1883
|
+
if (refreshed) {
|
|
1884
|
+
runtimeSet = void 0;
|
|
1885
|
+
runtimeSetPromise = void 0;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
async function ensureRuntimeClassSet(force = false) {
|
|
1889
|
+
const forceRuntimeRefresh = force || process.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
1890
|
+
await refreshRuntimeState(force);
|
|
1891
|
+
await runtimeState.readyPromise;
|
|
1892
|
+
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
1893
|
+
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
1894
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
1895
|
+
runtimeSetPromise = collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1896
|
+
force: forceRuntimeRefresh || invalidation.changed,
|
|
1897
|
+
skipRefresh: forceRuntimeRefresh,
|
|
1898
|
+
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
const task = runtimeSetPromise;
|
|
1902
|
+
try {
|
|
1903
|
+
runtimeSet = await task;
|
|
1904
|
+
return runtimeSet;
|
|
1905
|
+
} finally {
|
|
1906
|
+
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
|
|
1910
|
+
const forceRuntimeRefresh = forceRefresh || process.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
1911
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
1912
|
+
const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
|
|
1913
|
+
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
1914
|
+
await refreshRuntimeState(shouldRefreshPatcher);
|
|
1915
|
+
await runtimeState.readyPromise;
|
|
1916
|
+
if (shouldRefreshPatcher) {
|
|
1917
|
+
runtimeSet = void 0;
|
|
1918
|
+
runtimeSetPromise = void 0;
|
|
1919
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1920
|
+
}
|
|
1921
|
+
if (runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) try {
|
|
1922
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
1923
|
+
runtimeSet = nextRuntimeSet;
|
|
1924
|
+
return nextRuntimeSet;
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1927
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1928
|
+
}
|
|
1929
|
+
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
1930
|
+
const task = collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1931
|
+
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
1932
|
+
skipRefresh: forceRuntimeRefresh,
|
|
1933
|
+
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
1934
|
+
});
|
|
1935
|
+
runtimeSetPromise = task;
|
|
1936
|
+
try {
|
|
1937
|
+
runtimeSet = await task;
|
|
1938
|
+
return runtimeSet;
|
|
1939
|
+
} finally {
|
|
1940
|
+
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
1547
1941
|
}
|
|
1548
|
-
const parent = path.dirname(current);
|
|
1549
|
-
if (parent === current) break;
|
|
1550
|
-
current = parent;
|
|
1551
1942
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
}
|
|
1559
|
-
function isCssLikeImporter(importer) {
|
|
1560
|
-
if (!importer) return false;
|
|
1561
|
-
const normalized = cleanUrl$1(importer);
|
|
1562
|
-
return isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
1563
|
-
}
|
|
1564
|
-
function createRewriteCssImportsPlugins(options) {
|
|
1565
|
-
if (!options.shouldRewrite) return [];
|
|
1566
|
-
const { appType, getAppType, rootImport, weappTailwindcssDirPosix } = options;
|
|
1567
|
-
const resolveAppType = () => getAppType?.() ?? appType;
|
|
1568
|
-
return [{
|
|
1569
|
-
name: `${vitePluginName}:rewrite-css-imports`,
|
|
1570
|
-
enforce: "pre",
|
|
1571
|
-
resolveId: {
|
|
1572
|
-
order: "pre",
|
|
1573
|
-
handler(id, importer) {
|
|
1574
|
-
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
|
|
1575
|
-
join: joinPosixPath,
|
|
1576
|
-
appType: resolveAppType(),
|
|
1577
|
-
rootImport
|
|
1578
|
-
});
|
|
1579
|
-
if (!replacement) return null;
|
|
1580
|
-
if (importer && !isCssLikeImporter(importer)) return null;
|
|
1581
|
-
return replacement;
|
|
1582
|
-
}
|
|
1583
|
-
},
|
|
1584
|
-
transform: {
|
|
1585
|
-
order: "pre",
|
|
1586
|
-
handler(code, id) {
|
|
1587
|
-
if (!isCSSRequest(id)) return null;
|
|
1588
|
-
const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
|
|
1589
|
-
join: joinPosixPath,
|
|
1590
|
-
appType: resolveAppType(),
|
|
1591
|
-
rootImport
|
|
1592
|
-
});
|
|
1593
|
-
if (!rewritten) return null;
|
|
1594
|
-
return {
|
|
1595
|
-
code: rewritten,
|
|
1596
|
-
map: null
|
|
1597
|
-
};
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
}];
|
|
1943
|
+
return {
|
|
1944
|
+
runtimeState,
|
|
1945
|
+
refreshRuntimeState,
|
|
1946
|
+
ensureRuntimeClassSet,
|
|
1947
|
+
ensureBundleRuntimeClassSet
|
|
1948
|
+
};
|
|
1601
1949
|
}
|
|
1602
1950
|
//#endregion
|
|
1603
1951
|
//#region src/bundlers/vite/source-candidates.ts
|
|
@@ -1752,92 +2100,8 @@ function createSourceCandidateCollector() {
|
|
|
1752
2100
|
};
|
|
1753
2101
|
}
|
|
1754
2102
|
//#endregion
|
|
1755
|
-
//#region src/bundlers/vite/
|
|
1756
|
-
const debug = createDebug();
|
|
1757
|
-
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
1758
|
-
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
2103
|
+
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
1759
2104
|
const PACKAGE_JSON_FILE = "package.json";
|
|
1760
|
-
const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
|
|
1761
|
-
function getPostcssPluginName(plugin) {
|
|
1762
|
-
if (!plugin) return;
|
|
1763
|
-
if (typeof plugin === "function" && "postcss" in plugin) try {
|
|
1764
|
-
return getPostcssPluginName(plugin());
|
|
1765
|
-
} catch {
|
|
1766
|
-
return;
|
|
1767
|
-
}
|
|
1768
|
-
if (typeof plugin !== "object" || !("postcssPlugin" in plugin)) return;
|
|
1769
|
-
const { postcssPlugin } = plugin;
|
|
1770
|
-
return typeof postcssPlugin === "string" ? postcssPlugin : void 0;
|
|
1771
|
-
}
|
|
1772
|
-
function isTailwindPostcssPlugin(plugin) {
|
|
1773
|
-
const name = getPostcssPluginName(plugin);
|
|
1774
|
-
return typeof name === "string" && tailwindPostcssPluginNames.has(name);
|
|
1775
|
-
}
|
|
1776
|
-
function removeTailwindPostcssPlugins(plugins) {
|
|
1777
|
-
let removed = 0;
|
|
1778
|
-
for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindPostcssPlugin(plugins[i])) {
|
|
1779
|
-
plugins.splice(i, 1);
|
|
1780
|
-
removed++;
|
|
1781
|
-
}
|
|
1782
|
-
return removed;
|
|
1783
|
-
}
|
|
1784
|
-
async function resolveFilteredPostcssConfig(root) {
|
|
1785
|
-
try {
|
|
1786
|
-
const loaded = await postcssrc({}, root);
|
|
1787
|
-
const plugins = Array.isArray(loaded.plugins) ? [...loaded.plugins] : [];
|
|
1788
|
-
const removed = removeTailwindPostcssPlugins(plugins);
|
|
1789
|
-
if (removed === 0) return;
|
|
1790
|
-
return {
|
|
1791
|
-
options: loaded.options,
|
|
1792
|
-
plugins,
|
|
1793
|
-
removed
|
|
1794
|
-
};
|
|
1795
|
-
} catch (error) {
|
|
1796
|
-
if ((error instanceof Error ? error.message : String(error)).includes("No PostCSS Config found")) return;
|
|
1797
|
-
throw error;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
function isTailwindVitePlugin(plugin) {
|
|
1801
|
-
if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
|
|
1802
|
-
const { name } = plugin;
|
|
1803
|
-
return typeof name === "string" && name.startsWith("@tailwindcss/vite");
|
|
1804
|
-
}
|
|
1805
|
-
function removeTailwindVitePlugins(plugins) {
|
|
1806
|
-
let removed = 0;
|
|
1807
|
-
for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindVitePlugin(plugins[i])) {
|
|
1808
|
-
plugins.splice(i, 1);
|
|
1809
|
-
removed++;
|
|
1810
|
-
}
|
|
1811
|
-
return removed;
|
|
1812
|
-
}
|
|
1813
|
-
function disableTailwindVitePlugin(plugin) {
|
|
1814
|
-
if (!isTailwindVitePlugin(plugin)) return false;
|
|
1815
|
-
const mutablePlugin = plugin;
|
|
1816
|
-
for (const hook of [
|
|
1817
|
-
"configResolved",
|
|
1818
|
-
"configureServer",
|
|
1819
|
-
"transform",
|
|
1820
|
-
"hotUpdate",
|
|
1821
|
-
"handleHotUpdate"
|
|
1822
|
-
]) delete mutablePlugin[hook];
|
|
1823
|
-
return true;
|
|
1824
|
-
}
|
|
1825
|
-
function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
1826
|
-
let removed = 0;
|
|
1827
|
-
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
1828
|
-
const plugin = plugins[i];
|
|
1829
|
-
if (Array.isArray(plugin)) {
|
|
1830
|
-
removed += disableAndRemoveTailwindVitePlugins(plugin);
|
|
1831
|
-
if (plugin.length === 0) plugins.splice(i, 1);
|
|
1832
|
-
continue;
|
|
1833
|
-
}
|
|
1834
|
-
if (disableTailwindVitePlugin(plugin)) {
|
|
1835
|
-
plugins.splice(i, 1);
|
|
1836
|
-
removed++;
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
return removed;
|
|
1840
|
-
}
|
|
1841
2105
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
1842
2106
|
const resolvedRoot = path.resolve(root);
|
|
1843
2107
|
if (!existsSync(resolvedRoot)) return resolvedRoot;
|
|
@@ -1855,140 +2119,52 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
1855
2119
|
if (packageRoot && existsSync(path.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
1856
2120
|
return resolvedRoot;
|
|
1857
2121
|
}
|
|
2122
|
+
//#endregion
|
|
2123
|
+
//#region src/bundlers/vite/index.ts
|
|
2124
|
+
const debug = createDebug();
|
|
2125
|
+
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
2126
|
+
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
1858
2127
|
/**
|
|
1859
|
-
* @name
|
|
2128
|
+
* @name WeappTailwindcss
|
|
1860
2129
|
* @description uni-app vite / uni-app-x 版本插件
|
|
1861
2130
|
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
1862
2131
|
*/
|
|
1863
|
-
function
|
|
2132
|
+
function WeappTailwindcss(options = {}) {
|
|
1864
2133
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
1865
|
-
const rewriteCssImportsSpecified = Object.hasOwn(options, "rewriteCssImports");
|
|
1866
2134
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
1867
2135
|
const opts = getCompilerContext(options);
|
|
1868
2136
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
1869
2137
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
1870
|
-
const disabledOptions =
|
|
2138
|
+
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
1871
2139
|
const tailwindcssMajorVersion = initialTwPatcher.majorVersion ?? 0;
|
|
1872
|
-
const shouldOwnTailwindGeneration =
|
|
1873
|
-
const shouldRewriteCssImports =
|
|
2140
|
+
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
2141
|
+
const shouldRewriteCssImports = tailwindcssMajorVersion >= 4;
|
|
1874
2142
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
1875
2143
|
getAppType: () => opts.appType,
|
|
1876
2144
|
rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
|
|
2145
|
+
shouldOwnTailwindGeneration,
|
|
1877
2146
|
shouldRewrite: shouldRewriteCssImports,
|
|
1878
2147
|
weappTailwindcssDirPosix
|
|
1879
2148
|
});
|
|
1880
2149
|
if (disabledOptions.plugin) return rewritePlugins.length ? rewritePlugins : void 0;
|
|
1881
2150
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
1882
|
-
const patchRecorderState = setupPatchRecorder(initialTwPatcher, opts.tailwindcssBasedir, {
|
|
1883
|
-
source: "runtime",
|
|
1884
|
-
cwd: opts.tailwindcssBasedir ?? process.cwd()
|
|
1885
|
-
});
|
|
1886
|
-
const runtimeState = {
|
|
1887
|
-
twPatcher: initialTwPatcher,
|
|
1888
|
-
patchPromise: patchRecorderState.patchPromise,
|
|
1889
|
-
refreshTailwindcssPatcher,
|
|
1890
|
-
onPatchCompleted: patchRecorderState.onPatchCompleted
|
|
1891
|
-
};
|
|
1892
|
-
let runtimeSet;
|
|
1893
|
-
let runtimeSetPromise;
|
|
1894
2151
|
let resolvedConfig;
|
|
1895
|
-
let runtimeRefreshSignature;
|
|
1896
|
-
let runtimeRefreshOptionsKey;
|
|
1897
2152
|
let recordedGeneratorCandidates;
|
|
1898
|
-
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
|
|
1899
2153
|
const sourceCandidateCollector = createSourceCandidateCollector();
|
|
1900
2154
|
const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
|
|
1901
2155
|
const processedCssAssets = /* @__PURE__ */ new WeakSet();
|
|
1902
2156
|
const processedCssAssetFiles = /* @__PURE__ */ new Set();
|
|
1903
2157
|
const rememberedMainCssSources = /* @__PURE__ */ new Map();
|
|
1904
2158
|
const rememberedMainCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
rewriteCssImports: shouldRewriteCssImports
|
|
1915
|
-
});
|
|
1916
|
-
const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
|
|
1917
|
-
runtimeRefreshSignature = signature;
|
|
1918
|
-
runtimeRefreshOptionsKey = optionsKey;
|
|
1919
|
-
return {
|
|
1920
|
-
changed,
|
|
1921
|
-
signature,
|
|
1922
|
-
optionsKey
|
|
1923
|
-
};
|
|
1924
|
-
}
|
|
1925
|
-
async function refreshRuntimeState(force) {
|
|
1926
|
-
const invalidation = resolveRuntimeRefreshOptions();
|
|
1927
|
-
const refreshed = await refreshTailwindRuntimeState(runtimeState, {
|
|
1928
|
-
force: force || invalidation.changed,
|
|
1929
|
-
clearCache: force || invalidation.changed
|
|
1930
|
-
});
|
|
1931
|
-
if (invalidation.changed) debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
|
|
1932
|
-
if (refreshed) {
|
|
1933
|
-
runtimeSet = void 0;
|
|
1934
|
-
runtimeSetPromise = void 0;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
async function ensureRuntimeClassSet(force = false) {
|
|
1938
|
-
const forceRuntimeRefresh = force || process.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
1939
|
-
await refreshRuntimeState(force);
|
|
1940
|
-
await runtimeState.patchPromise;
|
|
1941
|
-
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
1942
|
-
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
1943
|
-
const invalidation = resolveRuntimeRefreshOptions();
|
|
1944
|
-
runtimeSetPromise = collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1945
|
-
force: forceRuntimeRefresh || invalidation.changed,
|
|
1946
|
-
skipRefresh: forceRuntimeRefresh,
|
|
1947
|
-
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
const task = runtimeSetPromise;
|
|
1951
|
-
try {
|
|
1952
|
-
runtimeSet = await task;
|
|
1953
|
-
return runtimeSet;
|
|
1954
|
-
} finally {
|
|
1955
|
-
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
|
|
1959
|
-
const forceRuntimeRefresh = forceRefresh || process.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
1960
|
-
const invalidation = resolveRuntimeRefreshOptions();
|
|
1961
|
-
const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
|
|
1962
|
-
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
1963
|
-
await refreshRuntimeState(shouldRefreshPatcher);
|
|
1964
|
-
await runtimeState.patchPromise;
|
|
1965
|
-
if (shouldRefreshPatcher) {
|
|
1966
|
-
runtimeSet = void 0;
|
|
1967
|
-
runtimeSetPromise = void 0;
|
|
1968
|
-
await bundleRuntimeClassSetManager.reset();
|
|
1969
|
-
}
|
|
1970
|
-
if (runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) try {
|
|
1971
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
1972
|
-
runtimeSet = nextRuntimeSet;
|
|
1973
|
-
return nextRuntimeSet;
|
|
1974
|
-
} catch (error) {
|
|
1975
|
-
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1976
|
-
await bundleRuntimeClassSetManager.reset();
|
|
1977
|
-
}
|
|
1978
|
-
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
1979
|
-
const task = collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1980
|
-
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
1981
|
-
skipRefresh: forceRuntimeRefresh,
|
|
1982
|
-
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
1983
|
-
});
|
|
1984
|
-
runtimeSetPromise = task;
|
|
1985
|
-
try {
|
|
1986
|
-
runtimeSet = await task;
|
|
1987
|
-
return runtimeSet;
|
|
1988
|
-
} finally {
|
|
1989
|
-
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
2159
|
+
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
2160
|
+
opts,
|
|
2161
|
+
initialTwPatcher,
|
|
2162
|
+
refreshTailwindcssPatcher,
|
|
2163
|
+
uniAppXEnabled,
|
|
2164
|
+
customAttributesEntities,
|
|
2165
|
+
disabledDefaultTemplateHandler,
|
|
2166
|
+
debug
|
|
2167
|
+
});
|
|
1992
2168
|
onLoad();
|
|
1993
2169
|
const getResolvedConfig = () => resolvedConfig;
|
|
1994
2170
|
const markCssAssetProcessed = (asset, file) => {
|
|
@@ -2081,6 +2257,18 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2081
2257
|
root,
|
|
2082
2258
|
outDir
|
|
2083
2259
|
});
|
|
2260
|
+
const basedir = opts.tailwindcssBasedir ? path.resolve(opts.tailwindcssBasedir) : void 0;
|
|
2261
|
+
if (basedir && basedir !== path.resolve(root)) await sourceCandidateCollector.scanRoot({
|
|
2262
|
+
root: basedir,
|
|
2263
|
+
outDir
|
|
2264
|
+
});
|
|
2265
|
+
for (const cssEntry of opts.tailwindcss?.cssEntries ?? []) {
|
|
2266
|
+
const cssEntryRoot = path.dirname(path.resolve(cssEntry));
|
|
2267
|
+
if (cssEntryRoot !== path.resolve(root) && cssEntryRoot !== basedir) await sourceCandidateCollector.scanRoot({
|
|
2268
|
+
root: cssEntryRoot,
|
|
2269
|
+
outDir
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2084
2272
|
}
|
|
2085
2273
|
},
|
|
2086
2274
|
{
|
|
@@ -2183,4 +2371,4 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2183
2371
|
return plugins;
|
|
2184
2372
|
}
|
|
2185
2373
|
//#endregion
|
|
2186
|
-
export {
|
|
2374
|
+
export { WeappTailwindcss as t };
|