weapp-tailwindcss 5.4.2 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/README.zh-CN.md +13 -1
- package/dist/bundlers/shared/final-css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/v4-generation-core.d.ts +1 -0
- package/dist/bundlers/vite/capability-profile.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer/web-plugin.d.ts +3 -0
- package/dist/bundlers/vite/css-handler-options.d.ts +32 -0
- package/dist/bundlers/vite/{generate-bundle/css-output.d.ts → css-output.d.ts} +1 -1
- package/dist/bundlers/vite/frameworks/generic/web.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +2 -32
- package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +2 -2
- package/dist/bundlers/vite/generate-bundle/runtime.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/runtime-class-set.d.ts +1 -5
- package/dist/bundlers/vite/shared/create-css-only-plugins-runtime.d.ts +3 -0
- package/dist/cache-CBJFB1HN.cjs +223 -0
- package/dist/compiler/events.d.ts +32 -0
- package/dist/compiler/host.d.ts +13 -0
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/runtime-state.d.ts +17 -0
- package/dist/compiler-B0YSc0DY.js +4877 -0
- package/dist/{wxml-o-CUulAM.cjs → compiler-D2ZJc3uA.cjs} +3649 -283
- package/dist/core.cjs +6 -3
- package/dist/core.d.ts +2 -0
- package/dist/core.js +4 -4
- package/dist/defaults-B5ep0ojb.js +120 -0
- package/dist/defaults-BI9j1znS.cjs +156 -0
- package/dist/defaults.cjs +5 -121
- package/dist/defaults.js +1 -116
- package/dist/final-css-cleanup-B0HUBtiE.js +308 -0
- package/dist/final-css-cleanup-DSjczga3.cjs +138 -0
- package/dist/{generator-WlhrtNa3.cjs → generator-DsrQ9txU.cjs} +62 -5
- package/dist/{generator-BjK5PRR-.js → generator-DyXTBPmE.js} +47 -2
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/dist/{gulp-ChecVI6A.cjs → gulp-C9ENAx3f.cjs} +30 -28
- package/dist/{gulp-D6LcfRz_.js → gulp-DXeQfvVC.js} +7 -7
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-afnWvy7u.cjs → hmr-timing-Cz4IesEM.cjs} +6 -229
- package/dist/{hmr-timing-CqDfjvqE.js → hmr-timing-DNxQm-bN.js} +6 -1258
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/{pipeline-helpers-DxPFMGxz.cjs → pipeline-helpers-CSGnR5gh.cjs} +6 -5
- package/dist/postcss.cjs +1 -1
- package/dist/postcss.js +1 -1
- package/dist/presets.cjs +4 -4
- package/dist/presets.js +2 -2
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +2 -2
- package/dist/runtime-state-BBQcA0n5.cjs +54 -0
- package/dist/{source-candidate-scan-signature-FywFU3Rg.cjs → scoped-generator-TVjEaOeP.cjs} +5 -123
- package/dist/{source-candidate-scan-signature-BVScymyM.js → scoped-generator-kRj_5Axx.js} +4 -92
- package/dist/source-candidate-scan-signature-B7cUxqqX.cjs +129 -0
- package/dist/source-candidate-scan-signature-CsP4BQNa.js +92 -0
- package/dist/style-injector/internal.d.ts +1 -1
- package/dist/style-injector/vite-web.d.ts +3 -0
- package/dist/{tailwindcss-9xmoCkaR.js → tailwindcss-BK9S7zuq.js} +1 -2
- package/dist/{tailwindcss-D3jltF7M.cjs → tailwindcss-C-jBBQfw.cjs} +8 -9
- package/dist/{transform-DQhgAarN.js → transform-CfOzh007.js} +3 -3
- package/dist/{transform-C6k9zTQR.cjs → transform-DUPOPZ54.cjs} +27 -27
- package/dist/uni-app-x/vite/style-source.d.ts +11 -0
- package/dist/{v4-generation-core-CPKNwzjz.cjs → v4-generation-core-CRNUU_Rr.cjs} +29 -1172
- package/dist/vite/web.cjs +27 -0
- package/dist/vite/web.d.ts +1 -0
- package/dist/vite/web.js +25 -0
- package/dist/{vite-D3aCtpmv.js → vite-BXe-axax.js} +263 -3587
- package/dist/{vite-D-gmOkPN.cjs → vite-D_mAIfTU.cjs} +514 -3798
- package/dist/vite-web.d.ts +4 -0
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-generation-loader.cjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
- package/dist/web-B2Ea9K4B.cjs +4361 -0
- package/dist/web-Cv7ualrU.js +3796 -0
- package/dist/{webpack-B-6a8Z8F.js → webpack-7Um2GFtx.js} +13 -12
- package/dist/{webpack-yAne9ZYu.cjs → webpack-Ce04-btG.cjs} +51 -49
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +13 -4
- package/dist/cache-options-DavPxrhC.cjs +0 -16
- package/dist/cache-options-DwBtLwQe.js +0 -5
- package/dist/compiler-B-m9VGqj.cjs +0 -2316
- package/dist/compiler-BgMj2E5l.js +0 -2051
- package/dist/local-style-matcher-DRpFEu1s.cjs +0 -34
- package/dist/local-style-matcher-DsiI2wIc.js +0 -17
- package/dist/object-B-8IHefx.js +0 -47
- package/dist/object-DbHtAXRk.cjs +0 -58
- package/dist/wxml-CvKyV69S.js +0 -1822
|
@@ -0,0 +1,3796 @@
|
|
|
1
|
+
import { resolveImplicitAppTypeFromViteRoot } from "./framework.js";
|
|
2
|
+
import { $ as hasTailwindRootDirectives, O as resolveTailwindcssOptions, Q as hasTailwindNonRootGenerationDirectives, S as findNearestPackageRoot, W as normalizeEmptyTailwindCustomVariants, X as hasLocalCssImport, Z as hasTailwindApplyDirective, a as resolveGeneratorRuntimeBranch, at as removeTailwindSourceDirectives, b as isTailwindV4CssEntry, dt as hasTailwindGeneratedCssMarkers, et as hasTailwindSourceDirectives, ht as stripGeneratorPlaceholderMarkers, i as normalizeWeappTailwindcssGeneratorOptions, kt as resolveSourceScanPath, q as hasUserCssLayerBlocks, rt as normalizeTailwindSourceForGenerator, tt as normalizeTailwindConfigDirectives, ut as hasTailwindGeneratedCss } from "./generator-DyXTBPmE.js";
|
|
3
|
+
import { a as findTailwindConfig, f as resolveSourceScanEntries, l as getRuntimeClassSetSignature } from "./tailwindcss-BK9S7zuq.js";
|
|
4
|
+
import { B as createSourceCandidateCollector, C as isSourceStyleRequest, D as parseBundlerGeneratedCssMarkerBlocks, H as isSourceCandidateRequest, M as isCssSourceTraceEnabled, N as createRuntimeClassSetManager, O as stripBundlerGeneratedCssMarkers, T as createBundlerGeneratedCssMarker, W as createSourceCandidateEligibilityMatcher, g as captureFrameworkPostcssOptions, j as createCssTokenSourceMap, k as annotateCssSourceTrace, m as scoreTailwindV4CssSourceFileMatch, r as generateTailwindV4Css, t as createHmrTimingRecorder, w as stripRequestQuery, z as finalizeCompilerShadowRun } from "./hmr-timing-DNxQm-bN.js";
|
|
5
|
+
import { C as createTailwindRuntimeReadyPromise, K as createDebug, S as collectRuntimeClassSet, T as refreshTailwindRuntimeState, f as getCompilerContext, g as vitePluginName, i as disposeCompilerOwner, n as createRuntimeAffectingSourceSignature, p as normalizeStyleHandlerMajorVersion, t as createCompilerRuntimeState } from "./compiler-B0YSc0DY.js";
|
|
6
|
+
import { n as resolvePackageDir, o as normalizeStyleInjectorOptions, r as normalizeOutputPathKey, t as createSourceCandidateScanSignature } from "./source-candidate-scan-signature-CsP4BQNa.js";
|
|
7
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import process$1 from "node:process";
|
|
10
|
+
import { collectCssImportRequestsRoot, isMiniProgramLocalCssImportRequest, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolvePostcssConfig, transformWebCssCompat } from "@weapp-tailwindcss/postcss";
|
|
11
|
+
import { LRUCache } from "lru-cache";
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
13
|
+
import { cleanUrl as cleanUrl$1, ensurePosix } from "@weapp-tailwindcss/shared";
|
|
14
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
import { weappStyleInjector } from "weapp-style-injector/vite";
|
|
17
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
18
|
+
//#region src/bundlers/vite/capability-profile.ts
|
|
19
|
+
const frameworkViteCapabilityProfile = {
|
|
20
|
+
name: "framework",
|
|
21
|
+
frameworkName: "generic",
|
|
22
|
+
generatorTarget: void 0,
|
|
23
|
+
platformFamily: "unknown",
|
|
24
|
+
sourceCandidates: true,
|
|
25
|
+
frameworkExtras: true,
|
|
26
|
+
serveJsTransform: true,
|
|
27
|
+
styleInjector: true
|
|
28
|
+
};
|
|
29
|
+
function createGenericWebViteCapabilityProfile(options) {
|
|
30
|
+
return {
|
|
31
|
+
name: "generic-web",
|
|
32
|
+
cssOnly: true,
|
|
33
|
+
frameworkName: "generic",
|
|
34
|
+
generatorTarget: "web",
|
|
35
|
+
platformFamily: "web",
|
|
36
|
+
sourceCandidates: options.cssSourceTrace === true || typeof options.cssSourceTrace === "object",
|
|
37
|
+
frameworkExtras: false,
|
|
38
|
+
serveJsTransform: false,
|
|
39
|
+
styleInjector: options.styleInjector !== void 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/bundlers/vite/source-output-relations.ts
|
|
44
|
+
const activeRelationOwnerStorage = new AsyncLocalStorage();
|
|
45
|
+
function normalizeSourceFile(sourceFile) {
|
|
46
|
+
return normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, ""));
|
|
47
|
+
}
|
|
48
|
+
function normalizeOutputFile(outputFile) {
|
|
49
|
+
return normalizeOutputPathKey(outputFile);
|
|
50
|
+
}
|
|
51
|
+
function collectOwnedSources(output) {
|
|
52
|
+
if (output.type === "chunk") {
|
|
53
|
+
if (output.facadeModuleId) return [output.facadeModuleId];
|
|
54
|
+
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
55
|
+
return moduleIds.length === 1 ? moduleIds : [];
|
|
56
|
+
}
|
|
57
|
+
return [output.originalFileName, ...Array.isArray(output.originalFileNames) ? output.originalFileNames : []].filter((sourceFile) => typeof sourceFile === "string" && sourceFile.length > 0);
|
|
58
|
+
}
|
|
59
|
+
function createViteSourceOutputRelationOwner() {
|
|
60
|
+
const outputsBySource = /* @__PURE__ */ new Map();
|
|
61
|
+
const sourcesByOutput = /* @__PURE__ */ new Map();
|
|
62
|
+
const deletedSources = /* @__PURE__ */ new Set();
|
|
63
|
+
const dirtySources = /* @__PURE__ */ new Set();
|
|
64
|
+
const consumers = /* @__PURE__ */ new Set();
|
|
65
|
+
let disposed = false;
|
|
66
|
+
const unlinkSourceFromOutput = (sourceFile, outputFile) => {
|
|
67
|
+
const outputs = outputsBySource.get(sourceFile);
|
|
68
|
+
outputs?.delete(outputFile);
|
|
69
|
+
if (outputs?.size === 0) outputsBySource.delete(sourceFile);
|
|
70
|
+
const sources = sourcesByOutput.get(outputFile);
|
|
71
|
+
sources?.delete(sourceFile);
|
|
72
|
+
if (sources?.size === 0) sourcesByOutput.delete(outputFile);
|
|
73
|
+
};
|
|
74
|
+
const unlinkSource = (sourceFile) => {
|
|
75
|
+
const outputs = [...outputsBySource.get(sourceFile) ?? []];
|
|
76
|
+
for (const outputFile of outputs) unlinkSourceFromOutput(sourceFile, outputFile);
|
|
77
|
+
return outputs;
|
|
78
|
+
};
|
|
79
|
+
const queueRemovedOutputs = (outputFiles) => {
|
|
80
|
+
for (const outputFile of outputFiles) {
|
|
81
|
+
if (sourcesByOutput.has(outputFile)) continue;
|
|
82
|
+
for (const consumer of consumers) consumer.pending.add(outputFile);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const recordOwnedOutput = (sourceFile, outputFile) => {
|
|
86
|
+
if (disposed) return;
|
|
87
|
+
const sourceKey = normalizeSourceFile(sourceFile);
|
|
88
|
+
const outputKey = normalizeOutputFile(outputFile);
|
|
89
|
+
if (!sourceKey || !outputKey || deletedSources.has(sourceKey)) return;
|
|
90
|
+
if (dirtySources.delete(sourceKey)) queueRemovedOutputs(unlinkSource(sourceKey));
|
|
91
|
+
const outputs = outputsBySource.get(sourceKey) ?? /* @__PURE__ */ new Set();
|
|
92
|
+
outputs.add(outputKey);
|
|
93
|
+
outputsBySource.set(sourceKey, outputs);
|
|
94
|
+
const sources = sourcesByOutput.get(outputKey) ?? /* @__PURE__ */ new Set();
|
|
95
|
+
sources.add(sourceKey);
|
|
96
|
+
sourcesByOutput.set(outputKey, sources);
|
|
97
|
+
};
|
|
98
|
+
const replaceOutputOwners = (outputFile, sourceFiles) => {
|
|
99
|
+
const outputKey = normalizeOutputFile(outputFile);
|
|
100
|
+
for (const sourceFile of [...sourcesByOutput.get(outputKey) ?? []]) unlinkSourceFromOutput(sourceFile, outputKey);
|
|
101
|
+
for (const sourceFile of sourceFiles) {
|
|
102
|
+
deletedSources.delete(normalizeSourceFile(sourceFile));
|
|
103
|
+
recordOwnedOutput(sourceFile, outputKey);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
createRemovalConsumer() {
|
|
108
|
+
const state = { pending: /* @__PURE__ */ new Set() };
|
|
109
|
+
consumers.add(state);
|
|
110
|
+
return { consume(currentBundleFiles) {
|
|
111
|
+
if (disposed || state.pending.size === 0) return [];
|
|
112
|
+
const currentFiles = new Set([...currentBundleFiles].map(normalizeOutputFile));
|
|
113
|
+
const removedFiles = [...state.pending].filter((file) => !currentFiles.has(file));
|
|
114
|
+
state.pending.clear();
|
|
115
|
+
return removedFiles;
|
|
116
|
+
} };
|
|
117
|
+
},
|
|
118
|
+
dispose() {
|
|
119
|
+
disposed = true;
|
|
120
|
+
outputsBySource.clear();
|
|
121
|
+
sourcesByOutput.clear();
|
|
122
|
+
deletedSources.clear();
|
|
123
|
+
dirtySources.clear();
|
|
124
|
+
consumers.clear();
|
|
125
|
+
},
|
|
126
|
+
getStats() {
|
|
127
|
+
return {
|
|
128
|
+
consumers: consumers.size,
|
|
129
|
+
dirtySources: dirtySources.size,
|
|
130
|
+
outputs: sourcesByOutput.size,
|
|
131
|
+
pendingOutputs: new Set([...consumers].flatMap((consumer) => [...consumer.pending])).size,
|
|
132
|
+
sources: outputsBySource.size
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
getOutputSources(outputFile) {
|
|
136
|
+
return new Set(sourcesByOutput.get(normalizeOutputFile(outputFile)) ?? []);
|
|
137
|
+
},
|
|
138
|
+
getOwnedOutputs(sourceFile) {
|
|
139
|
+
return new Set(outputsBySource.get(normalizeSourceFile(sourceFile)) ?? []);
|
|
140
|
+
},
|
|
141
|
+
observeSource(sourceFile) {
|
|
142
|
+
if (!disposed) {
|
|
143
|
+
const sourceKey = normalizeSourceFile(sourceFile);
|
|
144
|
+
deletedSources.delete(sourceKey);
|
|
145
|
+
if (outputsBySource.has(sourceKey)) dirtySources.add(sourceKey);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
recordBundle(bundle) {
|
|
149
|
+
if (disposed) return;
|
|
150
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
151
|
+
const ownedSources = collectOwnedSources(output);
|
|
152
|
+
if (ownedSources.length > 0) replaceOutputOwners(output.fileName || bundleFile, ownedSources);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
recordOwnedOutput,
|
|
156
|
+
removeSource(sourceFile) {
|
|
157
|
+
if (disposed) return /* @__PURE__ */ new Set();
|
|
158
|
+
const sourceKey = normalizeSourceFile(sourceFile);
|
|
159
|
+
deletedSources.add(sourceKey);
|
|
160
|
+
dirtySources.delete(sourceKey);
|
|
161
|
+
const removedOutputs = /* @__PURE__ */ new Set();
|
|
162
|
+
for (const outputFile of unlinkSource(sourceKey)) if (!sourcesByOutput.has(outputFile)) removedOutputs.add(outputFile);
|
|
163
|
+
queueRemovedOutputs(removedOutputs);
|
|
164
|
+
return removedOutputs;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function getActiveViteSourceOutputRelationOwner() {
|
|
169
|
+
return activeRelationOwnerStorage.getStore();
|
|
170
|
+
}
|
|
171
|
+
function withViteSourceOutputRelationOwner(owner, run) {
|
|
172
|
+
return activeRelationOwnerStorage.run(owner, run);
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/bundlers/vite/css-asset-identity.ts
|
|
176
|
+
function createViteCssAssetIdentityResolver(options) {
|
|
177
|
+
const identityByAsset = /* @__PURE__ */ new WeakMap();
|
|
178
|
+
const placeholderFile = normalizeOutputPathKey(path.resolve(options.generatorPlaceholderFile));
|
|
179
|
+
return (asset, file) => {
|
|
180
|
+
const cached = identityByAsset.get(asset);
|
|
181
|
+
if (cached) return cached;
|
|
182
|
+
const candidates = [
|
|
183
|
+
file,
|
|
184
|
+
asset.originalFileName,
|
|
185
|
+
...asset.originalFileNames ?? []
|
|
186
|
+
].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
187
|
+
const placeholderSourceFile = candidates.find((candidate) => normalizeOutputPathKey(path.resolve(candidate.replace(/[?#].*$/, ""))) === placeholderFile);
|
|
188
|
+
let identity;
|
|
189
|
+
if (placeholderSourceFile) identity = {
|
|
190
|
+
kind: "generator-placeholder",
|
|
191
|
+
sourceFile: placeholderSourceFile
|
|
192
|
+
};
|
|
193
|
+
else {
|
|
194
|
+
const processedSourceFile = candidates.find(options.isKnownProcessedSource);
|
|
195
|
+
identity = processedSourceFile ? {
|
|
196
|
+
kind: "bundler-generated",
|
|
197
|
+
sourceFile: processedSourceFile
|
|
198
|
+
} : { kind: "user" };
|
|
199
|
+
}
|
|
200
|
+
identityByAsset.set(asset, identity);
|
|
201
|
+
return identity;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/bundlers/vite/css-handler-options.ts
|
|
206
|
+
function resolveViteCssHandlerExtraOptions(file) {
|
|
207
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, "")).includes("/") ? { isMainChunk: false } : {};
|
|
208
|
+
}
|
|
209
|
+
function createCssHandlerOptionsCache(options) {
|
|
210
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
211
|
+
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
212
|
+
const getCssHandlerOptions = (file) => {
|
|
213
|
+
const majorVersion = options.getMajorVersion();
|
|
214
|
+
const appType = options.getAppType();
|
|
215
|
+
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
216
|
+
const outputRoot = options.getOutputRoot?.();
|
|
217
|
+
const sourceFile = stripRequestQuery(file);
|
|
218
|
+
const from = path.isAbsolute(sourceFile) ? sourceFile : outputRoot ? path.resolve(outputRoot, sourceFile) : sourceFile;
|
|
219
|
+
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
220
|
+
const dynamicCssOptions = options.getDynamicCssOptions?.() ?? {};
|
|
221
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}:${JSON.stringify(dynamicCssOptions)}`;
|
|
222
|
+
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
223
|
+
if (cached) return cached;
|
|
224
|
+
const created = {
|
|
225
|
+
isMainChunk,
|
|
226
|
+
...extraOptions,
|
|
227
|
+
...dynamicCssOptions,
|
|
228
|
+
postcssOptions: { options: { from } },
|
|
229
|
+
majorVersion: normalizeStyleHandlerMajorVersion(majorVersion),
|
|
230
|
+
sourceOptions: {
|
|
231
|
+
outputRoot,
|
|
232
|
+
...sourceFile === file ? {} : { requestFile: file }
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
cssHandlerOptionsCache.set(cacheKey, created);
|
|
236
|
+
return created;
|
|
237
|
+
};
|
|
238
|
+
const getCssUserHandlerOptions = (file) => {
|
|
239
|
+
const majorVersion = options.getMajorVersion();
|
|
240
|
+
const outputRoot = options.getOutputRoot?.();
|
|
241
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${outputRoot ?? ""}:${file}`;
|
|
242
|
+
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
243
|
+
if (cached) return cached;
|
|
244
|
+
const created = {
|
|
245
|
+
...getCssHandlerOptions(file),
|
|
246
|
+
isMainChunk: false
|
|
247
|
+
};
|
|
248
|
+
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
249
|
+
return created;
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
getCssHandlerOptions,
|
|
253
|
+
getCssUserHandlerOptions
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/bundlers/vite/utils.ts
|
|
258
|
+
function slash(p) {
|
|
259
|
+
return ensurePosix(p);
|
|
260
|
+
}
|
|
261
|
+
const isWindows = process$1.platform === "win32";
|
|
262
|
+
const cssLangRE = new RegExp(`\\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)(?:$|\\?)`);
|
|
263
|
+
const htmlLangRE = /\.html?(?:$|\?)/;
|
|
264
|
+
function isCSSRequest(request) {
|
|
265
|
+
return cssLangRE.test(request) || isSourceStyleRequest(request);
|
|
266
|
+
}
|
|
267
|
+
function isWeappViteSidecarRequest(request) {
|
|
268
|
+
const queryIndex = request.indexOf("?");
|
|
269
|
+
if (queryIndex < 0) return false;
|
|
270
|
+
const hashIndex = request.indexOf("#", queryIndex);
|
|
271
|
+
const query = request.slice(queryIndex + 1, hashIndex < 0 ? void 0 : hashIndex);
|
|
272
|
+
return new URLSearchParams(query).has("weapp-vite-sidecar");
|
|
273
|
+
}
|
|
274
|
+
function resolveViteCssPipelineRequestFile(request) {
|
|
275
|
+
return isWeappViteSidecarRequest(request) ? cleanUrl$1(request) : request;
|
|
276
|
+
}
|
|
277
|
+
function isHTMLRequest(request) {
|
|
278
|
+
return htmlLangRE.test(request);
|
|
279
|
+
}
|
|
280
|
+
function normalizePath(id) {
|
|
281
|
+
return path.posix.normalize(isWindows ? ensurePosix(id) : id);
|
|
282
|
+
}
|
|
283
|
+
async function formatPostcssSourceMap(rawMap, file) {
|
|
284
|
+
const inputFileDir = path.dirname(file);
|
|
285
|
+
const sources = rawMap.sources.map((source) => {
|
|
286
|
+
const cleanSource = cleanUrl$1(decodeURIComponent(source));
|
|
287
|
+
if (cleanSource[0] === "<" && cleanSource.endsWith(">")) return `\0${cleanSource}`;
|
|
288
|
+
return normalizePath(path.resolve(inputFileDir, cleanSource));
|
|
289
|
+
});
|
|
290
|
+
return {
|
|
291
|
+
file,
|
|
292
|
+
mappings: rawMap.mappings,
|
|
293
|
+
names: rawMap.names,
|
|
294
|
+
sources,
|
|
295
|
+
sourcesContent: rawMap.sourcesContent,
|
|
296
|
+
version: rawMap.version
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/bundlers/vite/css-output.ts
|
|
301
|
+
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
302
|
+
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
303
|
+
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
304
|
+
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
305
|
+
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
306
|
+
".wxss",
|
|
307
|
+
".acss",
|
|
308
|
+
".ttss",
|
|
309
|
+
".qss",
|
|
310
|
+
".jxss",
|
|
311
|
+
".tyss"
|
|
312
|
+
];
|
|
313
|
+
function resolveCssOutputRealPath(value) {
|
|
314
|
+
const resolved = path.resolve(value);
|
|
315
|
+
let current = resolved;
|
|
316
|
+
const pendingSegments = [];
|
|
317
|
+
while (!existsSync(current)) {
|
|
318
|
+
const parent = path.dirname(current);
|
|
319
|
+
if (parent === current) return resolved;
|
|
320
|
+
pendingSegments.unshift(path.basename(current));
|
|
321
|
+
current = parent;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
const realPath = realpathSync.native(current);
|
|
325
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
326
|
+
} catch {
|
|
327
|
+
return resolved;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function normalizeStyleOutputExtension(value) {
|
|
331
|
+
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
332
|
+
const normalized = value.trim().toLowerCase();
|
|
333
|
+
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
334
|
+
}
|
|
335
|
+
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
336
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
337
|
+
if (!cssMatcher?.(cleanFile)) return;
|
|
338
|
+
const ext = path.extname(cleanFile);
|
|
339
|
+
if (!ext || ext === ".css") return;
|
|
340
|
+
return ext;
|
|
341
|
+
}
|
|
342
|
+
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
343
|
+
let extension;
|
|
344
|
+
for (const file of files ?? []) {
|
|
345
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
346
|
+
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
347
|
+
if (!matchedExtension) continue;
|
|
348
|
+
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
349
|
+
if (extension && extension !== matchedExtension) return;
|
|
350
|
+
extension = matchedExtension;
|
|
351
|
+
}
|
|
352
|
+
return extension;
|
|
353
|
+
}
|
|
354
|
+
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
355
|
+
if (!cssMatcher || !stem) return;
|
|
356
|
+
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
357
|
+
}
|
|
358
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
359
|
+
const cleanStem = normalizeOutputPathKey(stem);
|
|
360
|
+
const stemSuffix = `/${cleanStem}`;
|
|
361
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
362
|
+
for (const file of files ?? []) {
|
|
363
|
+
const cleanFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
364
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
365
|
+
const extension = path.extname(cleanFile);
|
|
366
|
+
if (!extension || extension === ".css") continue;
|
|
367
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
368
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
369
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
370
|
+
}
|
|
371
|
+
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
372
|
+
}
|
|
373
|
+
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
374
|
+
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
375
|
+
}
|
|
376
|
+
function resolveReplayCssOutputFile(rootDir, file) {
|
|
377
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
378
|
+
const nextFile = path.isAbsolute(cleanFile) ? path.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(cleanFile)) : cleanFile;
|
|
379
|
+
const normalizedFile = normalizeOutputPathKey(nextFile);
|
|
380
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(cleanFile));
|
|
381
|
+
return normalizedFile;
|
|
382
|
+
}
|
|
383
|
+
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
384
|
+
if (typeof sourceRoot !== "string" || sourceRoot.trim().length === 0) return;
|
|
385
|
+
return normalizeOutputPathKey(path.isAbsolute(sourceRoot) ? path.relative(rootDir, sourceRoot) : sourceRoot).replace(/\/+$/, "");
|
|
386
|
+
}
|
|
387
|
+
function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
388
|
+
const outputFile = resolveReplayCssOutputFile(rootDir, file);
|
|
389
|
+
const normalizedSourceRoot = normalizeViteSourceRoot(rootDir, sourceRoot);
|
|
390
|
+
if (!normalizedSourceRoot) return outputFile;
|
|
391
|
+
if (outputFile === normalizedSourceRoot) return path.posix.basename(outputFile);
|
|
392
|
+
if (outputFile.startsWith(`${normalizedSourceRoot}/`)) return outputFile.slice(normalizedSourceRoot.length + 1);
|
|
393
|
+
return outputFile;
|
|
394
|
+
}
|
|
395
|
+
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
396
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
397
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !isCSSRequest(file)) return cleanFile;
|
|
398
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
399
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
400
|
+
cssMatcher: opts.cssMatcher,
|
|
401
|
+
fallback: styleOutputExtension,
|
|
402
|
+
files: styleOutputFiles,
|
|
403
|
+
stem
|
|
404
|
+
}));
|
|
405
|
+
}
|
|
406
|
+
function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
407
|
+
const sourceStyleRequest = isCSSRequest(file);
|
|
408
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot).replace(/[?#].*$/, "");
|
|
409
|
+
const sourceExtension = path.extname(cleanFile);
|
|
410
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
411
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
412
|
+
return `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
413
|
+
cssMatcher: opts.cssMatcher,
|
|
414
|
+
fallback: styleOutputExtension,
|
|
415
|
+
files: styleOutputFiles,
|
|
416
|
+
stem
|
|
417
|
+
})}`;
|
|
418
|
+
}
|
|
419
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
420
|
+
const matchedStyleExtension = !isWebGeneratorTarget && !preserveCssExtension ? resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) : void 0;
|
|
421
|
+
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) && sourceStyleRequest) return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, matchedStyleExtension);
|
|
422
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
423
|
+
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
424
|
+
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(cleanFile)) return cleanFile;
|
|
425
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
426
|
+
}
|
|
427
|
+
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
428
|
+
const sourceStyleRequest = isCSSRequest(sourceFile);
|
|
429
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot).replace(/[?#].*$/, "");
|
|
430
|
+
const sourceExtension = path.extname(cleanFile);
|
|
431
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
432
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
433
|
+
return resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
434
|
+
cssMatcher: opts.cssMatcher,
|
|
435
|
+
fallback: styleOutputExtension,
|
|
436
|
+
files: styleOutputFiles,
|
|
437
|
+
stem
|
|
438
|
+
})}`;
|
|
439
|
+
}
|
|
440
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
441
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
442
|
+
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
443
|
+
if (matchedStyleFile) return matchedStyleFile;
|
|
444
|
+
const styleExtension = resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? resolveMiniProgramStyleOutputExtension({
|
|
445
|
+
cssMatcher: opts.cssMatcher,
|
|
446
|
+
fallback: styleOutputExtension,
|
|
447
|
+
files: styleOutputFiles,
|
|
448
|
+
stem
|
|
449
|
+
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
450
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
451
|
+
}
|
|
452
|
+
function canProcessViteSourceStyleAsCss(source, file) {
|
|
453
|
+
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
454
|
+
try {
|
|
455
|
+
postcss.parse(source, { from: file });
|
|
456
|
+
return true;
|
|
457
|
+
} catch {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function normalizeCssSourceForCompare(css) {
|
|
462
|
+
return css.trim();
|
|
463
|
+
}
|
|
464
|
+
function stripStyleFileExtension(file) {
|
|
465
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
466
|
+
const ext = path.extname(normalized);
|
|
467
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
471
|
+
let _lazyMatch = () => {
|
|
472
|
+
var __lib__ = (() => {
|
|
473
|
+
var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
|
|
474
|
+
for (var n in e) m(r, n, {
|
|
475
|
+
get: e[n],
|
|
476
|
+
enumerable: true
|
|
477
|
+
});
|
|
478
|
+
}, H = (r, e, n, a) => {
|
|
479
|
+
if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, {
|
|
480
|
+
get: () => e[t],
|
|
481
|
+
enumerable: !(a = V(e, t)) || a.enumerable
|
|
482
|
+
});
|
|
483
|
+
return r;
|
|
484
|
+
}, J = (r) => H(m({}, "__esModule", { value: true }), r), w = {};
|
|
485
|
+
q(w, { default: () => re });
|
|
486
|
+
var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => {
|
|
487
|
+
const e = /* @__PURE__ */ new Map();
|
|
488
|
+
return (n) => {
|
|
489
|
+
const a = e.get(n);
|
|
490
|
+
if (a) return a;
|
|
491
|
+
const t = r(n);
|
|
492
|
+
return e.set(n, t), t;
|
|
493
|
+
};
|
|
494
|
+
}, rr = (r, e, n = {}) => {
|
|
495
|
+
const a = {
|
|
496
|
+
cache: {},
|
|
497
|
+
input: r,
|
|
498
|
+
index: 0,
|
|
499
|
+
indexMax: 0,
|
|
500
|
+
options: n,
|
|
501
|
+
output: []
|
|
502
|
+
};
|
|
503
|
+
if (v(e)(a) && a.index === r.length) return a.output;
|
|
504
|
+
throw new Error(`Failed to parse at index ${a.indexMax}`);
|
|
505
|
+
}, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => {
|
|
506
|
+
const n = {};
|
|
507
|
+
for (const a of r) {
|
|
508
|
+
if (a.length !== 1) throw new Error(`Invalid character: "${a}"`);
|
|
509
|
+
const t = a.charCodeAt(0);
|
|
510
|
+
n[t] = true;
|
|
511
|
+
}
|
|
512
|
+
return (a) => {
|
|
513
|
+
const t = a.index, o = a.input;
|
|
514
|
+
for (; a.index < o.length && o.charCodeAt(a.index) in n;) a.index += 1;
|
|
515
|
+
const u = a.index;
|
|
516
|
+
if (u > t) {
|
|
517
|
+
if (!h(e) && !a.options.silent) {
|
|
518
|
+
const s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e;
|
|
519
|
+
h(c) || a.output.push(c);
|
|
520
|
+
}
|
|
521
|
+
a.indexMax = Math.max(a.indexMax, a.index);
|
|
522
|
+
}
|
|
523
|
+
return true;
|
|
524
|
+
};
|
|
525
|
+
}, nr = (r, e) => {
|
|
526
|
+
const n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a);
|
|
527
|
+
return g((o) => {
|
|
528
|
+
t.lastIndex = o.index;
|
|
529
|
+
const u = t.exec(o.input);
|
|
530
|
+
if (u) {
|
|
531
|
+
if (!h(e) && !o.options.silent) {
|
|
532
|
+
const s = d(e) ? e(...u, o.input, String(o.index)) : e;
|
|
533
|
+
h(s) || o.output.push(s);
|
|
534
|
+
}
|
|
535
|
+
return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), true;
|
|
536
|
+
} else return false;
|
|
537
|
+
});
|
|
538
|
+
}, ar = (r, e) => (n) => {
|
|
539
|
+
if (n.input.startsWith(r, n.index)) {
|
|
540
|
+
if (!h(e) && !n.options.silent) {
|
|
541
|
+
const t = d(e) ? e(r, n.input, String(n.index)) : e;
|
|
542
|
+
h(t) || n.output.push(t);
|
|
543
|
+
}
|
|
544
|
+
return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), true;
|
|
545
|
+
} else return false;
|
|
546
|
+
}, C = (r, e, n, a) => {
|
|
547
|
+
const t = v(r);
|
|
548
|
+
return g(_(M((o) => {
|
|
549
|
+
let u = 0;
|
|
550
|
+
for (; u < n;) {
|
|
551
|
+
const s = o.index;
|
|
552
|
+
if (!t(o) || (u += 1, o.index === s)) break;
|
|
553
|
+
}
|
|
554
|
+
return u >= e;
|
|
555
|
+
})));
|
|
556
|
+
}, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, 1 / 0), x = (r, e) => {
|
|
557
|
+
const n = r.map(v);
|
|
558
|
+
return g(_(M((a) => {
|
|
559
|
+
for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return false;
|
|
560
|
+
return true;
|
|
561
|
+
})));
|
|
562
|
+
}, l = (r, e) => {
|
|
563
|
+
const n = r.map(v);
|
|
564
|
+
return g(_((a) => {
|
|
565
|
+
for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return true;
|
|
566
|
+
return false;
|
|
567
|
+
}));
|
|
568
|
+
}, M = (r, e = false) => {
|
|
569
|
+
const n = v(r);
|
|
570
|
+
return (a) => {
|
|
571
|
+
const t = a.index, o = a.output.length, u = n(a);
|
|
572
|
+
return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u;
|
|
573
|
+
};
|
|
574
|
+
}, _ = (r, e) => {
|
|
575
|
+
return v(r);
|
|
576
|
+
}, g = (() => {
|
|
577
|
+
let r = 0;
|
|
578
|
+
return (e) => {
|
|
579
|
+
const n = v(e), a = r += 1;
|
|
580
|
+
return (t) => {
|
|
581
|
+
var o;
|
|
582
|
+
if (t.options.memoization === false) return n(t);
|
|
583
|
+
const u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u);
|
|
584
|
+
if (c === false) return false;
|
|
585
|
+
if (W(c)) return t.index = c, true;
|
|
586
|
+
if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), true;
|
|
587
|
+
{
|
|
588
|
+
const Z = t.output.length;
|
|
589
|
+
if (n(t)) {
|
|
590
|
+
const D = t.index, U = t.output.length;
|
|
591
|
+
if (U > Z) {
|
|
592
|
+
const ee = t.output.slice(Z, U);
|
|
593
|
+
s.set(u, {
|
|
594
|
+
index: D,
|
|
595
|
+
output: ee
|
|
596
|
+
});
|
|
597
|
+
} else s.set(u, D);
|
|
598
|
+
return true;
|
|
599
|
+
} else return s.set(u, false), false;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
})(), E = (r) => {
|
|
604
|
+
let e;
|
|
605
|
+
return (n) => (e || (e = v(r())), e(n));
|
|
606
|
+
}, v = Y((r) => {
|
|
607
|
+
if (d(r)) return Q(r) ? E(r) : r;
|
|
608
|
+
if (b(r) || X(r)) return i(r);
|
|
609
|
+
if (A(r)) return x(r);
|
|
610
|
+
if (K(r)) return l(Object.values(r));
|
|
611
|
+
throw new Error("Invalid rule");
|
|
612
|
+
}), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => {
|
|
613
|
+
let e = "";
|
|
614
|
+
for (; r > 0;) e = P[(r - 1) % 26] + e, r = Math.floor((r - 1) / 26);
|
|
615
|
+
return e;
|
|
616
|
+
}, O = (r) => {
|
|
617
|
+
let e = 0;
|
|
618
|
+
for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1;
|
|
619
|
+
return e;
|
|
620
|
+
}, S = (r, e) => {
|
|
621
|
+
if (e < r) return S(e, r);
|
|
622
|
+
const n = [];
|
|
623
|
+
for (; r <= e;) n.push(r++);
|
|
624
|
+
return n;
|
|
625
|
+
}, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: false }).join("")), ur = (r) => {
|
|
626
|
+
const e = {};
|
|
627
|
+
return (n) => e[n] ?? (e[n] = r(n));
|
|
628
|
+
}, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), fr = l([i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), i(/^(!!)+/, "")]), j = l([
|
|
629
|
+
i(/\/(\*\*\/)+/, "(?:/.+/|/)"),
|
|
630
|
+
i(/^(\*\*\/)+/, "(?:^|.*/)"),
|
|
631
|
+
i(/\/(\*\*)$/, "(?:/.*|$)"),
|
|
632
|
+
i(/\*\*/, ".*")
|
|
633
|
+
]), N = l([i(/\*\/(?!\*\*\/)/, "[^/]*/"), i(/\*/, "[^/]*")]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Er = l([
|
|
634
|
+
y,
|
|
635
|
+
i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`),
|
|
636
|
+
br,
|
|
637
|
+
i(/[^\]]/, p)
|
|
638
|
+
]), B = x([
|
|
639
|
+
$r,
|
|
640
|
+
tr(Ar),
|
|
641
|
+
f(Er),
|
|
642
|
+
wr
|
|
643
|
+
]), Pr = i("{", "(?:"), Or = i("}", ")"), I = x([
|
|
644
|
+
Pr,
|
|
645
|
+
l([
|
|
646
|
+
i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")),
|
|
647
|
+
i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")),
|
|
648
|
+
i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase())
|
|
649
|
+
]),
|
|
650
|
+
Or
|
|
651
|
+
]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), F = x([
|
|
652
|
+
kr,
|
|
653
|
+
f(l([
|
|
654
|
+
j,
|
|
655
|
+
N,
|
|
656
|
+
k,
|
|
657
|
+
B,
|
|
658
|
+
I,
|
|
659
|
+
E(() => F),
|
|
660
|
+
y,
|
|
661
|
+
Fr,
|
|
662
|
+
Ir,
|
|
663
|
+
Lr
|
|
664
|
+
])),
|
|
665
|
+
Br
|
|
666
|
+
]), L = z(f(l([
|
|
667
|
+
sr,
|
|
668
|
+
cr,
|
|
669
|
+
lr,
|
|
670
|
+
fr,
|
|
671
|
+
j,
|
|
672
|
+
N,
|
|
673
|
+
k,
|
|
674
|
+
B,
|
|
675
|
+
I,
|
|
676
|
+
F,
|
|
677
|
+
y,
|
|
678
|
+
pr,
|
|
679
|
+
vr
|
|
680
|
+
]))), Tr = i(/\\./, p), qr = i(/./, p), Yr = z(f(l([
|
|
681
|
+
Tr,
|
|
682
|
+
i(/\*\*\*+/, "*"),
|
|
683
|
+
i(/([^/{[(!])\*\*/, (r, e) => `${e}*`),
|
|
684
|
+
i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`),
|
|
685
|
+
qr
|
|
686
|
+
]))), $ = (r, e) => {
|
|
687
|
+
const n = Array.isArray(r) ? r : [r];
|
|
688
|
+
if (!n.length) return false;
|
|
689
|
+
const a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : "");
|
|
690
|
+
return a.some((s) => s.test(o));
|
|
691
|
+
};
|
|
692
|
+
$.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s");
|
|
693
|
+
var re = $;
|
|
694
|
+
return J(w);
|
|
695
|
+
})();
|
|
696
|
+
return __lib__.default || __lib__;
|
|
697
|
+
};
|
|
698
|
+
let _match;
|
|
699
|
+
const zeptomatch = (path, pattern) => {
|
|
700
|
+
if (!_match) {
|
|
701
|
+
_match = _lazyMatch();
|
|
702
|
+
_lazyMatch = null;
|
|
703
|
+
}
|
|
704
|
+
return _match(path, pattern);
|
|
705
|
+
};
|
|
706
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
707
|
+
function normalizeWindowsPath(input = "") {
|
|
708
|
+
if (!input) return input;
|
|
709
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
710
|
+
}
|
|
711
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
712
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
713
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
714
|
+
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
715
|
+
const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
716
|
+
const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
717
|
+
const normalize = function(path) {
|
|
718
|
+
if (path.length === 0) return ".";
|
|
719
|
+
path = normalizeWindowsPath(path);
|
|
720
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
721
|
+
const isPathAbsolute = isAbsolute(path);
|
|
722
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
723
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
724
|
+
if (path.length === 0) {
|
|
725
|
+
if (isPathAbsolute) return "/";
|
|
726
|
+
return trailingSeparator ? "./" : ".";
|
|
727
|
+
}
|
|
728
|
+
if (trailingSeparator) path += "/";
|
|
729
|
+
if (_DRIVE_LETTER_RE.test(path)) path += "/";
|
|
730
|
+
if (isUNCPath) {
|
|
731
|
+
if (!isPathAbsolute) return `//./${path}`;
|
|
732
|
+
return `//${path}`;
|
|
733
|
+
}
|
|
734
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
735
|
+
};
|
|
736
|
+
const join = function(...segments) {
|
|
737
|
+
let path = "";
|
|
738
|
+
for (const seg of segments) {
|
|
739
|
+
if (!seg) continue;
|
|
740
|
+
if (path.length > 0) {
|
|
741
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
742
|
+
const segLeading = seg[0] === "/";
|
|
743
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
744
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
745
|
+
} else path += seg;
|
|
746
|
+
}
|
|
747
|
+
return normalize(path);
|
|
748
|
+
};
|
|
749
|
+
function cwd() {
|
|
750
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
751
|
+
return "/";
|
|
752
|
+
}
|
|
753
|
+
const resolve = function(...arguments_) {
|
|
754
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
755
|
+
let resolvedPath = "";
|
|
756
|
+
let resolvedAbsolute = false;
|
|
757
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
758
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
759
|
+
if (!path || path.length === 0) continue;
|
|
760
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
761
|
+
resolvedAbsolute = isAbsolute(path);
|
|
762
|
+
}
|
|
763
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
764
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
|
|
765
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
766
|
+
};
|
|
767
|
+
function normalizeString(path, allowAboveRoot) {
|
|
768
|
+
let res = "";
|
|
769
|
+
let lastSegmentLength = 0;
|
|
770
|
+
let lastSlash = -1;
|
|
771
|
+
let dots = 0;
|
|
772
|
+
let char = null;
|
|
773
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
774
|
+
if (index < path.length) char = path[index];
|
|
775
|
+
else if (char === "/") break;
|
|
776
|
+
else char = "/";
|
|
777
|
+
if (char === "/") {
|
|
778
|
+
if (lastSlash === index - 1 || dots === 1);
|
|
779
|
+
else if (dots === 2) {
|
|
780
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
781
|
+
if (res.length > 2) {
|
|
782
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
783
|
+
if (lastSlashIndex === -1) {
|
|
784
|
+
res = "";
|
|
785
|
+
lastSegmentLength = 0;
|
|
786
|
+
} else {
|
|
787
|
+
res = res.slice(0, lastSlashIndex);
|
|
788
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
789
|
+
}
|
|
790
|
+
lastSlash = index;
|
|
791
|
+
dots = 0;
|
|
792
|
+
continue;
|
|
793
|
+
} else if (res.length > 0) {
|
|
794
|
+
res = "";
|
|
795
|
+
lastSegmentLength = 0;
|
|
796
|
+
lastSlash = index;
|
|
797
|
+
dots = 0;
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (allowAboveRoot) {
|
|
802
|
+
res += res.length > 0 ? "/.." : "..";
|
|
803
|
+
lastSegmentLength = 2;
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
807
|
+
else res = path.slice(lastSlash + 1, index);
|
|
808
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
809
|
+
}
|
|
810
|
+
lastSlash = index;
|
|
811
|
+
dots = 0;
|
|
812
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
813
|
+
else dots = -1;
|
|
814
|
+
}
|
|
815
|
+
return res;
|
|
816
|
+
}
|
|
817
|
+
const isAbsolute = function(p) {
|
|
818
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
819
|
+
};
|
|
820
|
+
const toNamespacedPath = function(p) {
|
|
821
|
+
return normalizeWindowsPath(p);
|
|
822
|
+
};
|
|
823
|
+
const extname = function(p) {
|
|
824
|
+
if (p === "..") return "";
|
|
825
|
+
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
826
|
+
return match && match[1] || "";
|
|
827
|
+
};
|
|
828
|
+
const relative = function(from, to) {
|
|
829
|
+
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
830
|
+
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
831
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
|
|
832
|
+
const _fromCopy = [..._from];
|
|
833
|
+
for (const segment of _fromCopy) {
|
|
834
|
+
if (_to[0] !== segment) break;
|
|
835
|
+
_from.shift();
|
|
836
|
+
_to.shift();
|
|
837
|
+
}
|
|
838
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
839
|
+
};
|
|
840
|
+
const dirname = function(p) {
|
|
841
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
842
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
843
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
844
|
+
};
|
|
845
|
+
const format = function(p) {
|
|
846
|
+
const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
|
|
847
|
+
const segments = [
|
|
848
|
+
p.root,
|
|
849
|
+
p.dir,
|
|
850
|
+
p.base ?? (p.name ?? "") + ext
|
|
851
|
+
].filter(Boolean);
|
|
852
|
+
return normalizeWindowsPath(p.root ? resolve(...segments) : segments.join("/"));
|
|
853
|
+
};
|
|
854
|
+
const basename = function(p, extension) {
|
|
855
|
+
const segments = normalizeWindowsPath(p).split("/");
|
|
856
|
+
let lastSegment = "";
|
|
857
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
858
|
+
const val = segments[i];
|
|
859
|
+
if (val) {
|
|
860
|
+
lastSegment = val;
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
865
|
+
};
|
|
866
|
+
const parse = function(p) {
|
|
867
|
+
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
868
|
+
const base = basename(p);
|
|
869
|
+
const extension = extname(base);
|
|
870
|
+
return {
|
|
871
|
+
root,
|
|
872
|
+
dir: dirname(p),
|
|
873
|
+
base,
|
|
874
|
+
ext: extension,
|
|
875
|
+
name: base.slice(0, base.length - extension.length)
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
const matchesGlob = (path, pattern) => {
|
|
879
|
+
return zeptomatch(pattern, normalize(path));
|
|
880
|
+
};
|
|
881
|
+
const _path = {
|
|
882
|
+
__proto__: null,
|
|
883
|
+
basename,
|
|
884
|
+
dirname,
|
|
885
|
+
extname,
|
|
886
|
+
format,
|
|
887
|
+
isAbsolute,
|
|
888
|
+
join,
|
|
889
|
+
matchesGlob,
|
|
890
|
+
normalize,
|
|
891
|
+
normalizeString,
|
|
892
|
+
parse,
|
|
893
|
+
relative,
|
|
894
|
+
resolve,
|
|
895
|
+
sep: "/",
|
|
896
|
+
toNamespacedPath
|
|
897
|
+
};
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
|
|
900
|
+
const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
|
901
|
+
const _platforms = {
|
|
902
|
+
posix: void 0,
|
|
903
|
+
win32: void 0
|
|
904
|
+
};
|
|
905
|
+
const mix = (del = delimiter) => {
|
|
906
|
+
return new Proxy(_path, { get(_, prop) {
|
|
907
|
+
if (prop === "delimiter") return del;
|
|
908
|
+
if (prop === "posix") return posix;
|
|
909
|
+
if (prop === "win32") return win32;
|
|
910
|
+
return _platforms[prop] || _path[prop];
|
|
911
|
+
} });
|
|
912
|
+
};
|
|
913
|
+
const posix = /* @__PURE__ */ mix(":");
|
|
914
|
+
const win32 = /* @__PURE__ */ mix(";");
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/bundlers/vite/processed-css-assets/style-files.ts
|
|
917
|
+
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
918
|
+
function isCssOutputFile(file) {
|
|
919
|
+
return CSS_OUTPUT_FILE_RE.test(file);
|
|
920
|
+
}
|
|
921
|
+
function isRootStyleOutputFile(file) {
|
|
922
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
923
|
+
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
924
|
+
}
|
|
925
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
926
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
927
|
+
}
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/bundlers/vite/processed-css-assets/markers-imports.ts
|
|
930
|
+
function createCssAssetPipelineContext(options, file, bundle) {
|
|
931
|
+
const context = options.createCssPipelineContext?.(file);
|
|
932
|
+
return context ? {
|
|
933
|
+
...context,
|
|
934
|
+
bundle
|
|
935
|
+
} : void 0;
|
|
936
|
+
}
|
|
937
|
+
function getAssetFile(bundleFile, asset) {
|
|
938
|
+
return asset.fileName || bundleFile;
|
|
939
|
+
}
|
|
940
|
+
function readAssetSource$1(asset) {
|
|
941
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
942
|
+
}
|
|
943
|
+
function clearAssetSource(asset) {
|
|
944
|
+
asset.source = "";
|
|
945
|
+
}
|
|
946
|
+
function appendCss(baseCss, css) {
|
|
947
|
+
if (baseCss.length === 0) return css;
|
|
948
|
+
if (css.length === 0) return baseCss;
|
|
949
|
+
return `${baseCss}\n${css}`;
|
|
950
|
+
}
|
|
951
|
+
function normalizeCssRecordIdentity(css) {
|
|
952
|
+
return css.trim();
|
|
953
|
+
}
|
|
954
|
+
function hasNonCommentCss(css) {
|
|
955
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").trim().length > 0;
|
|
956
|
+
}
|
|
957
|
+
function dedupeViteCssResults(records) {
|
|
958
|
+
const seen = /* @__PURE__ */ new Set();
|
|
959
|
+
return records.filter((record) => {
|
|
960
|
+
const key = `${normalizeOutputPathKey(record.outputFile ?? "")}\0${normalizeCssRecordIdentity(record.css)}`;
|
|
961
|
+
if (seen.has(key)) return false;
|
|
962
|
+
seen.add(key);
|
|
963
|
+
return true;
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
967
|
+
let changed = false;
|
|
968
|
+
root.walkAtRules("media", (atRule) => {
|
|
969
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
970
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
971
|
+
else atRule.remove();
|
|
972
|
+
changed = true;
|
|
973
|
+
});
|
|
974
|
+
if (changed) root.walkAtRules((atRule) => {
|
|
975
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
976
|
+
});
|
|
977
|
+
return changed;
|
|
978
|
+
}
|
|
979
|
+
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
980
|
+
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
981
|
+
}
|
|
982
|
+
function removeTailwindEntryDirectivesFromCss(css) {
|
|
983
|
+
try {
|
|
984
|
+
const source = stripGeneratorPlaceholderMarkers(css);
|
|
985
|
+
const root = postcss.parse(source);
|
|
986
|
+
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
987
|
+
const removedTailwindDirectives = removeTailwindSourceDirectivesRoot(root);
|
|
988
|
+
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
989
|
+
} catch {
|
|
990
|
+
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
994
|
+
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
995
|
+
return css.split(/\r?\n/).filter((line) => {
|
|
996
|
+
const trimmed = line.trim();
|
|
997
|
+
if (!trimmed.startsWith("@import")) return true;
|
|
998
|
+
const params = trimmed.slice(7).trim().replace(/;$/, "").trim();
|
|
999
|
+
const request = parseTailwindCssDirectiveRequest(params);
|
|
1000
|
+
return request === void 0 || isMiniProgramLocalCssImportRequest(request);
|
|
1001
|
+
}).join("\n");
|
|
1002
|
+
}
|
|
1003
|
+
function normalizeInjectableCssForTarget(css, file) {
|
|
1004
|
+
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
1005
|
+
}
|
|
1006
|
+
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
1007
|
+
if (!css.includes("@import")) return {
|
|
1008
|
+
css,
|
|
1009
|
+
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
1010
|
+
};
|
|
1011
|
+
try {
|
|
1012
|
+
const root = postcss.parse(css);
|
|
1013
|
+
const changed = isMiniProgramStyleOutputFile(file) ? removeUnsupportedMiniProgramCssImportsRoot(root) : false;
|
|
1014
|
+
const importedStyleFiles = collectImportedStyleFilesRoot(root, file);
|
|
1015
|
+
return {
|
|
1016
|
+
css: changed ? root.toString() : css,
|
|
1017
|
+
importedStyleFiles: importedStyleFiles.size > 0 ? importedStyleFiles : collectImportedStyleFilesFallback(css, file)
|
|
1018
|
+
};
|
|
1019
|
+
} catch {
|
|
1020
|
+
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
1021
|
+
return {
|
|
1022
|
+
css: fallbackCss,
|
|
1023
|
+
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function stripStyleExtension(file) {
|
|
1028
|
+
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
1029
|
+
}
|
|
1030
|
+
function isStyleImportRequest(request) {
|
|
1031
|
+
return typeof request === "string" && request.length > 0 && !/^(?:https?:)?\/\//i.test(request) && /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(request);
|
|
1032
|
+
}
|
|
1033
|
+
function resolveImportedStyleFile(targetFile, request) {
|
|
1034
|
+
if (!isStyleImportRequest(request)) return;
|
|
1035
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
1036
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
1037
|
+
const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
1038
|
+
return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1039
|
+
}
|
|
1040
|
+
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
1041
|
+
const imports = /* @__PURE__ */ new Set();
|
|
1042
|
+
for (const request of requests) {
|
|
1043
|
+
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
1044
|
+
if (importedFile) imports.add(importedFile);
|
|
1045
|
+
}
|
|
1046
|
+
return imports;
|
|
1047
|
+
}
|
|
1048
|
+
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
1049
|
+
return collectImportedStyleFilesFromRequests(collectCssImportRequestsRoot(root), targetFile);
|
|
1050
|
+
}
|
|
1051
|
+
function collectImportedStyleFilesFallback(css, targetFile) {
|
|
1052
|
+
return collectImportedStyleFilesFromRequests([...css.matchAll(/@import\s+(?:url\(\s*)?(?:"([^"]+)"|'([^']+)'|([^\s;)]+))/g)].map((match) => match[1] ?? match[2] ?? match[3]).filter((request) => typeof request === "string" && request.length > 0), targetFile);
|
|
1053
|
+
}
|
|
1054
|
+
function collectImportedStyleFiles(css, targetFile) {
|
|
1055
|
+
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
1056
|
+
try {
|
|
1057
|
+
const imports = collectImportedStyleFilesRoot(postcss.parse(css), targetFile);
|
|
1058
|
+
return imports.size > 0 ? imports : collectImportedStyleFilesFallback(css, targetFile);
|
|
1059
|
+
} catch {}
|
|
1060
|
+
return collectImportedStyleFilesFallback(css, targetFile);
|
|
1061
|
+
}
|
|
1062
|
+
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
1063
|
+
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
1064
|
+
}
|
|
1065
|
+
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
1066
|
+
if (!markerFile) return false;
|
|
1067
|
+
return normalizeOutputPathKey(stripStyleExtension(targetFile)) === normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
1068
|
+
}
|
|
1069
|
+
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1070
|
+
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1071
|
+
if (blocks.length <= 1) return stripBundlerGeneratedCssMarkers(rawSource);
|
|
1072
|
+
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1073
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : stripBundlerGeneratedCssMarkers(rawSource);
|
|
1074
|
+
}
|
|
1075
|
+
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1076
|
+
return parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
1077
|
+
}
|
|
1078
|
+
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1079
|
+
const sources = [];
|
|
1080
|
+
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
1081
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1082
|
+
if (output.type !== "asset") continue;
|
|
1083
|
+
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
1084
|
+
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1085
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$1(output)).trim();
|
|
1086
|
+
if (source.length > 0) sources.push(source);
|
|
1087
|
+
}
|
|
1088
|
+
return sources;
|
|
1089
|
+
}
|
|
1090
|
+
function isHtmlOutputFile(file) {
|
|
1091
|
+
return /\.html(?:$|[?#])/i.test(file);
|
|
1092
|
+
}
|
|
1093
|
+
function stripQueryAndHash(file) {
|
|
1094
|
+
return file.replace(/[?#].*$/, "");
|
|
1095
|
+
}
|
|
1096
|
+
function resolveHtmlLinkedStyleFile(htmlFile, request) {
|
|
1097
|
+
if (!isStyleImportRequest(request)) return;
|
|
1098
|
+
const cleanRequest = stripQueryAndHash(request);
|
|
1099
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
1100
|
+
const htmlDir = posix.posix.dirname(normalizeOutputPathKey(stripQueryAndHash(htmlFile)));
|
|
1101
|
+
return normalizeOutputPathKey(posix.posix.join(htmlDir === "." ? "" : htmlDir, cleanRequest));
|
|
1102
|
+
}
|
|
1103
|
+
function collectHtmlLinkedStyleFiles(bundle) {
|
|
1104
|
+
const linkedFiles = /* @__PURE__ */ new Set();
|
|
1105
|
+
const linkedBasenames = /* @__PURE__ */ new Set();
|
|
1106
|
+
const linkHrefRE = /<link\s[^>]*href\s*=\s*(["'])([^"']+)\1[^>]*>/gi;
|
|
1107
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1108
|
+
if (output.type !== "asset") continue;
|
|
1109
|
+
const htmlFile = getAssetFile(bundleFile, output);
|
|
1110
|
+
if (!isHtmlOutputFile(htmlFile)) continue;
|
|
1111
|
+
const html = readAssetSource$1(output);
|
|
1112
|
+
for (const match of html.matchAll(linkHrefRE)) {
|
|
1113
|
+
const href = match[2];
|
|
1114
|
+
if (!href) continue;
|
|
1115
|
+
const linkedFile = resolveHtmlLinkedStyleFile(htmlFile, href);
|
|
1116
|
+
if (!linkedFile || !isRootStyleOutputFile(linkedFile)) continue;
|
|
1117
|
+
linkedFiles.add(linkedFile);
|
|
1118
|
+
linkedBasenames.add(posix.posix.basename(linkedFile));
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return {
|
|
1122
|
+
linkedBasenames,
|
|
1123
|
+
linkedFiles
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function isLinkedStyleFile(file, linked) {
|
|
1127
|
+
const fileKey = normalizeOutputPathKey(stripQueryAndHash(file));
|
|
1128
|
+
return linked.linkedFiles.has(fileKey) || isRootStyleOutputFile(fileKey) && linked.linkedBasenames.has(posix.posix.basename(fileKey));
|
|
1129
|
+
}
|
|
1130
|
+
function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options = {}) {
|
|
1131
|
+
const linked = collectHtmlLinkedStyleFiles(bundle);
|
|
1132
|
+
if (linked.linkedFiles.size === 0 && linked.linkedBasenames.size === 0) return 0;
|
|
1133
|
+
const linkedSources = /* @__PURE__ */ new Set();
|
|
1134
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1135
|
+
if (output.type !== "asset") continue;
|
|
1136
|
+
const file = getAssetFile(bundleFile, output);
|
|
1137
|
+
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
1138
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$1(output)).trim();
|
|
1139
|
+
if (source.length > 0) linkedSources.add(source);
|
|
1140
|
+
}
|
|
1141
|
+
if (linkedSources.size === 0) return 0;
|
|
1142
|
+
let removed = 0;
|
|
1143
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1144
|
+
if (output.type !== "asset") continue;
|
|
1145
|
+
const file = getAssetFile(bundleFile, output);
|
|
1146
|
+
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
1147
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$1(output)).trim();
|
|
1148
|
+
if (!linkedSources.has(source)) continue;
|
|
1149
|
+
delete bundle[bundleFile];
|
|
1150
|
+
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
1151
|
+
removed++;
|
|
1152
|
+
}
|
|
1153
|
+
return removed;
|
|
1154
|
+
}
|
|
1155
|
+
//#endregion
|
|
1156
|
+
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
1157
|
+
function resolveStyleMatchingRealPath(value) {
|
|
1158
|
+
const resolved = path.resolve(value);
|
|
1159
|
+
let current = resolved;
|
|
1160
|
+
const pendingSegments = [];
|
|
1161
|
+
while (!existsSync(current)) {
|
|
1162
|
+
const parent = path.dirname(current);
|
|
1163
|
+
if (parent === current) return resolved;
|
|
1164
|
+
pendingSegments.unshift(path.basename(current));
|
|
1165
|
+
current = parent;
|
|
1166
|
+
}
|
|
1167
|
+
try {
|
|
1168
|
+
const realPath = realpathSync.native(current);
|
|
1169
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
1170
|
+
} catch {
|
|
1171
|
+
return resolved;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
1175
|
+
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
1176
|
+
}
|
|
1177
|
+
function collectStyleFileMatchBases(file, roots) {
|
|
1178
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1179
|
+
const bases = /* @__PURE__ */ new Set();
|
|
1180
|
+
const addBase = (candidate) => {
|
|
1181
|
+
const base = slash(stripStyleFileExtension(candidate));
|
|
1182
|
+
if (base.length > 0) bases.add(base);
|
|
1183
|
+
};
|
|
1184
|
+
addBase(normalizedFile);
|
|
1185
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
1186
|
+
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
1187
|
+
const relative = path.relative(resolveStyleMatchingRealPath(root), resolveStyleMatchingRealPath(normalizedFile));
|
|
1188
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
1189
|
+
}
|
|
1190
|
+
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
1191
|
+
return bases;
|
|
1192
|
+
}
|
|
1193
|
+
function collectParentDirectories(file) {
|
|
1194
|
+
const directories = [];
|
|
1195
|
+
let current = path.dirname(path.resolve(file.replace(/[?#].*$/, "")));
|
|
1196
|
+
while (true) {
|
|
1197
|
+
directories.push(current);
|
|
1198
|
+
const parent = path.dirname(current);
|
|
1199
|
+
if (parent === current) break;
|
|
1200
|
+
current = parent;
|
|
1201
|
+
}
|
|
1202
|
+
return directories;
|
|
1203
|
+
}
|
|
1204
|
+
function hasMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
1205
|
+
return scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) > 0;
|
|
1206
|
+
}
|
|
1207
|
+
function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
1208
|
+
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
1209
|
+
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
1210
|
+
let bestScore = 0;
|
|
1211
|
+
const hasDirectorySegment = (value) => slash(value).includes("/");
|
|
1212
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
1213
|
+
else if (hasDirectorySegment(sourceBase) && outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
1214
|
+
else if (hasDirectorySegment(outputBase) && sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
1215
|
+
return bestScore;
|
|
1216
|
+
}
|
|
1217
|
+
//#endregion
|
|
1218
|
+
//#region src/bundlers/vite/generate-bundle/sfc-style-source.ts
|
|
1219
|
+
const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
1220
|
+
".vue",
|
|
1221
|
+
".uvue",
|
|
1222
|
+
".nvue",
|
|
1223
|
+
".svelte",
|
|
1224
|
+
".mpx"
|
|
1225
|
+
];
|
|
1226
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1227
|
+
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1228
|
+
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1229
|
+
function isSfcStyleSourceFile(file) {
|
|
1230
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1231
|
+
return SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => normalizedFile.endsWith(extension));
|
|
1232
|
+
}
|
|
1233
|
+
function extractSfcStyleBlocks(source) {
|
|
1234
|
+
const styleSources = [];
|
|
1235
|
+
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1236
|
+
let index = 0;
|
|
1237
|
+
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1238
|
+
while (match !== null) {
|
|
1239
|
+
const attrs = match[1] ?? "";
|
|
1240
|
+
styleSources.push({
|
|
1241
|
+
attrs,
|
|
1242
|
+
index,
|
|
1243
|
+
scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
|
|
1244
|
+
source: match[2] ?? ""
|
|
1245
|
+
});
|
|
1246
|
+
index += 1;
|
|
1247
|
+
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1248
|
+
}
|
|
1249
|
+
return styleSources;
|
|
1250
|
+
}
|
|
1251
|
+
function extractSfcStyleSources(source) {
|
|
1252
|
+
return extractSfcStyleBlocks(source).map((style) => style.source);
|
|
1253
|
+
}
|
|
1254
|
+
function hasSfcStyleSources(source) {
|
|
1255
|
+
return extractSfcStyleSources(source).length > 0;
|
|
1256
|
+
}
|
|
1257
|
+
function resolveSfcStyleBlockLang(attrs) {
|
|
1258
|
+
const match = SFC_LANG_STYLE_ATTR_RE.exec(attrs);
|
|
1259
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
1260
|
+
}
|
|
1261
|
+
function resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks) {
|
|
1262
|
+
const scopedStyleBlock = styleBlocks.find((style) => style.scoped);
|
|
1263
|
+
return scopedStyleBlock ? [`${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true`, ...resolveSfcStyleBlockLang(scopedStyleBlock.attrs) ? [`lang=${encodeURIComponent(resolveSfcStyleBlockLang(scopedStyleBlock.attrs))}`] : []].join("&") : sourceFile;
|
|
1264
|
+
}
|
|
1265
|
+
function normalizeSfcStyleSourceForCompare(source) {
|
|
1266
|
+
return source.replace(/\r\n?/g, "\n").trim();
|
|
1267
|
+
}
|
|
1268
|
+
function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
1269
|
+
const params = new URLSearchParams();
|
|
1270
|
+
params.set("vue", "");
|
|
1271
|
+
params.set("type", "style");
|
|
1272
|
+
params.set("index", String(styleBlock.index));
|
|
1273
|
+
if (styleBlock.scoped) params.set("scoped", "true");
|
|
1274
|
+
const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
|
|
1275
|
+
if (lang) params.set("lang", lang);
|
|
1276
|
+
return `${sourceFile}?${params.toString()}`;
|
|
1277
|
+
}
|
|
1278
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource, currentRequest) {
|
|
1279
|
+
if (!sfcSource) return sourceFile;
|
|
1280
|
+
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
1281
|
+
if (styleBlocks.length === 0) return sourceFile;
|
|
1282
|
+
const normalizedStyleSource = normalizeSfcStyleSourceForCompare(styleSource);
|
|
1283
|
+
const matchedBlocks = styleBlocks.filter((styleBlock) => {
|
|
1284
|
+
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
1285
|
+
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
1286
|
+
});
|
|
1287
|
+
const requestIndex = currentRequest ? Number.parseInt(new URLSearchParams(currentRequest.split("?", 2)[1] ?? "").get("index") ?? "", 10) : NaN;
|
|
1288
|
+
const styleBlock = (Number.isInteger(requestIndex) ? styleBlocks.find((styleBlock) => styleBlock.index === requestIndex) : void 0) ?? (matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0);
|
|
1289
|
+
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1290
|
+
}
|
|
1291
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
1292
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1293
|
+
return hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1294
|
+
}
|
|
1295
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1296
|
+
if (isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1297
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1298
|
+
}
|
|
1299
|
+
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1300
|
+
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
1301
|
+
if (!sourceFile) {
|
|
1302
|
+
debug("sfc style source infer skipped: no source file for %s", outputFile);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
const source = getSfcSource?.(sourceFile);
|
|
1306
|
+
if (source == null) {
|
|
1307
|
+
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const styleBlocks = extractSfcStyleBlocks(source);
|
|
1311
|
+
const rawSource = styleBlocks.map((style) => style.source).join("\n");
|
|
1312
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1313
|
+
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
debug("sfc style source inferred: %s -> %s", outputFile, sourceFile);
|
|
1317
|
+
return {
|
|
1318
|
+
outputFile,
|
|
1319
|
+
rawSource,
|
|
1320
|
+
sourceFile: resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks)
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
function normalizeSfcSourceFileForCompare(file) {
|
|
1324
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1325
|
+
}
|
|
1326
|
+
function collectChunkModuleIds(output) {
|
|
1327
|
+
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1328
|
+
return [
|
|
1329
|
+
output.facadeModuleId,
|
|
1330
|
+
...moduleIds,
|
|
1331
|
+
...Object.keys(output.modules ?? {})
|
|
1332
|
+
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
1333
|
+
}
|
|
1334
|
+
function normalizeSourceStyleModuleId(id) {
|
|
1335
|
+
const file = id.replace(/[?#].*$/, "");
|
|
1336
|
+
if (!CSS_SOURCE_OUTPUT_EXT_RE.test(file)) return;
|
|
1337
|
+
if (!path.isAbsolute(file)) return;
|
|
1338
|
+
return path.resolve(file);
|
|
1339
|
+
}
|
|
1340
|
+
function resolveSiblingJsChunkFile(outputFile, cssMatcher) {
|
|
1341
|
+
const normalizedOutputFile = outputFile.replace(/[?#].*$/, "");
|
|
1342
|
+
if (cssMatcher?.(normalizedOutputFile)) {
|
|
1343
|
+
const extension = path.extname(normalizedOutputFile);
|
|
1344
|
+
return extension ? `${normalizedOutputFile.slice(0, -extension.length)}.js` : void 0;
|
|
1345
|
+
}
|
|
1346
|
+
if (CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".js");
|
|
1347
|
+
}
|
|
1348
|
+
function normalizeSfcModuleId(id) {
|
|
1349
|
+
const file = id.replace(/[?#].*$/, "");
|
|
1350
|
+
if (!isSfcStyleSourceFile(file)) return;
|
|
1351
|
+
if (!path.isAbsolute(file)) return;
|
|
1352
|
+
return path.resolve(file);
|
|
1353
|
+
}
|
|
1354
|
+
function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug) {
|
|
1355
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, cssMatcher);
|
|
1356
|
+
if (!siblingJsFile) {
|
|
1357
|
+
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1361
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1362
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1363
|
+
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
const sourceFiles = collectChunkModuleIds(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1367
|
+
if (sourceFiles.length === 0) {
|
|
1368
|
+
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1372
|
+
sourceFile,
|
|
1373
|
+
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1374
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1375
|
+
debug("sfc style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1376
|
+
const bestScore = scoredSources[0]?.score;
|
|
1377
|
+
if (!bestScore) return;
|
|
1378
|
+
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1379
|
+
if (bestSources.length !== 1) {
|
|
1380
|
+
debug("sfc style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
return bestSources[0]?.sourceFile;
|
|
1384
|
+
}
|
|
1385
|
+
function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1386
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, void 0);
|
|
1387
|
+
if (!siblingJsFile) {
|
|
1388
|
+
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1392
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1393
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1394
|
+
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
const sourceFiles = collectChunkModuleIds(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1398
|
+
if (sourceFiles.length === 0) {
|
|
1399
|
+
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
if (sourceFiles.length === 1) {
|
|
1403
|
+
debug("source style sibling chunk inferred from single css module: %s -> %s", outputFile, sourceFiles[0]);
|
|
1404
|
+
return sourceFiles[0];
|
|
1405
|
+
}
|
|
1406
|
+
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1407
|
+
sourceFile,
|
|
1408
|
+
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1409
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1410
|
+
debug("source style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1411
|
+
const bestScore = scoredSources[0]?.score;
|
|
1412
|
+
if (!bestScore) return;
|
|
1413
|
+
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1414
|
+
if (bestSources.length !== 1) {
|
|
1415
|
+
debug("source style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
return bestSources[0]?.sourceFile;
|
|
1419
|
+
}
|
|
1420
|
+
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1421
|
+
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1422
|
+
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1423
|
+
if (!sourceFile || !rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1424
|
+
const cachedSources = [...getSourceStyleSources?.() ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1425
|
+
file,
|
|
1426
|
+
source,
|
|
1427
|
+
score: scoreTailwindV4CssSourceFileMatch(outputFile, file, {
|
|
1428
|
+
outputRoot,
|
|
1429
|
+
projectRoot: sourceRoot
|
|
1430
|
+
})
|
|
1431
|
+
}));
|
|
1432
|
+
const configuredSources = [...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1433
|
+
file,
|
|
1434
|
+
source,
|
|
1435
|
+
score: scoreTailwindV4CssSourceFileMatch(outputFile, file, {
|
|
1436
|
+
outputRoot,
|
|
1437
|
+
projectRoot: sourceRoot
|
|
1438
|
+
})
|
|
1439
|
+
}));
|
|
1440
|
+
const scoredSources = [...cachedSources, ...configuredSources].filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1441
|
+
const bestScore = scoredSources[0]?.score;
|
|
1442
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
1443
|
+
if (bestSources.length === 1) {
|
|
1444
|
+
sourceFile = bestSources[0].file;
|
|
1445
|
+
rawSource = bestSources[0].source;
|
|
1446
|
+
debug("source style source inferred from cache: %s -> %s", outputFile, sourceFile);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (!sourceFile || !rawSource) return;
|
|
1450
|
+
if (!hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1451
|
+
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
return {
|
|
1455
|
+
outputFile,
|
|
1456
|
+
rawSource,
|
|
1457
|
+
sourceFile
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
//#endregion
|
|
1461
|
+
//#region src/bundlers/vite/web-css-compat.ts
|
|
1462
|
+
/**
|
|
1463
|
+
* Web target 的 Tailwind 兼容转换由 generator-css 负责;Vite 外层只处理非 Web 生成目标
|
|
1464
|
+
* 落到 WebView 产物时的最终兼容需求,避免同一份 CSS 在 dev/build 中被重复解析转换。
|
|
1465
|
+
*/
|
|
1466
|
+
function shouldApplyViteWebCssCompat(context, strategy) {
|
|
1467
|
+
if (strategy?.shouldApplyWebCssCompat?.(context) !== true) return false;
|
|
1468
|
+
return !context.currentGeneratorBranch.isWeb || context.currentGeneratorOptions.webCompat !== void 0;
|
|
1469
|
+
}
|
|
1470
|
+
function resolveViteWebCssCompatOptions(context) {
|
|
1471
|
+
return context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true;
|
|
1472
|
+
}
|
|
1473
|
+
//#endregion
|
|
1474
|
+
//#region src/bundlers/vite/query.ts
|
|
1475
|
+
function parseVueRequest(id) {
|
|
1476
|
+
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
1477
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
1478
|
+
const query = Object.fromEntries(searchParams);
|
|
1479
|
+
if (query.vue != null) query.vue = true;
|
|
1480
|
+
if (query.index != null) query.index = Number(query.index);
|
|
1481
|
+
if (query.raw != null) query.raw = true;
|
|
1482
|
+
if (query.url != null) query.url = true;
|
|
1483
|
+
if (query.scoped != null) query.scoped = true;
|
|
1484
|
+
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
1485
|
+
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
1486
|
+
if (langType) query.lang = langType;
|
|
1487
|
+
return {
|
|
1488
|
+
filename,
|
|
1489
|
+
query
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region src/bundlers/vite/module-identity.ts
|
|
1494
|
+
const WINDOWS_DRIVE_RE = /^\/?[a-z]:[\\/]/i;
|
|
1495
|
+
const WINDOWS_UNC_RE = /^(?:\\\\|\/\/)/;
|
|
1496
|
+
function unique(values) {
|
|
1497
|
+
return [...new Set([...values].filter((value) => typeof value === "string" && value.length > 0))];
|
|
1498
|
+
}
|
|
1499
|
+
function decodeFileId(id) {
|
|
1500
|
+
try {
|
|
1501
|
+
return decodeURIComponent(id);
|
|
1502
|
+
} catch {
|
|
1503
|
+
return id;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
function stripViteFsPrefix(id) {
|
|
1507
|
+
if (!id.startsWith("/@fs/")) return id;
|
|
1508
|
+
const file = id.slice(5);
|
|
1509
|
+
return file.startsWith("/") || WINDOWS_DRIVE_RE.test(file) ? file : `/${file}`;
|
|
1510
|
+
}
|
|
1511
|
+
function stripFileProtocol(id) {
|
|
1512
|
+
if (!id.startsWith("file://")) return id;
|
|
1513
|
+
try {
|
|
1514
|
+
return fileURLToPath(id);
|
|
1515
|
+
} catch {
|
|
1516
|
+
return id;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function isWindowsFile(file) {
|
|
1520
|
+
return WINDOWS_DRIVE_RE.test(file) || WINDOWS_UNC_RE.test(file);
|
|
1521
|
+
}
|
|
1522
|
+
function normalizeWindowsFile(file) {
|
|
1523
|
+
const withoutDriveSlash = /^\/[a-z]:[\\/]/i.test(file) ? file.slice(1) : file;
|
|
1524
|
+
return slash(path.win32.resolve(withoutDriveSlash));
|
|
1525
|
+
}
|
|
1526
|
+
function normalizeFile(file, root) {
|
|
1527
|
+
if (isWindowsFile(file) || isWindowsFile(root)) return normalizeWindowsFile(isWindowsFile(file) ? file : path.win32.resolve(root, file.replace(/^\//, "")));
|
|
1528
|
+
if (path.isAbsolute(file)) {
|
|
1529
|
+
if (file === root || file.startsWith(`${root}${path.sep}`) || existsSync(file) || existsSync(path.dirname(file))) return slash(path.resolve(file));
|
|
1530
|
+
const rootRelativeFile = path.resolve(root, file.slice(1));
|
|
1531
|
+
return existsSync(rootRelativeFile) || existsSync(path.dirname(rootRelativeFile)) ? slash(rootRelativeFile) : slash(path.resolve(file));
|
|
1532
|
+
}
|
|
1533
|
+
return slash(path.resolve(root, file));
|
|
1534
|
+
}
|
|
1535
|
+
function resolveRealFile(file) {
|
|
1536
|
+
if (process$1.platform !== "win32" && isWindowsFile(file)) return file;
|
|
1537
|
+
let current = file;
|
|
1538
|
+
const missingSegments = [];
|
|
1539
|
+
try {
|
|
1540
|
+
while (true) try {
|
|
1541
|
+
const resolvedParent = realpathSync.native(current);
|
|
1542
|
+
return slash(path.join(resolvedParent, ...missingSegments));
|
|
1543
|
+
} catch {
|
|
1544
|
+
const parent = path.dirname(current);
|
|
1545
|
+
if (parent === current) return file;
|
|
1546
|
+
missingSegments.unshift(path.basename(current));
|
|
1547
|
+
current = parent;
|
|
1548
|
+
}
|
|
1549
|
+
} catch {
|
|
1550
|
+
return file;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
function normalizeIdentityKey(file) {
|
|
1554
|
+
return isWindowsFile(file) || process$1.platform === "win32" ? file.toLowerCase() : file;
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* 将 Vite URL、文件路径和 Windows 的等价路径收敛为同一个模块身份。
|
|
1558
|
+
*/
|
|
1559
|
+
function resolveViteModuleIdentity(id, root = process$1.cwd()) {
|
|
1560
|
+
const cleanId = decodeFileId(cleanUrl$1(id));
|
|
1561
|
+
const decodedRoot = decodeFileId(cleanUrl$1(root));
|
|
1562
|
+
const normalizedRoot = isWindowsFile(decodedRoot) ? normalizeWindowsFile(decodedRoot) : slash(path.resolve(decodedRoot));
|
|
1563
|
+
const unwrappedId = stripFileProtocol(stripViteFsPrefix(cleanId));
|
|
1564
|
+
const file = unwrappedId.startsWith("\0") ? void 0 : normalizeFile(unwrappedId, normalizedRoot);
|
|
1565
|
+
const realFile = file ? resolveRealFile(file) : void 0;
|
|
1566
|
+
const key = realFile ? normalizeIdentityKey(realFile) : cleanId;
|
|
1567
|
+
const pathApi = isWindowsFile(normalizedRoot) ? path.win32 : path.posix;
|
|
1568
|
+
const relativeUrl = realFile && normalizeIdentityKey(realFile).startsWith(`${normalizeIdentityKey(normalizedRoot)}/`) ? `/${slash(pathApi.relative(normalizedRoot, realFile))}` : void 0;
|
|
1569
|
+
return {
|
|
1570
|
+
cleanId,
|
|
1571
|
+
file: realFile,
|
|
1572
|
+
key,
|
|
1573
|
+
lookupFiles: unique([file, realFile]),
|
|
1574
|
+
lookupIds: unique([
|
|
1575
|
+
id,
|
|
1576
|
+
cleanId,
|
|
1577
|
+
unwrappedId,
|
|
1578
|
+
file,
|
|
1579
|
+
realFile,
|
|
1580
|
+
realFile ? `/@fs/${realFile}` : void 0,
|
|
1581
|
+
relativeUrl
|
|
1582
|
+
])
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
function hasSameViteModuleIdentity(left, right, root = process$1.cwd()) {
|
|
1586
|
+
if (!left || !right) return false;
|
|
1587
|
+
return resolveViteModuleIdentity(left, root).key === resolveViteModuleIdentity(right, root).key;
|
|
1588
|
+
}
|
|
1589
|
+
//#endregion
|
|
1590
|
+
//#region src/bundlers/vite/hot-css-modules.ts
|
|
1591
|
+
async function resolveHotModulesByIds(ctx, ids, acceptModule) {
|
|
1592
|
+
const modules = [];
|
|
1593
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
1594
|
+
const seenModuleIds = /* @__PURE__ */ new Set();
|
|
1595
|
+
const seenFileIdentities = /* @__PURE__ */ new Set();
|
|
1596
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
1597
|
+
const collectModule = (mod) => {
|
|
1598
|
+
if (mod == null || seenModules.has(mod) || !acceptModule(mod)) return;
|
|
1599
|
+
seenModules.add(mod);
|
|
1600
|
+
modules.push(mod);
|
|
1601
|
+
};
|
|
1602
|
+
for (const id of ids) {
|
|
1603
|
+
if (typeof id !== "string" || id.length === 0) continue;
|
|
1604
|
+
const identity = resolveViteModuleIdentity(id, root);
|
|
1605
|
+
for (const moduleId of identity.lookupIds) {
|
|
1606
|
+
if (seenModuleIds.has(moduleId)) continue;
|
|
1607
|
+
seenModuleIds.add(moduleId);
|
|
1608
|
+
collectModule(ctx.server.moduleGraph.getModuleById?.(moduleId));
|
|
1609
|
+
if (moduleId.startsWith("/")) collectModule(await ctx.server.moduleGraph.getModuleByUrl?.(moduleId));
|
|
1610
|
+
}
|
|
1611
|
+
if (seenFileIdentities.has(identity.key)) continue;
|
|
1612
|
+
seenFileIdentities.add(identity.key);
|
|
1613
|
+
for (const file of identity.lookupFiles) for (const mod of ctx.server.moduleGraph.getModulesByFile?.(file) ?? []) collectModule(mod);
|
|
1614
|
+
}
|
|
1615
|
+
return modules;
|
|
1616
|
+
}
|
|
1617
|
+
async function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds, selectModules) {
|
|
1618
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
1619
|
+
const outDir = ctx.server.config?.build?.outDir ? resolveViteModuleIdentity(ctx.server.config.build.outDir, root) : void 0;
|
|
1620
|
+
const isHotSourceStyleModule = (id) => {
|
|
1621
|
+
if (!isSourceStyleRequest(id)) return false;
|
|
1622
|
+
const file = cleanUrl$1(id);
|
|
1623
|
+
if (isRootMiniProgramStyleUrl(file) || !isAbsoluteFilePath(file) && !file.startsWith("/")) return false;
|
|
1624
|
+
if (outDir) {
|
|
1625
|
+
const identity = resolveViteModuleIdentity(file, root);
|
|
1626
|
+
if (identity.key === outDir.key || identity.key.startsWith(`${outDir.key}/`)) return false;
|
|
1627
|
+
}
|
|
1628
|
+
return true;
|
|
1629
|
+
};
|
|
1630
|
+
const modules = await resolveHotModulesByIds(ctx, tailwindRootCssModuleIds, (mod) => {
|
|
1631
|
+
const modId = mod.id ?? mod.url;
|
|
1632
|
+
return isHotSourceStyleModule(modId);
|
|
1633
|
+
});
|
|
1634
|
+
const seenHotModules = new Set(modules);
|
|
1635
|
+
for (let index = 0; index < modules.length; index++) for (const importer of modules[index]?.importers ?? []) {
|
|
1636
|
+
const importerId = importer.id ?? importer.url;
|
|
1637
|
+
if (!seenHotModules.has(importer) && isHotSourceStyleModule(importerId)) {
|
|
1638
|
+
seenHotModules.add(importer);
|
|
1639
|
+
modules.push(importer);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
const selectedModules = selectModules?.(modules) ?? modules;
|
|
1643
|
+
for (const mod of selectedModules) ctx.server.moduleGraph.invalidateModule(mod);
|
|
1644
|
+
return selectedModules;
|
|
1645
|
+
}
|
|
1646
|
+
async function resolveHotSourceModulesByIds(ctx, ids) {
|
|
1647
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
1648
|
+
const sourceIds = new Set(ids);
|
|
1649
|
+
for (const id of ids) {
|
|
1650
|
+
if (typeof id !== "string" || !/\.(?:uvue|nvue|vue|tsx?|jsx?)(?:$|[?#])/i.test(id)) continue;
|
|
1651
|
+
const identity = resolveViteModuleIdentity(id, root);
|
|
1652
|
+
for (const lookupId of identity.lookupIds) if (!/[?&]import(?:[=&]|$)/.test(lookupId)) sourceIds.add(`${cleanUrl$1(lookupId)}?import`);
|
|
1653
|
+
}
|
|
1654
|
+
return resolveHotModulesByIds(ctx, sourceIds, (mod) => {
|
|
1655
|
+
const modId = mod.id ?? mod.url;
|
|
1656
|
+
return !isSourceStyleRequest(modId);
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
async function resolveHotSourceModules(ctx) {
|
|
1660
|
+
const modules = [];
|
|
1661
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
1662
|
+
const collectModule = (mod) => {
|
|
1663
|
+
if (mod == null || seenModules.has(mod)) return;
|
|
1664
|
+
const modId = mod.id ?? mod.url;
|
|
1665
|
+
if (isSourceStyleRequest(modId)) return;
|
|
1666
|
+
seenModules.add(mod);
|
|
1667
|
+
modules.push(mod);
|
|
1668
|
+
};
|
|
1669
|
+
for (const mod of ctx.modules) collectModule(mod);
|
|
1670
|
+
for (const mod of await resolveHotSourceModulesByIds(ctx, [ctx.file])) collectModule(mod);
|
|
1671
|
+
return modules;
|
|
1672
|
+
}
|
|
1673
|
+
function mergeHotModulesByIdentity(root, ...groups) {
|
|
1674
|
+
const modules = [];
|
|
1675
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
1676
|
+
const seenIdentities = /* @__PURE__ */ new Set();
|
|
1677
|
+
for (const mod of groups.flat()) {
|
|
1678
|
+
if (seenModules.has(mod)) continue;
|
|
1679
|
+
const ids = [
|
|
1680
|
+
mod.id,
|
|
1681
|
+
mod.url,
|
|
1682
|
+
mod.file
|
|
1683
|
+
].filter((id) => typeof id === "string" && id.length > 0);
|
|
1684
|
+
const moduleKind = ids.some(isSourceStyleRequest) ? "style" : "source";
|
|
1685
|
+
const keys = ids.map((id) => `${moduleKind}:${resolveViteModuleIdentity(id, root).key}`);
|
|
1686
|
+
if (keys.some((key) => seenIdentities.has(key))) continue;
|
|
1687
|
+
seenModules.add(mod);
|
|
1688
|
+
keys.forEach((key) => seenIdentities.add(key));
|
|
1689
|
+
modules.push(mod);
|
|
1690
|
+
}
|
|
1691
|
+
return modules;
|
|
1692
|
+
}
|
|
1693
|
+
function resolveModuleHotUrl(mod) {
|
|
1694
|
+
if (typeof mod.url === "string" && mod.url.length > 0) return mod.url;
|
|
1695
|
+
if (typeof mod.id === "string" && mod.id.startsWith("/")) return mod.id;
|
|
1696
|
+
}
|
|
1697
|
+
function isAbsoluteFilePath(file) {
|
|
1698
|
+
return path.isAbsolute(file) || /^[A-Z]:[\\/]/i.test(file) || file.startsWith("\\\\");
|
|
1699
|
+
}
|
|
1700
|
+
function normalizeAbsoluteFilePath(file) {
|
|
1701
|
+
if (/^[A-Z]:[\\/]/i.test(file) || file.startsWith("\\\\")) return slash(path.win32.resolve(file));
|
|
1702
|
+
return slash(path.resolve(file));
|
|
1703
|
+
}
|
|
1704
|
+
function isRootMiniProgramStyleUrl(file) {
|
|
1705
|
+
return /^\/[^/]+\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
1706
|
+
}
|
|
1707
|
+
function resolveCssHotUrl(id, root) {
|
|
1708
|
+
const suffix = /[?#]/.test(id) ? id.slice(id.search(/[?#]/)) : "";
|
|
1709
|
+
const cleanId = cleanUrl$1(id);
|
|
1710
|
+
if (/^\/(?!@fs\/|[A-Z]:)/i.test(cleanId) && !cleanId.startsWith(slash(root))) {
|
|
1711
|
+
if (isRootMiniProgramStyleUrl(cleanId)) return;
|
|
1712
|
+
return `${cleanId}${suffix}`;
|
|
1713
|
+
}
|
|
1714
|
+
const file = resolveViteModuleIdentity(id, root).file ?? cleanId;
|
|
1715
|
+
if (!isAbsoluteFilePath(file)) return;
|
|
1716
|
+
const normalizedRoot = normalizeAbsoluteFilePath(root);
|
|
1717
|
+
const normalizedFile = normalizeAbsoluteFilePath(file);
|
|
1718
|
+
if (!normalizedFile.startsWith(`${normalizedRoot}/`)) return;
|
|
1719
|
+
return `/${slash(path.relative(normalizedRoot, normalizedFile))}${suffix}`;
|
|
1720
|
+
}
|
|
1721
|
+
function includesHotModule(modules, target, root) {
|
|
1722
|
+
const targetUrl = resolveModuleHotUrl(target);
|
|
1723
|
+
const targetId = target.id;
|
|
1724
|
+
return modules.some((mod) => {
|
|
1725
|
+
if (mod === target) return true;
|
|
1726
|
+
return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId || [
|
|
1727
|
+
target.id,
|
|
1728
|
+
target.url,
|
|
1729
|
+
target.file
|
|
1730
|
+
].some((targetIdentity) => [
|
|
1731
|
+
mod.id,
|
|
1732
|
+
mod.url,
|
|
1733
|
+
mod.file
|
|
1734
|
+
].some((moduleIdentity) => hasSameViteModuleIdentity(targetIdentity, moduleIdentity, root)));
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
function includesHotId(modules, targetId, root) {
|
|
1738
|
+
return modules.some((mod) => [
|
|
1739
|
+
mod.id,
|
|
1740
|
+
mod.url,
|
|
1741
|
+
mod.file
|
|
1742
|
+
].some((moduleId) => hasSameViteModuleIdentity(targetId, moduleId, root)));
|
|
1743
|
+
}
|
|
1744
|
+
function createSupplementalHotUpdate(hotUrl, timestamp) {
|
|
1745
|
+
return {
|
|
1746
|
+
type: "js-update",
|
|
1747
|
+
timestamp,
|
|
1748
|
+
path: hotUrl,
|
|
1749
|
+
acceptedPath: hotUrl,
|
|
1750
|
+
explicitImportRequired: false,
|
|
1751
|
+
isWithinCircularImport: false
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
1755
|
+
return modules.some((mod) => {
|
|
1756
|
+
const modId = mod.id ?? mod.url;
|
|
1757
|
+
return !isSourceStyleRequest(modId) && mod.isSelfAccepting === true;
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = [], fallbackSourceIds = [], handledModules = ctx.modules) {
|
|
1761
|
+
const seenUrls = /* @__PURE__ */ new Set();
|
|
1762
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
1763
|
+
const updates = [];
|
|
1764
|
+
for (const id of fallbackSourceIds) {
|
|
1765
|
+
if (includesHotId(handledModules, id, root)) continue;
|
|
1766
|
+
const hotUrl = resolveCssHotUrl(id, root);
|
|
1767
|
+
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
1768
|
+
seenUrls.add(hotUrl);
|
|
1769
|
+
updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
|
|
1770
|
+
}
|
|
1771
|
+
for (const id of fallbackCssIds) {
|
|
1772
|
+
if (!isSourceStyleRequest(id) || includesHotId(handledModules, id, root)) continue;
|
|
1773
|
+
const hotUrl = resolveCssHotUrl(id, root);
|
|
1774
|
+
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
1775
|
+
seenUrls.add(hotUrl);
|
|
1776
|
+
updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
|
|
1777
|
+
}
|
|
1778
|
+
for (const mod of cssModules) {
|
|
1779
|
+
if (includesHotModule(handledModules, mod, root)) continue;
|
|
1780
|
+
const moduleHotUrl = resolveModuleHotUrl(mod);
|
|
1781
|
+
const hotUrl = moduleHotUrl ? resolveCssHotUrl(moduleHotUrl, root) : void 0;
|
|
1782
|
+
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
1783
|
+
seenUrls.add(hotUrl);
|
|
1784
|
+
updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
|
|
1785
|
+
}
|
|
1786
|
+
if (updates.length === 0) return;
|
|
1787
|
+
queueMicrotask(() => {
|
|
1788
|
+
ctx.server.ws?.send?.({
|
|
1789
|
+
type: "update",
|
|
1790
|
+
updates
|
|
1791
|
+
});
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
function sendFullReloadForUnresolvedHotUpdate(ctx) {
|
|
1795
|
+
ctx.server.ws?.send?.({
|
|
1796
|
+
type: "full-reload",
|
|
1797
|
+
path: "*",
|
|
1798
|
+
triggeredBy: ctx.file
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
//#endregion
|
|
1802
|
+
//#region src/bundlers/vite/shared/generic-web-production-fast-path.ts
|
|
1803
|
+
/**
|
|
1804
|
+
* Generic Web 非 watch 生产构建由 Tailwind Scanner 直接提供候选,不需要重复维护小程序候选状态。
|
|
1805
|
+
*/
|
|
1806
|
+
function shouldSkipGenericWebProductionSourceCandidates(options) {
|
|
1807
|
+
return options.frameworkName === "generic" && options.command === "build" && options.watch == null && options.isWebGeneratorTarget && options.requiresSourceCandidateState !== true;
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* 在 Vite 解析插件列表时排除无需维护的候选层,避免其 hooks 进入模块图。
|
|
1811
|
+
*/
|
|
1812
|
+
function createGenericWebProductionSourceCandidatesApply(options) {
|
|
1813
|
+
return (config, env) => !shouldSkipGenericWebProductionSourceCandidates({
|
|
1814
|
+
command: env.command,
|
|
1815
|
+
frameworkName: options.frameworkName,
|
|
1816
|
+
isWebGeneratorTarget: options.getIsWebGeneratorTarget(),
|
|
1817
|
+
requiresSourceCandidateState: options.requiresSourceCandidateState,
|
|
1818
|
+
watch: config.build?.watch
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Generic Web 生产构建的 CSS 已在 Vite transform 阶段生成时,不需要再建立面向小程序的完整产物快照。
|
|
1823
|
+
*/
|
|
1824
|
+
function shouldUseGenericWebProductionFastPath(options) {
|
|
1825
|
+
return shouldSkipGenericWebProductionSourceCandidates(options) && options.hasProcessedCss;
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Finalizer fast path 只处理无小程序结构语义的 Generic Web 生产产物。
|
|
1829
|
+
*/
|
|
1830
|
+
function shouldUseGenericWebFinalizerFastPath(options) {
|
|
1831
|
+
return shouldUseGenericWebProductionFastPath(options) && !options.hasFrameworkRootImportShells && !options.isHarmonyAppStyleTarget && !options.isNativeAppStyleTarget;
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* 将 Generic Web fast path 的判定和跳过生命周期集中起来,供 generateBundle hook 直接消费。
|
|
1835
|
+
*/
|
|
1836
|
+
function createGenericWebProductionBundleHooks(options) {
|
|
1837
|
+
return {
|
|
1838
|
+
onSkipProcessBundle: () => {
|
|
1839
|
+
options.onStart();
|
|
1840
|
+
options.onEnd();
|
|
1841
|
+
},
|
|
1842
|
+
shouldProcessBundle: () => {
|
|
1843
|
+
const config = options.getResolvedConfig();
|
|
1844
|
+
return !shouldUseGenericWebProductionFastPath({
|
|
1845
|
+
command: config?.command,
|
|
1846
|
+
frameworkName: options.frameworkName,
|
|
1847
|
+
hasProcessedCss: options.getHasProcessedCss(),
|
|
1848
|
+
isWebGeneratorTarget: options.getIsWebGeneratorTarget(),
|
|
1849
|
+
watch: config?.build?.watch
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1854
|
+
//#endregion
|
|
1855
|
+
//#region src/bundlers/vite/css-finalizer/options.ts
|
|
1856
|
+
function inferPlatformFromViteOutDir(outDir) {
|
|
1857
|
+
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
1858
|
+
if (!segment) return;
|
|
1859
|
+
const normalized = segment.trim().toLowerCase();
|
|
1860
|
+
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
1861
|
+
}
|
|
1862
|
+
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
1863
|
+
const candidate = error;
|
|
1864
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
1865
|
+
}
|
|
1866
|
+
function registerGeneratorDependencies(ctx, dependencies) {
|
|
1867
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
1868
|
+
for (const dependency of dependencies ?? []) try {
|
|
1869
|
+
ctx.addWatchFile(dependency);
|
|
1870
|
+
} catch (error) {
|
|
1871
|
+
if (isAddWatchFileInvalidRollupPhaseError(error)) {
|
|
1872
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
throw error;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
function createCssHandlerOptions(opts, majorVersion, file, outputRoot, extraOptions = {}) {
|
|
1879
|
+
const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
|
|
1880
|
+
return {
|
|
1881
|
+
...extraOptions,
|
|
1882
|
+
cssPreflight: opts.cssPreflight,
|
|
1883
|
+
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
1884
|
+
postcssOptions: { options: { from } },
|
|
1885
|
+
...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
1889
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
1890
|
+
appType: opts.appType,
|
|
1891
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
1892
|
+
tailwindcssMajorVersion: majorVersion,
|
|
1893
|
+
uniAppX: opts.uniAppX
|
|
1894
|
+
});
|
|
1895
|
+
if (!generatorOptions.enabled) return false;
|
|
1896
|
+
if (hasLocalCssImport(rawSource)) return false;
|
|
1897
|
+
if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
1898
|
+
if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
1899
|
+
return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
|
|
1900
|
+
}
|
|
1901
|
+
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
1902
|
+
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
1903
|
+
}
|
|
1904
|
+
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
1905
|
+
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
1906
|
+
}
|
|
1907
|
+
function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
1908
|
+
const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(context, cssPipelineStrategy);
|
|
1909
|
+
const defaultWebCssCompat = (value) => transformWebCssCompat(value, resolveViteWebCssCompatOptions(context));
|
|
1910
|
+
return cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
1911
|
+
...context,
|
|
1912
|
+
defaultWebCssCompat,
|
|
1913
|
+
removeScopedPreflight: (value) => value,
|
|
1914
|
+
shouldApplyWebCssCompat
|
|
1915
|
+
}) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
|
|
1916
|
+
}
|
|
1917
|
+
//#endregion
|
|
1918
|
+
//#region src/bundlers/vite/css-finalizer/generic-web-fast-path.ts
|
|
1919
|
+
function readAssetSource(asset) {
|
|
1920
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1921
|
+
}
|
|
1922
|
+
function collectCssAssets(bundle, context) {
|
|
1923
|
+
const assets = /* @__PURE__ */ new Map();
|
|
1924
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1925
|
+
if (output.type !== "asset") continue;
|
|
1926
|
+
const file = output.fileName || bundleFile;
|
|
1927
|
+
if (!context.opts.cssMatcher(file) || context.opts.htmlMatcher(file)) continue;
|
|
1928
|
+
assets.set(normalizeOutputPathKey(file), {
|
|
1929
|
+
asset: output,
|
|
1930
|
+
file,
|
|
1931
|
+
original: readAssetSource(output)
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
return assets;
|
|
1935
|
+
}
|
|
1936
|
+
function resolveProcessedCssOutputFile(file, options, bundleFiles) {
|
|
1937
|
+
return resolveViteCssPipelineOutputFile(file, options.context.opts, options.rootDir, true, false, options.sourceRoot, ".css", bundleFiles);
|
|
1938
|
+
}
|
|
1939
|
+
function resolveProcessedCssAssets(cssAssets, records, options, bundleFiles) {
|
|
1940
|
+
const assetBySourceFile = /* @__PURE__ */ new Map();
|
|
1941
|
+
for (const output of cssAssets.values()) {
|
|
1942
|
+
const identity = options.context.resolveCssAssetIdentity?.(output.asset, output.file);
|
|
1943
|
+
if (identity?.kind === "bundler-generated" && identity.sourceFile) assetBySourceFile.set(normalizeOutputPathKey(identity.sourceFile), output);
|
|
1944
|
+
for (const sourceFile of collectMatchingGeneratedCssMarkerFiles(output.file, output.original, (file) => resolveProcessedCssOutputFile(file, options, bundleFiles))) assetBySourceFile.set(normalizeOutputPathKey(sourceFile), output);
|
|
1945
|
+
}
|
|
1946
|
+
const processedAssets = /* @__PURE__ */ new Map();
|
|
1947
|
+
const htmlOwnedAssets = [...cssAssets.values()].filter((output) => [output.asset.originalFileName, ...output.asset.originalFileNames ?? []].some((file) => typeof file === "string" && /\.html(?:$|[?#])/i.test(file)));
|
|
1948
|
+
for (const [file, record] of records) {
|
|
1949
|
+
const recordCss = typeof record === "string" ? record : record.css;
|
|
1950
|
+
const outputFile = typeof record === "string" ? resolveProcessedCssOutputFile(file, options, bundleFiles) : record.outputFile ?? resolveProcessedCssOutputFile(file, options, bundleFiles);
|
|
1951
|
+
let output = assetBySourceFile.get(normalizeOutputPathKey(file)) ?? (outputFile ? cssAssets.get(normalizeOutputPathKey(outputFile)) : void 0);
|
|
1952
|
+
let useAssetSource = output !== void 0;
|
|
1953
|
+
if (!output) {
|
|
1954
|
+
const matchingAssets = [...cssAssets.values()].filter((candidate) => options.context.isCssAssetProcessed(candidate.asset, candidate.file) && resolveViteProcessedCssAssetSource(candidate.file, candidate.original, (sourceFile) => resolveProcessedCssOutputFile(sourceFile, options, bundleFiles)) === recordCss);
|
|
1955
|
+
if (matchingAssets.length === 1) {
|
|
1956
|
+
output = matchingAssets[0];
|
|
1957
|
+
useAssetSource = true;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
if (!output && records.length === 1 && htmlOwnedAssets.length === 1) {
|
|
1961
|
+
output = htmlOwnedAssets[0];
|
|
1962
|
+
useAssetSource = hasTailwindGeneratedCss(output.original) || hasTailwindGeneratedCssMarkers(output.original);
|
|
1963
|
+
}
|
|
1964
|
+
if (!output) return;
|
|
1965
|
+
const existing = processedAssets.get(output);
|
|
1966
|
+
if (existing !== void 0 && existing.css !== recordCss) return;
|
|
1967
|
+
processedAssets.set(output, {
|
|
1968
|
+
css: recordCss,
|
|
1969
|
+
useAssetSource
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
return processedAssets;
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Generic Web 的 transform 结果能唯一映射到最终 CSS asset 时,只做一次 marker 清理和 Web 兼容收尾。
|
|
1976
|
+
*/
|
|
1977
|
+
function tryFinalizeGenericWebCss(options) {
|
|
1978
|
+
const { bundle, context } = options;
|
|
1979
|
+
const resolvedConfig = context.getResolvedConfig();
|
|
1980
|
+
const collectStartedAt = performance.now();
|
|
1981
|
+
const processedCssResults = [...context.getViteProcessedCssAssetResults?.() ?? []];
|
|
1982
|
+
if (!shouldUseGenericWebFinalizerFastPath({
|
|
1983
|
+
command: resolvedConfig?.command,
|
|
1984
|
+
frameworkName: context.frameworkName ?? "",
|
|
1985
|
+
hasFrameworkRootImportShells: (context.frameworkRootImportShellTargetByFile?.size ?? 0) > 0,
|
|
1986
|
+
hasProcessedCss: processedCssResults.length > 0,
|
|
1987
|
+
isHarmonyAppStyleTarget: options.isHarmonyAppStyleTarget,
|
|
1988
|
+
isNativeAppStyleTarget: options.isNativeAppStyleTarget,
|
|
1989
|
+
isWebGeneratorTarget: options.isWebGeneratorTarget,
|
|
1990
|
+
watch: resolvedConfig?.build?.watch
|
|
1991
|
+
})) return false;
|
|
1992
|
+
const enumerateStartedAt = performance.now();
|
|
1993
|
+
const cssAssets = collectCssAssets(bundle, context);
|
|
1994
|
+
const bundleFiles = [...cssAssets.values()].map((item) => item.file);
|
|
1995
|
+
options.recordTiming("assets.enumerate", enumerateStartedAt);
|
|
1996
|
+
const processedAssets = resolveProcessedCssAssets(cssAssets, processedCssResults, options, bundleFiles);
|
|
1997
|
+
options.recordTiming("processedCss.collect", collectStartedAt);
|
|
1998
|
+
if (!processedAssets) return false;
|
|
1999
|
+
const writeStartedAt = performance.now();
|
|
2000
|
+
for (const [{ asset, file, original }, processed] of processedAssets) {
|
|
2001
|
+
const finalizeStartedAt = performance.now();
|
|
2002
|
+
const finalCssSource = processed.useAssetSource ? original : processed.css;
|
|
2003
|
+
const generated = finalizeWebCss(stripBundlerGeneratedCssMarkers(finalCssSource), {
|
|
2004
|
+
...options.createCssPipelineContext(file),
|
|
2005
|
+
file
|
|
2006
|
+
}, context.cssPipelineStrategy);
|
|
2007
|
+
options.recordTiming("finalizeWebCss", finalizeStartedAt);
|
|
2008
|
+
asset.source = generated;
|
|
2009
|
+
context.markCssAssetProcessed(asset, file);
|
|
2010
|
+
context.recordCssAssetResult?.(file, generated);
|
|
2011
|
+
if (generated !== original) context.opts.onUpdate(file, original, generated);
|
|
2012
|
+
}
|
|
2013
|
+
options.recordTiming("processedCss.inject", performance.now());
|
|
2014
|
+
options.recordTiming("assets.markerCleanupWrite", writeStartedAt);
|
|
2015
|
+
return true;
|
|
2016
|
+
}
|
|
2017
|
+
//#endregion
|
|
2018
|
+
//#region src/bundlers/vite/css-finalizer/web-plugin.ts
|
|
2019
|
+
/**
|
|
2020
|
+
* Generic Web 专用 CSS finalizer。
|
|
2021
|
+
*
|
|
2022
|
+
* 该插件只处理已经在 CSS transform 阶段记录的 CSS asset,不扫描或改写
|
|
2023
|
+
* HTML、JavaScript、模板和小程序分包产物。
|
|
2024
|
+
*/
|
|
2025
|
+
function createViteWebCssFinalizerOutputPlugin(context) {
|
|
2026
|
+
return {
|
|
2027
|
+
name: "weapp-tailwindcss:adaptor:web-css-finalizer",
|
|
2028
|
+
enforce: "post",
|
|
2029
|
+
async closeBundle() {
|
|
2030
|
+
if (context.getResolvedConfig()?.build?.watch != null) return;
|
|
2031
|
+
await disposeCompilerOwner(context.runtimeState);
|
|
2032
|
+
},
|
|
2033
|
+
async closeWatcher() {
|
|
2034
|
+
await disposeCompilerOwner(context.runtimeState);
|
|
2035
|
+
},
|
|
2036
|
+
generateBundle: {
|
|
2037
|
+
order: "post",
|
|
2038
|
+
async handler(_options, bundle) {
|
|
2039
|
+
const resolvedConfig = context.getResolvedConfig();
|
|
2040
|
+
if (resolvedConfig?.command !== "build") return;
|
|
2041
|
+
const rootDir = resolvedConfig.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
2042
|
+
const recordTiming = (phase, startedAt) => {
|
|
2043
|
+
context.hmrTimingRecorder?.record(`webCssFinalizer.${phase}`, performance.now() - startedAt);
|
|
2044
|
+
};
|
|
2045
|
+
const startedAt = performance.now();
|
|
2046
|
+
if (!tryFinalizeGenericWebCss({
|
|
2047
|
+
bundle,
|
|
2048
|
+
context,
|
|
2049
|
+
createCssPipelineContext: (file) => ({
|
|
2050
|
+
bundle,
|
|
2051
|
+
currentGeneratorBranch: {
|
|
2052
|
+
isWeb: true,
|
|
2053
|
+
isNativeApp: false,
|
|
2054
|
+
isMiniProgram: false
|
|
2055
|
+
},
|
|
2056
|
+
currentGeneratorOptions: {
|
|
2057
|
+
target: "web",
|
|
2058
|
+
enabled: true
|
|
2059
|
+
},
|
|
2060
|
+
file,
|
|
2061
|
+
opts: context.opts,
|
|
2062
|
+
resolvedConfig,
|
|
2063
|
+
resolveStylePlatform: () => "web"
|
|
2064
|
+
}),
|
|
2065
|
+
isHarmonyAppStyleTarget: false,
|
|
2066
|
+
isNativeAppStyleTarget: false,
|
|
2067
|
+
isWebGeneratorTarget: true,
|
|
2068
|
+
recordTiming,
|
|
2069
|
+
rootDir,
|
|
2070
|
+
sourceRoot: void 0
|
|
2071
|
+
})) context.debug("Generic Web CSS finalizer skipped: no unique processed CSS asset");
|
|
2072
|
+
finalizeCompilerShadowRun(context.runtimeState);
|
|
2073
|
+
context.hmrTimingRecorder?.record("webCssFinalizer.total", performance.now() - startedAt);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
//#endregion
|
|
2079
|
+
//#region src/bundlers/vite/map-cache.ts
|
|
2080
|
+
function touchMapEntry(map, key, value) {
|
|
2081
|
+
map.delete(key);
|
|
2082
|
+
map.set(key, value);
|
|
2083
|
+
}
|
|
2084
|
+
function pruneMapToMaxSize(map, maxSize, onDelete) {
|
|
2085
|
+
while (map.size > maxSize) {
|
|
2086
|
+
const key = map.keys().next().value;
|
|
2087
|
+
if (key === void 0) break;
|
|
2088
|
+
map.delete(key);
|
|
2089
|
+
onDelete?.(key);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region src/bundlers/vite/css-memory.ts
|
|
2094
|
+
const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
2095
|
+
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
2096
|
+
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
2097
|
+
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
2098
|
+
function toMb$1(bytes) {
|
|
2099
|
+
return Math.round(bytes / 1024 / 1024);
|
|
2100
|
+
}
|
|
2101
|
+
function summarizeStringMapCache(map) {
|
|
2102
|
+
let bytes = 0;
|
|
2103
|
+
for (const value of map.values()) bytes += value.length;
|
|
2104
|
+
return {
|
|
2105
|
+
bytes,
|
|
2106
|
+
mb: toMb$1(bytes),
|
|
2107
|
+
size: map.size
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
function summarizeRememberedCssSources(map) {
|
|
2111
|
+
let bytes = 0;
|
|
2112
|
+
for (const value of map.values()) bytes += value.rawSource.length;
|
|
2113
|
+
return {
|
|
2114
|
+
bytes,
|
|
2115
|
+
mb: toMb$1(bytes),
|
|
2116
|
+
size: map.size
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
function stripSourceHash(sourceFile) {
|
|
2120
|
+
const hashIndex = sourceFile.indexOf("#");
|
|
2121
|
+
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
2122
|
+
}
|
|
2123
|
+
function normalizeCssSourceIdentity(sourceFile) {
|
|
2124
|
+
const cleanSourceFile = stripSourceHash(sourceFile);
|
|
2125
|
+
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
2126
|
+
const normalizedFile = normalizeOutputPathKey(filename);
|
|
2127
|
+
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
2128
|
+
return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
|
|
2129
|
+
}
|
|
2130
|
+
function hasSfcStyleBlocks(source) {
|
|
2131
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
2132
|
+
return SFC_STYLE_BLOCK_RE.test(source);
|
|
2133
|
+
}
|
|
2134
|
+
function extractSfcStyleBlock(source, index) {
|
|
2135
|
+
const targetIndex = index ?? 0;
|
|
2136
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
2137
|
+
let currentIndex = 0;
|
|
2138
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
2139
|
+
while (match !== null) {
|
|
2140
|
+
if (currentIndex === targetIndex) return match[1] ?? "";
|
|
2141
|
+
currentIndex++;
|
|
2142
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
function extractSfcStyleSource(source, index) {
|
|
2146
|
+
if (index !== void 0) return extractSfcStyleBlock(source, index);
|
|
2147
|
+
const styleSources = [];
|
|
2148
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
2149
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
2150
|
+
while (match !== null) {
|
|
2151
|
+
styleSources.push(match[1] ?? "");
|
|
2152
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
2153
|
+
}
|
|
2154
|
+
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
2155
|
+
}
|
|
2156
|
+
function normalizeKnownSfcSourceKey(file) {
|
|
2157
|
+
return normalizeOutputPathKey(path.resolve(cleanUrl$1(file)));
|
|
2158
|
+
}
|
|
2159
|
+
function shouldCollectTransformedSourceCandidates(id) {
|
|
2160
|
+
if (isWeappViteSidecarRequest(id)) return false;
|
|
2161
|
+
if (id.search(/[?#]/) < 0) return true;
|
|
2162
|
+
const file = cleanUrl$1(id);
|
|
2163
|
+
return !SFC_COMPONENT_FILE_RE.test(file);
|
|
2164
|
+
}
|
|
2165
|
+
function createViteCssMemory(options) {
|
|
2166
|
+
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
2167
|
+
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
2168
|
+
const knownCssSources = /* @__PURE__ */ new Map();
|
|
2169
|
+
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
2170
|
+
const rememberKnownSfcSource = (id, code) => {
|
|
2171
|
+
if (id.search(/[?#]/) >= 0) return;
|
|
2172
|
+
const file = cleanUrl$1(id);
|
|
2173
|
+
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
2174
|
+
if (!hasSfcStyleBlocks(code)) return;
|
|
2175
|
+
touchMapEntry(knownSfcSources, normalizeKnownSfcSourceKey(file), code);
|
|
2176
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
2177
|
+
};
|
|
2178
|
+
const getKnownSfcSource = (file) => {
|
|
2179
|
+
const scanSource = options.getSourceCandidateSource(file);
|
|
2180
|
+
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
2181
|
+
const key = normalizeKnownSfcSourceKey(file);
|
|
2182
|
+
const source = knownSfcSources.get(key);
|
|
2183
|
+
if (source != null) touchMapEntry(knownSfcSources, key, source);
|
|
2184
|
+
return source;
|
|
2185
|
+
};
|
|
2186
|
+
const getKnownCssSource = (file) => {
|
|
2187
|
+
const source = knownCssSources.get(normalizeCssSourceIdentity(file));
|
|
2188
|
+
if (source != null) touchMapEntry(knownCssSources, normalizeCssSourceIdentity(file), source);
|
|
2189
|
+
return source;
|
|
2190
|
+
};
|
|
2191
|
+
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
2192
|
+
getActiveViteSourceOutputRelationOwner()?.recordOwnedOutput(entry.sourceFile, entry.outputFile);
|
|
2193
|
+
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
2194
|
+
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
2195
|
+
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
2196
|
+
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
2197
|
+
const previous = rememberedCssSources.get(key);
|
|
2198
|
+
touchMapEntry(rememberedCssSources, key, entry);
|
|
2199
|
+
const relatedRememberedEntries = [...rememberedCssSources].filter(([rememberedKey, remembered]) => rememberedKey !== key && normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
2200
|
+
for (const [rememberedKey, remembered] of relatedRememberedEntries) {
|
|
2201
|
+
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
2202
|
+
...remembered,
|
|
2203
|
+
outputFile: entry.outputFile,
|
|
2204
|
+
rawSource: entry.rawSource,
|
|
2205
|
+
sourceFile: entry.sourceFile
|
|
2206
|
+
});
|
|
2207
|
+
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
2208
|
+
}
|
|
2209
|
+
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
2210
|
+
else if (previous?.rawSource !== entry.rawSource || previous?.sourceFile !== entry.sourceFile) rememberedCssSignatureByFile.delete(key);
|
|
2211
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
2212
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
2213
|
+
});
|
|
2214
|
+
};
|
|
2215
|
+
const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
|
|
2216
|
+
if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
|
|
2217
|
+
const nextRemembered = {
|
|
2218
|
+
...remembered,
|
|
2219
|
+
rawSource,
|
|
2220
|
+
sourceFile
|
|
2221
|
+
};
|
|
2222
|
+
touchMapEntry(rememberedCssSources, rememberedKey, nextRemembered);
|
|
2223
|
+
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
2224
|
+
return nextRemembered;
|
|
2225
|
+
};
|
|
2226
|
+
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
2227
|
+
touchMapEntry(knownCssSources, normalizeCssSourceIdentity(sourceFile), rawSource);
|
|
2228
|
+
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
2229
|
+
const relatedRememberedEntries = [...rememberedCssSources].filter(([, remembered]) => normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
2230
|
+
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
2231
|
+
};
|
|
2232
|
+
const resolveCachedStyleSource = (sourceFile) => {
|
|
2233
|
+
const file = cleanUrl$1(stripRequestQuery(sourceFile));
|
|
2234
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
2235
|
+
if (isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
2236
|
+
};
|
|
2237
|
+
const resolveCurrentStyleSource = (sourceFile) => {
|
|
2238
|
+
const cached = resolveCachedStyleSource(sourceFile);
|
|
2239
|
+
if (cached != null) return cached;
|
|
2240
|
+
const file = cleanUrl$1(stripRequestQuery(sourceFile));
|
|
2241
|
+
const knownSource = knownCssSources.get(normalizeCssSourceIdentity(sourceFile));
|
|
2242
|
+
if (knownSource != null) return knownSource;
|
|
2243
|
+
const candidateSource = options.getSourceCandidateSource(file);
|
|
2244
|
+
if (candidateSource != null) return candidateSource;
|
|
2245
|
+
};
|
|
2246
|
+
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
2247
|
+
const file = cleanUrl$1(sourceFile);
|
|
2248
|
+
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
2249
|
+
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl$1(remembered.sourceFile))) === normalizedSourceFile);
|
|
2250
|
+
if (matchedRememberedSources.length === 0) return;
|
|
2251
|
+
const source = await resolveCurrentStyleSource(file);
|
|
2252
|
+
if (source == null) {
|
|
2253
|
+
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
2257
|
+
for (const remembered of matchedRememberedSources) {
|
|
2258
|
+
const { query } = parseVueRequest(remembered.sourceFile);
|
|
2259
|
+
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
2260
|
+
if (styleSource !== void 0) refreshRememberedCssSourceBySourceFile(remembered.sourceFile, styleSource);
|
|
2261
|
+
}
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
if (isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
2265
|
+
};
|
|
2266
|
+
const prune = (pruneOptions) => {
|
|
2267
|
+
const activeFiles = new Set([...pruneOptions.activeFiles].map(normalizeOutputPathKey));
|
|
2268
|
+
for (const [key, remembered] of rememberedCssSources) {
|
|
2269
|
+
const outputKey = normalizeOutputPathKey(remembered.outputFile);
|
|
2270
|
+
const sourceKey = normalizeOutputPathKey(remembered.sourceFile);
|
|
2271
|
+
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
2272
|
+
rememberedCssSources.delete(key);
|
|
2273
|
+
rememberedCssSignatureByFile.delete(key);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
if (pruneOptions.activeKnownSfcFiles) {
|
|
2277
|
+
const activeKnownSfcFiles = new Set([...pruneOptions.activeKnownSfcFiles].map((file) => normalizeKnownSfcSourceKey(file)).filter((file) => SFC_COMPONENT_FILE_RE.test(file)));
|
|
2278
|
+
for (const key of knownSfcSources.keys()) if (!activeKnownSfcFiles.has(key)) knownSfcSources.delete(key);
|
|
2279
|
+
}
|
|
2280
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
2281
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
2282
|
+
});
|
|
2283
|
+
pruneMapToMaxSize(knownCssSources, VITE_REMEMBERED_CSS_CACHE_MAX);
|
|
2284
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
2285
|
+
};
|
|
2286
|
+
return {
|
|
2287
|
+
getKnownSfcSource,
|
|
2288
|
+
getKnownCssSource,
|
|
2289
|
+
getRememberedCssSignature: (file) => rememberedCssSignatureByFile.get(normalizeOutputPathKey(file)),
|
|
2290
|
+
getRememberedCssSourceEntry: (file) => rememberedCssSources.get(normalizeOutputPathKey(file)),
|
|
2291
|
+
getRememberedCssSources: () => rememberedCssSources,
|
|
2292
|
+
getStats: () => ({
|
|
2293
|
+
rememberedCssSources: rememberedCssSources.size,
|
|
2294
|
+
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
2295
|
+
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
2296
|
+
knownCssSources: knownCssSources.size,
|
|
2297
|
+
knownCssSourcesRaw: summarizeStringMapCache(knownCssSources),
|
|
2298
|
+
knownSfcSources: knownSfcSources.size,
|
|
2299
|
+
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
2300
|
+
}),
|
|
2301
|
+
rememberCssSource,
|
|
2302
|
+
rememberKnownSfcSource,
|
|
2303
|
+
refreshRememberedCssSourceByCurrentFile,
|
|
2304
|
+
refreshRememberedCssSourceBySourceFile,
|
|
2305
|
+
setRememberedCssSignature: (file, cssRuntimeSignature) => {
|
|
2306
|
+
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
2307
|
+
},
|
|
2308
|
+
prune
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
//#endregion
|
|
2312
|
+
//#region src/bundlers/vite/plugin-cache.ts
|
|
2313
|
+
function isMissingInternalCssSource(file, packageDir) {
|
|
2314
|
+
return !existsSync(file) && path.resolve(file).startsWith(`${packageDir}${path.sep}`);
|
|
2315
|
+
}
|
|
2316
|
+
function normalizeVitePersistentCacheKey(file) {
|
|
2317
|
+
return normalizeOutputPathKey(file);
|
|
2318
|
+
}
|
|
2319
|
+
function toMb(bytes) {
|
|
2320
|
+
return Math.round(bytes / 1024 / 1024);
|
|
2321
|
+
}
|
|
2322
|
+
function summarizeStringCache(map) {
|
|
2323
|
+
let bytes = 0;
|
|
2324
|
+
for (const value of map.values()) bytes += value.length;
|
|
2325
|
+
return {
|
|
2326
|
+
bytes,
|
|
2327
|
+
mb: toMb(bytes),
|
|
2328
|
+
size: map.size
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
function summarizeViteProcessedCssResults(map) {
|
|
2332
|
+
let bytes = 0;
|
|
2333
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
2334
|
+
return {
|
|
2335
|
+
bytes,
|
|
2336
|
+
mb: toMb(bytes),
|
|
2337
|
+
size: map.size
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
//#endregion
|
|
2341
|
+
//#region src/bundlers/shared/css-imports.ts
|
|
2342
|
+
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
2343
|
+
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
2344
|
+
function normalizeTailwindcssSpecifier(specifier) {
|
|
2345
|
+
if (specifier === "tailwindcss$" || specifier === "weapp-tailwindcss$") return specifier.slice(0, -1);
|
|
2346
|
+
return specifier;
|
|
2347
|
+
}
|
|
2348
|
+
function getTailwindcssSubpath(specifier) {
|
|
2349
|
+
if (specifier === "tailwindcss" || specifier === "weapp-tailwindcss") return "index.css";
|
|
2350
|
+
return specifier.replace(/^(?:tailwindcss|weapp-tailwindcss)\//, "");
|
|
2351
|
+
}
|
|
2352
|
+
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
2353
|
+
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
2354
|
+
if (!tailwindcssImportRE.test(normalized)) return null;
|
|
2355
|
+
if (normalized === "tailwindcss" || normalized === "weapp-tailwindcss") return options?.rootImport ?? (options?.join ?? path.join)(pkgDir, "index.css");
|
|
2356
|
+
return (options?.join ?? path.join)(pkgDir, getTailwindcssSubpath(normalized));
|
|
2357
|
+
}
|
|
2358
|
+
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
2359
|
+
let hasReplacements = false;
|
|
2360
|
+
const rewritten = code.replace(tailwindcssCssImportStatementRE, (full, prefix, quote, specifier, suffix) => {
|
|
2361
|
+
const replacement = resolveTailwindcssImport(specifier, pkgDir, options);
|
|
2362
|
+
if (!replacement) return full;
|
|
2363
|
+
hasReplacements = true;
|
|
2364
|
+
return `${prefix}${quote}${replacement}${suffix}`;
|
|
2365
|
+
});
|
|
2366
|
+
return hasReplacements ? rewritten : void 0;
|
|
2367
|
+
}
|
|
2368
|
+
//#endregion
|
|
2369
|
+
//#region src/bundlers/vite/rewrite-css-imports.ts
|
|
2370
|
+
function joinPosixPath(base, subpath) {
|
|
2371
|
+
if (base.endsWith("/")) return `${base}${subpath}`;
|
|
2372
|
+
return `${base}/${subpath}`;
|
|
2373
|
+
}
|
|
2374
|
+
function isCssLikeImporter(importer) {
|
|
2375
|
+
if (!importer) return false;
|
|
2376
|
+
const normalized = cleanUrl$1(importer);
|
|
2377
|
+
return isSourceStyleRequest(importer) || isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
2378
|
+
}
|
|
2379
|
+
function stripTailwindConfigDirectives(code) {
|
|
2380
|
+
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
2381
|
+
}
|
|
2382
|
+
function createRewriteCssImportsPlugins(options) {
|
|
2383
|
+
if (!options.shouldRewrite && !options.shouldOwnTailwindGeneration) return [];
|
|
2384
|
+
const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
|
|
2385
|
+
const resolveAppType = () => getAppType?.() ?? appType;
|
|
2386
|
+
return [{
|
|
2387
|
+
name: `${vitePluginName}:rewrite-css-imports`,
|
|
2388
|
+
enforce: "pre",
|
|
2389
|
+
resolveId(id, importer) {
|
|
2390
|
+
if (!options.shouldRewrite) return null;
|
|
2391
|
+
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
|
|
2392
|
+
join: joinPosixPath,
|
|
2393
|
+
appType: resolveAppType(),
|
|
2394
|
+
rootImport
|
|
2395
|
+
});
|
|
2396
|
+
if (!replacement) return null;
|
|
2397
|
+
if (importer && !isCssLikeImporter(importer)) return null;
|
|
2398
|
+
return replacement;
|
|
2399
|
+
},
|
|
2400
|
+
async transform(code, id) {
|
|
2401
|
+
if (!isCSSRequest(id)) return null;
|
|
2402
|
+
const file = cleanUrl$1(id);
|
|
2403
|
+
const normalizedCode = !isSfcStyleSourceFile(file) && (hasTailwindRootDirectives(code) || code.includes("@config")) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
2404
|
+
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
2405
|
+
const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode, { importFallback: true });
|
|
2406
|
+
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
2407
|
+
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
2408
|
+
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
2409
|
+
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, {
|
|
2410
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
2411
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
2412
|
+
cssStage: "raw"
|
|
2413
|
+
});
|
|
2414
|
+
if (generatedCss !== void 0) return {
|
|
2415
|
+
code: generatedCss,
|
|
2416
|
+
map: null
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2419
|
+
if (!options.shouldRewrite) {
|
|
2420
|
+
if (normalizedCode !== code) return {
|
|
2421
|
+
code: normalizedCode,
|
|
2422
|
+
map: null
|
|
2423
|
+
};
|
|
2424
|
+
return null;
|
|
2425
|
+
}
|
|
2426
|
+
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
2427
|
+
join: joinPosixPath,
|
|
2428
|
+
appType: resolveAppType(),
|
|
2429
|
+
rootImport
|
|
2430
|
+
});
|
|
2431
|
+
const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ?? normalizedCode) : rewritten;
|
|
2432
|
+
if (!nextCode || nextCode === code) return null;
|
|
2433
|
+
return {
|
|
2434
|
+
code: nextCode,
|
|
2435
|
+
map: null
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
}];
|
|
2439
|
+
}
|
|
2440
|
+
function hasVitePipelineTailwindGenerationDirective(code) {
|
|
2441
|
+
return hasTailwindRootDirectives(code) || hasTailwindApplyDirective(code);
|
|
2442
|
+
}
|
|
2443
|
+
//#endregion
|
|
2444
|
+
//#region src/bundlers/vite/runtime-class-set.ts
|
|
2445
|
+
function createViteRuntimeClassSet(options) {
|
|
2446
|
+
const { opts, initialTailwindRuntime, refreshTailwindcssRuntime, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
2447
|
+
const readyPromise = createTailwindRuntimeReadyPromise(initialTailwindRuntime);
|
|
2448
|
+
const runtimeState = createCompilerRuntimeState({
|
|
2449
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
2450
|
+
readyPromise,
|
|
2451
|
+
refreshTailwindcssRuntime
|
|
2452
|
+
});
|
|
2453
|
+
const bundleRuntimeClassSetManager = createRuntimeClassSetManager({
|
|
2454
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
2455
|
+
escapeMap: opts.escapeMap
|
|
2456
|
+
});
|
|
2457
|
+
const transformRuntimeClassSetManager = createRuntimeClassSetManager({
|
|
2458
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
2459
|
+
escapeMap: opts.escapeMap
|
|
2460
|
+
});
|
|
2461
|
+
let runtimeSet;
|
|
2462
|
+
let runtimeSetPromise;
|
|
2463
|
+
let runtimeRefreshSignature;
|
|
2464
|
+
let runtimeRefreshOptionsKey;
|
|
2465
|
+
function resolveRuntimeRefreshOptions() {
|
|
2466
|
+
const configPath = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.config;
|
|
2467
|
+
const signature = getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
2468
|
+
const optionsKey = JSON.stringify({
|
|
2469
|
+
appType: opts.appType,
|
|
2470
|
+
uniAppX: uniAppXEnabled,
|
|
2471
|
+
customAttributesEntities,
|
|
2472
|
+
disabledDefaultTemplateHandler,
|
|
2473
|
+
configPath
|
|
2474
|
+
});
|
|
2475
|
+
const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
|
|
2476
|
+
runtimeRefreshSignature = signature;
|
|
2477
|
+
runtimeRefreshOptionsKey = optionsKey;
|
|
2478
|
+
return {
|
|
2479
|
+
changed,
|
|
2480
|
+
signature,
|
|
2481
|
+
optionsKey
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
async function refreshRuntimeState(force) {
|
|
2485
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
2486
|
+
const shouldRefresh = force || invalidation.changed;
|
|
2487
|
+
const refreshed = await refreshTailwindRuntimeState(runtimeState, {
|
|
2488
|
+
force: shouldRefresh,
|
|
2489
|
+
clearCache: force || invalidation.changed
|
|
2490
|
+
});
|
|
2491
|
+
if (invalidation.changed) debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
|
|
2492
|
+
if (refreshed) {
|
|
2493
|
+
runtimeSet = void 0;
|
|
2494
|
+
runtimeSetPromise = void 0;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
async function ensureRuntimeClassSet(force = false) {
|
|
2498
|
+
const forceRuntimeRefresh = force || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
2499
|
+
await refreshRuntimeState(force);
|
|
2500
|
+
await runtimeState.readyPromise;
|
|
2501
|
+
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
2502
|
+
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
2503
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
2504
|
+
runtimeSetPromise = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
2505
|
+
force: forceRuntimeRefresh || invalidation.changed,
|
|
2506
|
+
skipRefresh: forceRuntimeRefresh,
|
|
2507
|
+
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
const task = runtimeSetPromise;
|
|
2511
|
+
try {
|
|
2512
|
+
runtimeSet = await task;
|
|
2513
|
+
return runtimeSet;
|
|
2514
|
+
} finally {
|
|
2515
|
+
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
|
|
2519
|
+
const forceRuntimeRefresh = forceRefresh || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
2520
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
2521
|
+
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
2522
|
+
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
2523
|
+
await refreshRuntimeState(shouldRefreshRuntime);
|
|
2524
|
+
await runtimeState.readyPromise;
|
|
2525
|
+
if (shouldRefreshRuntime) {
|
|
2526
|
+
runtimeSet = void 0;
|
|
2527
|
+
runtimeSetPromise = void 0;
|
|
2528
|
+
await bundleRuntimeClassSetManager.reset();
|
|
2529
|
+
await transformRuntimeClassSetManager.reset();
|
|
2530
|
+
}
|
|
2531
|
+
if (!forceRuntimeRefresh) try {
|
|
2532
|
+
const baseClassSet = options.baseClassSet ?? runtimeSet ?? await collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
2533
|
+
force: invalidation.changed,
|
|
2534
|
+
clearCache: invalidation.changed
|
|
2535
|
+
});
|
|
2536
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
|
|
2537
|
+
baseClassSet,
|
|
2538
|
+
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync
|
|
2539
|
+
});
|
|
2540
|
+
runtimeSet = nextRuntimeSet;
|
|
2541
|
+
return nextRuntimeSet;
|
|
2542
|
+
} catch (error) {
|
|
2543
|
+
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
2544
|
+
await bundleRuntimeClassSetManager.reset();
|
|
2545
|
+
}
|
|
2546
|
+
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
2547
|
+
const task = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
2548
|
+
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
2549
|
+
skipRefresh: forceRuntimeRefresh,
|
|
2550
|
+
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
2551
|
+
});
|
|
2552
|
+
runtimeSetPromise = task;
|
|
2553
|
+
try {
|
|
2554
|
+
runtimeSet = await task;
|
|
2555
|
+
return runtimeSet;
|
|
2556
|
+
} finally {
|
|
2557
|
+
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
return {
|
|
2561
|
+
runtimeState,
|
|
2562
|
+
refreshRuntimeState,
|
|
2563
|
+
ensureRuntimeClassSet,
|
|
2564
|
+
ensureBundleRuntimeClassSet
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
//#endregion
|
|
2568
|
+
//#region src/bundlers/vite/serve-css-generation.ts
|
|
2569
|
+
const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/;
|
|
2570
|
+
const COMMON_JS_PROXY_RE = /\?commonjs-proxy/;
|
|
2571
|
+
const VITE_CSS_HMR_MODULE_RE = /\b__vite__updateStyle\s*\(/;
|
|
2572
|
+
const VITE_CSS_CONST_RE = /\bconst\s+__vite__css\s*=\s*("(?:\\[\s\S]|[^"])*")/;
|
|
2573
|
+
const DEFERRED_CSS_HMR_QUERY_RE = /[?&](?:hmr(?:[=&]|$)|t=\d+)/;
|
|
2574
|
+
function decodeJsStringLiteral(literal) {
|
|
2575
|
+
try {
|
|
2576
|
+
return JSON.parse(literal);
|
|
2577
|
+
} catch {
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
function encodeJsStringLiteral(value) {
|
|
2582
|
+
return JSON.stringify(value);
|
|
2583
|
+
}
|
|
2584
|
+
function extractViteCssHmrModuleCss(code) {
|
|
2585
|
+
const match = VITE_CSS_CONST_RE.exec(code);
|
|
2586
|
+
if (!match?.[1]) return;
|
|
2587
|
+
const css = decodeJsStringLiteral(match[1]);
|
|
2588
|
+
if (typeof css !== "string") return;
|
|
2589
|
+
return {
|
|
2590
|
+
css,
|
|
2591
|
+
start: match.index + match[0].lastIndexOf(match[1]),
|
|
2592
|
+
end: match.index + match[0].length
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
function replaceViteCssHmrModuleCss(code, css) {
|
|
2596
|
+
const extracted = extractViteCssHmrModuleCss(code);
|
|
2597
|
+
if (!extracted) return;
|
|
2598
|
+
return `${code.slice(0, extracted.start)}${encodeJsStringLiteral(css)}${code.slice(extracted.end)}`;
|
|
2599
|
+
}
|
|
2600
|
+
function isViteServeStyleRequest(id, command) {
|
|
2601
|
+
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
2602
|
+
}
|
|
2603
|
+
function isViteServeCssRootRequest(id, command) {
|
|
2604
|
+
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
2605
|
+
}
|
|
2606
|
+
function isViteBuildStyleRequest(id, command) {
|
|
2607
|
+
return command === "build" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
2608
|
+
}
|
|
2609
|
+
function isViteCssHmrModule(code, id, command) {
|
|
2610
|
+
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && (/[?&](?:direct|vue)(?:&|$)/.test(id) || DEFERRED_CSS_HMR_QUERY_RE.test(id));
|
|
2611
|
+
}
|
|
2612
|
+
function hasViteCssGenerationDirective(code) {
|
|
2613
|
+
return hasTailwindRootDirectives(code) || hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
2614
|
+
}
|
|
2615
|
+
function hasViteServeCssRootDirective(code) {
|
|
2616
|
+
return hasTailwindRootDirectives(code);
|
|
2617
|
+
}
|
|
2618
|
+
function createViteCssGenerationPlugins(options) {
|
|
2619
|
+
return [
|
|
2620
|
+
{
|
|
2621
|
+
name: `${vitePluginName}:generate:serve`,
|
|
2622
|
+
apply: "serve",
|
|
2623
|
+
enforce: "pre",
|
|
2624
|
+
async transform(code, id) {
|
|
2625
|
+
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
2626
|
+
if (!hasTailwindRootDirectives(code)) return;
|
|
2627
|
+
if (DEFERRED_CSS_HMR_QUERY_RE.test(id)) return;
|
|
2628
|
+
await options.onTailwindRootCss?.(id, code);
|
|
2629
|
+
const generatedCss = await options.generateCss(id, code, {
|
|
2630
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
2631
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
2632
|
+
cssStage: "raw"
|
|
2633
|
+
});
|
|
2634
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
2635
|
+
return {
|
|
2636
|
+
code: generatedCss,
|
|
2637
|
+
map: null
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
},
|
|
2641
|
+
{
|
|
2642
|
+
name: `${vitePluginName}:generate:build`,
|
|
2643
|
+
apply: "build",
|
|
2644
|
+
enforce: "pre",
|
|
2645
|
+
async transform(code, id) {
|
|
2646
|
+
if (!options.shouldGenerate() || options.shouldGenerateBuild?.() === false || !isViteBuildStyleRequest(id, options.getCommand())) return;
|
|
2647
|
+
if (!hasViteCssGenerationDirective(code)) return;
|
|
2648
|
+
if (options.shouldDeferGeneration?.(id, code)) return;
|
|
2649
|
+
if (hasViteServeCssRootDirective(code)) await options.onTailwindRootCss?.(id, code);
|
|
2650
|
+
const generatedCss = await options.generateCss(id, code, {
|
|
2651
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
2652
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
2653
|
+
cssStage: "raw"
|
|
2654
|
+
});
|
|
2655
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
2656
|
+
return {
|
|
2657
|
+
code: generatedCss,
|
|
2658
|
+
map: null
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
},
|
|
2662
|
+
{
|
|
2663
|
+
name: `${vitePluginName}:generate:serve-hmr`,
|
|
2664
|
+
apply: "serve",
|
|
2665
|
+
enforce: "post",
|
|
2666
|
+
async transform(code, id) {
|
|
2667
|
+
if (!options.shouldGenerate() || !isViteCssHmrModule(code, id, options.getCommand())) return;
|
|
2668
|
+
const extracted = extractViteCssHmrModuleCss(code);
|
|
2669
|
+
if (!extracted) return;
|
|
2670
|
+
if (!hasViteCssGenerationDirective(extracted.css)) return;
|
|
2671
|
+
if (options.shouldDeferGeneration?.(id, extracted.css)) return;
|
|
2672
|
+
if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
|
|
2673
|
+
const generatedCss = await options.generateCss(id, extracted.css, {
|
|
2674
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
2675
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
2676
|
+
cssStage: "framework-processed"
|
|
2677
|
+
});
|
|
2678
|
+
if (generatedCss === void 0 || generatedCss === extracted.css) return;
|
|
2679
|
+
const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
|
|
2680
|
+
if (nextCode === void 0 || nextCode === code) return;
|
|
2681
|
+
return {
|
|
2682
|
+
code: nextCode,
|
|
2683
|
+
map: null
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
];
|
|
2688
|
+
}
|
|
2689
|
+
//#endregion
|
|
2690
|
+
//#region src/bundlers/vite/shared/framework-css-generation-queue.ts
|
|
2691
|
+
function createFrameworkCssGenerationQueue(normalizeId, generate) {
|
|
2692
|
+
const pendingByFile = /* @__PURE__ */ new Map();
|
|
2693
|
+
return (id, ...args) => {
|
|
2694
|
+
const fileKey = normalizeId(id);
|
|
2695
|
+
const task = (pendingByFile.get(fileKey) ?? Promise.resolve()).then(() => generate(id, ...args));
|
|
2696
|
+
const tail = task.then(() => void 0, () => void 0);
|
|
2697
|
+
pendingByFile.set(fileKey, tail);
|
|
2698
|
+
tail.then(() => {
|
|
2699
|
+
if (pendingByFile.get(fileKey) === tail) pendingByFile.delete(fileKey);
|
|
2700
|
+
});
|
|
2701
|
+
return task;
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
//#endregion
|
|
2705
|
+
//#region src/bundlers/vite/shared/framework-hmr-candidate-state.ts
|
|
2706
|
+
function createViteHmrCandidateState(options) {
|
|
2707
|
+
let pendingChange;
|
|
2708
|
+
let pendingCssTargetFiles;
|
|
2709
|
+
let pendingTargetsArmed = false;
|
|
2710
|
+
let pendingFullRegeneration = false;
|
|
2711
|
+
const normalizeCssTargetFile = (file) => normalizeVitePersistentCacheKey(cleanUrl$1(file));
|
|
2712
|
+
const clear = () => {
|
|
2713
|
+
pendingChange = void 0;
|
|
2714
|
+
pendingCssTargetFiles = void 0;
|
|
2715
|
+
pendingTargetsArmed = false;
|
|
2716
|
+
pendingFullRegeneration = false;
|
|
2717
|
+
};
|
|
2718
|
+
const queueFullRegeneration = () => {
|
|
2719
|
+
pendingChange = void 0;
|
|
2720
|
+
pendingCssTargetFiles = void 0;
|
|
2721
|
+
pendingTargetsArmed = false;
|
|
2722
|
+
pendingFullRegeneration = true;
|
|
2723
|
+
};
|
|
2724
|
+
const queueChange = (change) => {
|
|
2725
|
+
var _pendingChange;
|
|
2726
|
+
if (pendingFullRegeneration) return;
|
|
2727
|
+
pendingFullRegeneration = false;
|
|
2728
|
+
if (!pendingChange) {
|
|
2729
|
+
pendingChange = {
|
|
2730
|
+
file: change.file,
|
|
2731
|
+
runtimeAffecting: change.runtimeAffecting,
|
|
2732
|
+
addedCandidates: new Set(change.addedCandidates),
|
|
2733
|
+
removedCandidates: new Set(change.removedCandidates)
|
|
2734
|
+
};
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
for (const candidate of change.addedCandidates) {
|
|
2738
|
+
pendingChange.addedCandidates.add(candidate);
|
|
2739
|
+
pendingChange.removedCandidates.delete(candidate);
|
|
2740
|
+
}
|
|
2741
|
+
for (const candidate of change.removedCandidates) if (!pendingChange.addedCandidates.delete(candidate)) pendingChange.removedCandidates.add(candidate);
|
|
2742
|
+
(_pendingChange = pendingChange).runtimeAffecting || (_pendingChange.runtimeAffecting = change.runtimeAffecting);
|
|
2743
|
+
pendingChange.file = change.file;
|
|
2744
|
+
};
|
|
2745
|
+
const createChange = (file, change, changeOptions = {}) => ({
|
|
2746
|
+
...change,
|
|
2747
|
+
file,
|
|
2748
|
+
runtimeAffecting: changeOptions.runtimeAffecting === true || options.isRuntimeAffectingSource?.(file) === true || isSourceStyleRequest(file)
|
|
2749
|
+
});
|
|
2750
|
+
const apply = (change) => {
|
|
2751
|
+
if (isSourceStyleRequest(change.file)) {
|
|
2752
|
+
clear();
|
|
2753
|
+
return change;
|
|
2754
|
+
}
|
|
2755
|
+
if (change.runtimeAffecting) {
|
|
2756
|
+
queueFullRegeneration();
|
|
2757
|
+
return change;
|
|
2758
|
+
}
|
|
2759
|
+
const preserveDeletedCss = options.getGeneratorOptions().hmr.preserveDeletedCss;
|
|
2760
|
+
if (preserveDeletedCss) {
|
|
2761
|
+
if (change.addedCandidates.size > 0) queueChange(change);
|
|
2762
|
+
else if (!pendingChange && !pendingFullRegeneration) clear();
|
|
2763
|
+
return change;
|
|
2764
|
+
}
|
|
2765
|
+
clear();
|
|
2766
|
+
if (!preserveDeletedCss) queueFullRegeneration();
|
|
2767
|
+
return change;
|
|
2768
|
+
};
|
|
2769
|
+
const resolve = (generatorCode, file) => {
|
|
2770
|
+
const fileKey = normalizeCssTargetFile(file);
|
|
2771
|
+
if (options.getCommand() !== "serve" || !pendingChange || pendingChange.runtimeAffecting || pendingChange.addedCandidates.size === 0 || options.getGeneratorOptions().target === "weapp" && hasUserCssLayerBlocks(generatorCode) || !options.cleanGeneratedCssByFile.has(fileKey) || !options.generatedClassSetByFile.has(fileKey) || pendingTargetsArmed && !pendingCssTargetFiles?.has(fileKey)) return;
|
|
2772
|
+
return pendingChange;
|
|
2773
|
+
};
|
|
2774
|
+
const finishTarget = (file) => {
|
|
2775
|
+
if (!pendingChange && !pendingFullRegeneration) return;
|
|
2776
|
+
if (!pendingTargetsArmed || !pendingCssTargetFiles) return;
|
|
2777
|
+
pendingCssTargetFiles.delete(normalizeCssTargetFile(file));
|
|
2778
|
+
if (pendingCssTargetFiles.size === 0) clear();
|
|
2779
|
+
};
|
|
2780
|
+
const armTargets = (cssModules, fallbackCssIds) => {
|
|
2781
|
+
if (!pendingChange && !pendingFullRegeneration) {
|
|
2782
|
+
pendingCssTargetFiles = void 0;
|
|
2783
|
+
pendingTargetsArmed = false;
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
const targets = /* @__PURE__ */ new Set();
|
|
2787
|
+
const addTarget = (file) => {
|
|
2788
|
+
if (!file) return;
|
|
2789
|
+
const key = normalizeCssTargetFile(file);
|
|
2790
|
+
if (pendingFullRegeneration || options.cleanGeneratedCssByFile.has(key)) targets.add(key);
|
|
2791
|
+
};
|
|
2792
|
+
for (const module of cssModules) {
|
|
2793
|
+
addTarget(module.id);
|
|
2794
|
+
addTarget(module.file);
|
|
2795
|
+
addTarget(module.url);
|
|
2796
|
+
}
|
|
2797
|
+
for (const id of fallbackCssIds) addTarget(id);
|
|
2798
|
+
pendingCssTargetFiles = targets;
|
|
2799
|
+
pendingTargetsArmed = true;
|
|
2800
|
+
};
|
|
2801
|
+
const reconcileRuntimeCandidates = (file, candidates, rootCssIds) => {
|
|
2802
|
+
if (options.getCommand() !== "serve" || pendingFullRegeneration) return;
|
|
2803
|
+
const generatedClassSets = [];
|
|
2804
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
2805
|
+
for (const id of rootCssIds) {
|
|
2806
|
+
const fileKey = normalizeCssTargetFile(id);
|
|
2807
|
+
if (seenFiles.has(fileKey)) continue;
|
|
2808
|
+
seenFiles.add(fileKey);
|
|
2809
|
+
const classSet = options.generatedClassSetByFile.get(fileKey);
|
|
2810
|
+
if (classSet) generatedClassSets.push(classSet);
|
|
2811
|
+
}
|
|
2812
|
+
if (generatedClassSets.length === 0) return;
|
|
2813
|
+
const addedCandidates = /* @__PURE__ */ new Set();
|
|
2814
|
+
for (const candidate of candidates) if (generatedClassSets.some((classSet) => !classSet.has(candidate))) addedCandidates.add(candidate);
|
|
2815
|
+
if (addedCandidates.size === 0) return;
|
|
2816
|
+
apply(createChange(file, {
|
|
2817
|
+
addedCandidates,
|
|
2818
|
+
removedCandidates: /* @__PURE__ */ new Set()
|
|
2819
|
+
}));
|
|
2820
|
+
};
|
|
2821
|
+
return {
|
|
2822
|
+
apply,
|
|
2823
|
+
armTargets,
|
|
2824
|
+
clear,
|
|
2825
|
+
createChange,
|
|
2826
|
+
finishTarget,
|
|
2827
|
+
hasPendingCandidateAppend: () => pendingChange != null && !pendingChange.runtimeAffecting && pendingChange.addedCandidates.size > 0,
|
|
2828
|
+
hasPendingChange: () => pendingChange != null || pendingFullRegeneration,
|
|
2829
|
+
queueFullRegeneration,
|
|
2830
|
+
reconcileRuntimeCandidates,
|
|
2831
|
+
resolve,
|
|
2832
|
+
shouldForceFullRegeneration: (file, resolved) => {
|
|
2833
|
+
if (options.getCommand() !== "serve") return false;
|
|
2834
|
+
if (pendingFullRegeneration) return pendingTargetsArmed && pendingCssTargetFiles?.has(normalizeCssTargetFile(file)) === true;
|
|
2835
|
+
return pendingChange != null && !resolved && pendingTargetsArmed && pendingCssTargetFiles?.has(normalizeCssTargetFile(file)) === true;
|
|
2836
|
+
},
|
|
2837
|
+
snapshotDebugState: () => ({
|
|
2838
|
+
pendingAddedCandidates: pendingChange?.addedCandidates.size ?? 0,
|
|
2839
|
+
pendingCssTargets: pendingCssTargetFiles?.size ?? 0,
|
|
2840
|
+
pendingFullRegeneration
|
|
2841
|
+
})
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
//#endregion
|
|
2845
|
+
//#region src/bundlers/vite/shared/framework-hmr-module-version.ts
|
|
2846
|
+
function acceptVersion(versions, keys, timestamp) {
|
|
2847
|
+
if (keys.some((key) => (versions.get(key) ?? 0) > timestamp)) return false;
|
|
2848
|
+
for (const key of keys) versions.set(key, Math.max(versions.get(key) ?? 0, timestamp));
|
|
2849
|
+
return true;
|
|
2850
|
+
}
|
|
2851
|
+
function createViteHmrCssModuleVersionTracker() {
|
|
2852
|
+
const versions = /* @__PURE__ */ new Map();
|
|
2853
|
+
const keysForId = (id, root) => [resolveViteModuleIdentity(id, root).key];
|
|
2854
|
+
const keysForModule = (mod, root) => [...new Set([
|
|
2855
|
+
mod.id,
|
|
2856
|
+
mod.url,
|
|
2857
|
+
mod.file
|
|
2858
|
+
].filter((id) => typeof id === "string" && id.length > 0).flatMap((id) => keysForId(id, root)))];
|
|
2859
|
+
return {
|
|
2860
|
+
clear() {
|
|
2861
|
+
versions.clear();
|
|
2862
|
+
},
|
|
2863
|
+
filterIds(ids, timestamp, root) {
|
|
2864
|
+
return [...ids].filter((id) => acceptVersion(versions, keysForId(id, root), timestamp));
|
|
2865
|
+
},
|
|
2866
|
+
filterModules(modules, timestamp, root) {
|
|
2867
|
+
return modules.filter((mod) => {
|
|
2868
|
+
const keys = keysForModule(mod, root);
|
|
2869
|
+
return keys.length === 0 || acceptVersion(versions, keys, timestamp);
|
|
2870
|
+
});
|
|
2871
|
+
},
|
|
2872
|
+
reserveRefreshTimestamp(modules, timestamp, root) {
|
|
2873
|
+
const moduleKeys = modules.flatMap((mod) => keysForModule(mod, root));
|
|
2874
|
+
const latestTimestamp = moduleKeys.reduce((latest, key) => Math.max(latest, versions.get(key) ?? 0), 0);
|
|
2875
|
+
const refreshTimestamp = Math.max(Date.now(), timestamp + 1, latestTimestamp + 1);
|
|
2876
|
+
for (const key of moduleKeys) versions.set(key, refreshTimestamp);
|
|
2877
|
+
return refreshTimestamp;
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
function createViteHmrCssModuleVersionFilterPlugin(tracker) {
|
|
2882
|
+
return {
|
|
2883
|
+
name: "weapp-tailwindcss:hmr-css-module-version",
|
|
2884
|
+
enforce: "post",
|
|
2885
|
+
handleHotUpdate: {
|
|
2886
|
+
order: "post",
|
|
2887
|
+
handler(ctx) {
|
|
2888
|
+
const styleModules = ctx.modules.filter((mod) => {
|
|
2889
|
+
const request = mod.id ?? mod.url;
|
|
2890
|
+
return isSourceStyleRequest(request);
|
|
2891
|
+
});
|
|
2892
|
+
if (styleModules.length === 0) return;
|
|
2893
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
2894
|
+
const currentStyleModules = tracker.filterModules(styleModules, ctx.timestamp, root);
|
|
2895
|
+
if (currentStyleModules.length === styleModules.length) return;
|
|
2896
|
+
const droppedStyleModules = styleModules.filter((mod) => !currentStyleModules.includes(mod));
|
|
2897
|
+
for (const mod of droppedStyleModules) ctx.server.moduleGraph.invalidateModule(mod);
|
|
2898
|
+
const refreshTimestamp = tracker.reserveRefreshTimestamp(droppedStyleModules, ctx.timestamp, root);
|
|
2899
|
+
sendSupplementalCssHotUpdates({
|
|
2900
|
+
...ctx,
|
|
2901
|
+
timestamp: refreshTimestamp
|
|
2902
|
+
}, droppedStyleModules, [], [], []);
|
|
2903
|
+
return [...ctx.modules.filter((mod) => !styleModules.includes(mod)), ...currentStyleModules];
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
//#endregion
|
|
2909
|
+
//#region src/bundlers/vite/official-tailwind-plugins.ts
|
|
2910
|
+
function isTailwindVitePlugin(plugin) {
|
|
2911
|
+
if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
|
|
2912
|
+
const { name } = plugin;
|
|
2913
|
+
return typeof name === "string" && name.startsWith("@tailwindcss/vite");
|
|
2914
|
+
}
|
|
2915
|
+
function removeTailwindVitePlugins(plugins) {
|
|
2916
|
+
let removed = 0;
|
|
2917
|
+
for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindVitePlugin(plugins[i])) {
|
|
2918
|
+
plugins.splice(i, 1);
|
|
2919
|
+
removed++;
|
|
2920
|
+
}
|
|
2921
|
+
return removed;
|
|
2922
|
+
}
|
|
2923
|
+
function disableTailwindVitePlugin(plugin) {
|
|
2924
|
+
if (!isTailwindVitePlugin(plugin)) return false;
|
|
2925
|
+
const mutablePlugin = plugin;
|
|
2926
|
+
for (const hook of [
|
|
2927
|
+
"configResolved",
|
|
2928
|
+
"configureServer",
|
|
2929
|
+
"transform",
|
|
2930
|
+
"hotUpdate",
|
|
2931
|
+
"handleHotUpdate"
|
|
2932
|
+
]) delete mutablePlugin[hook];
|
|
2933
|
+
return true;
|
|
2934
|
+
}
|
|
2935
|
+
function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
2936
|
+
let removed = 0;
|
|
2937
|
+
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
2938
|
+
const plugin = plugins[i];
|
|
2939
|
+
if (Array.isArray(plugin)) {
|
|
2940
|
+
removed += disableAndRemoveTailwindVitePlugins(plugin);
|
|
2941
|
+
if (plugin.length === 0) plugins.splice(i, 1);
|
|
2942
|
+
continue;
|
|
2943
|
+
}
|
|
2944
|
+
if (disableTailwindVitePlugin(plugin)) {
|
|
2945
|
+
plugins.splice(i, 1);
|
|
2946
|
+
removed++;
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
return removed;
|
|
2950
|
+
}
|
|
2951
|
+
//#endregion
|
|
2952
|
+
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
2953
|
+
const PACKAGE_JSON_FILE = "package.json";
|
|
2954
|
+
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
2955
|
+
const resolvedRoot = path.resolve(root);
|
|
2956
|
+
if (!existsSync(resolvedRoot)) return resolvedRoot;
|
|
2957
|
+
const searchRoots = [];
|
|
2958
|
+
let current = resolvedRoot;
|
|
2959
|
+
while (true) {
|
|
2960
|
+
searchRoots.push(current);
|
|
2961
|
+
const parent = path.dirname(current);
|
|
2962
|
+
if (parent === current) break;
|
|
2963
|
+
current = parent;
|
|
2964
|
+
}
|
|
2965
|
+
const tailwindConfigPath = findTailwindConfig(searchRoots);
|
|
2966
|
+
if (tailwindConfigPath) return path.dirname(tailwindConfigPath);
|
|
2967
|
+
const packageRoot = findNearestPackageRoot(resolvedRoot);
|
|
2968
|
+
if (packageRoot && existsSync(path.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
2969
|
+
return resolvedRoot;
|
|
2970
|
+
}
|
|
2971
|
+
//#endregion
|
|
2972
|
+
//#region src/bundlers/vite/shared/framework-post-plugin.ts
|
|
2973
|
+
function createFrameworkPostPlugin(options) {
|
|
2974
|
+
const plugin = {
|
|
2975
|
+
name: `${vitePluginName}:post`,
|
|
2976
|
+
enforce: "post",
|
|
2977
|
+
config(config) {
|
|
2978
|
+
if (!options.shouldOwnTailwindGeneration) return;
|
|
2979
|
+
if (Array.isArray(config.plugins)) {
|
|
2980
|
+
const removed = disableAndRemoveTailwindVitePlugins(config.plugins);
|
|
2981
|
+
if (removed > 0) {
|
|
2982
|
+
logger.warn("检测到 @tailwindcss/vite,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
2983
|
+
options.debug("disable official tailwind vite plugins in generator mode: %d", removed);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
const root = config.root ? path.resolve(config.root) : process$1.cwd();
|
|
2987
|
+
const baseConfig = { resolve: { alias: [{
|
|
2988
|
+
find: /^tailwindcss$/,
|
|
2989
|
+
replacement: options.generatorPlaceholderCssFile
|
|
2990
|
+
}] } };
|
|
2991
|
+
if (config.css?.postcss !== void 0) return baseConfig;
|
|
2992
|
+
return resolvePostcssConfig(root).then((postcssConfig) => {
|
|
2993
|
+
if (!postcssConfig) return baseConfig;
|
|
2994
|
+
const plugins = [...postcssConfig.plugins];
|
|
2995
|
+
const removed = removeTailwindPostcssPlugins(plugins);
|
|
2996
|
+
if (removed > 0) options.debug("inline filtered postcss config without official tailwind plugins in generator mode: %d", removed);
|
|
2997
|
+
return {
|
|
2998
|
+
...baseConfig,
|
|
2999
|
+
css: { postcss: {
|
|
3000
|
+
...postcssConfig.options,
|
|
3001
|
+
plugins
|
|
3002
|
+
} }
|
|
3003
|
+
};
|
|
3004
|
+
});
|
|
3005
|
+
},
|
|
3006
|
+
async configResolved(config) {
|
|
3007
|
+
await options.hmrTimingRecorder.measure("configResolved", async () => {
|
|
3008
|
+
options.setResolvedConfig(config);
|
|
3009
|
+
if (options.shouldOwnTailwindGeneration) {
|
|
3010
|
+
const removed = Array.isArray(config.plugins) ? removeTailwindVitePlugins(config.plugins) : 0;
|
|
3011
|
+
if (removed > 0) options.debug("remove official tailwind vite plugins in generator mode: %d", removed);
|
|
3012
|
+
}
|
|
3013
|
+
const resolvedRoot = config.root ? path.resolve(config.root) : void 0;
|
|
3014
|
+
let shouldRefreshRuntime = false;
|
|
3015
|
+
if (!options.hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
3016
|
+
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
3017
|
+
if (options.opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|
|
3018
|
+
const previousBasedir = options.opts.tailwindcssBasedir;
|
|
3019
|
+
options.opts.tailwindcssBasedir = nextTailwindcssBasedir;
|
|
3020
|
+
shouldRefreshRuntime = options.syncCssEntriesFromAnchor(nextTailwindcssBasedir) || shouldRefreshRuntime;
|
|
3021
|
+
options.debug("align tailwindcss basedir with vite root: %s -> %s", previousBasedir ?? "undefined", nextTailwindcssBasedir);
|
|
3022
|
+
shouldRefreshRuntime = true;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
if (options.shouldInferAppType && resolvedRoot) {
|
|
3026
|
+
const nextAppType = resolveImplicitAppTypeFromViteRoot(resolvedRoot, { searchUp: false });
|
|
3027
|
+
if (nextAppType && options.opts.appType !== nextAppType) {
|
|
3028
|
+
const previousAppType = options.opts.appType;
|
|
3029
|
+
options.opts.appType = nextAppType;
|
|
3030
|
+
logger.debug("根据 Vite 项目根目录自动推断 appType -> %s", nextAppType);
|
|
3031
|
+
options.debug("align appType with vite root: %s -> %s", previousAppType ?? "undefined", nextAppType);
|
|
3032
|
+
shouldRefreshRuntime = true;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
if (options.frameworkName === "generic" && !options.hasExplicitGeneratorTarget && options.opts.generator !== false && options.opts.appType === void 0 && options.opts.platform === void 0 && options.opts.cssOptions?.platform === void 0 && !options.resolveViteStylePlatform()) {
|
|
3036
|
+
const generator = options.opts.generator && typeof options.opts.generator === "object" ? options.opts.generator : {};
|
|
3037
|
+
options.opts.generator = {
|
|
3038
|
+
...generator,
|
|
3039
|
+
target: "web"
|
|
3040
|
+
};
|
|
3041
|
+
logger.debug("Generic Vite 项目未指定目标,自动使用 generator.target -> web");
|
|
3042
|
+
options.debug("default generic vite generator target to web after configResolved");
|
|
3043
|
+
shouldRefreshRuntime = true;
|
|
3044
|
+
}
|
|
3045
|
+
if (shouldRefreshRuntime) await options.refreshRuntimeState(true);
|
|
3046
|
+
if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
|
|
3047
|
+
const postcssPlugins = config.css.postcss.plugins;
|
|
3048
|
+
if (options.shouldOwnTailwindGeneration) {
|
|
3049
|
+
const removed = removeTailwindPostcssPlugins(postcssPlugins);
|
|
3050
|
+
if (removed > 0) {
|
|
3051
|
+
logger.warn("检测到 @tailwindcss/postcss,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
3052
|
+
options.debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
captureFrameworkPostcssOptions(options.opts, config.css?.postcss && typeof config.css.postcss === "object" ? config.css.postcss : void 0);
|
|
3057
|
+
}, { emit: false });
|
|
3058
|
+
}
|
|
3059
|
+
};
|
|
3060
|
+
if (typeof options.generateBundleHook === "function") plugin.generateBundle = {
|
|
3061
|
+
order: "post",
|
|
3062
|
+
handler: options.generateBundleHook
|
|
3063
|
+
};
|
|
3064
|
+
if (options.api) plugin.api = options.api;
|
|
3065
|
+
return plugin;
|
|
3066
|
+
}
|
|
3067
|
+
//#endregion
|
|
3068
|
+
//#region src/bundlers/vite/shared/framework-processed-css-registry.ts
|
|
3069
|
+
function createFrameworkProcessedCssRegistry() {
|
|
3070
|
+
const results = /* @__PURE__ */ new Map();
|
|
3071
|
+
const sourceFiles = /* @__PURE__ */ new Set();
|
|
3072
|
+
const markSource = (file) => {
|
|
3073
|
+
sourceFiles.add(path.resolve(cleanUrl$1(file)));
|
|
3074
|
+
};
|
|
3075
|
+
const record = (file, css, options = {}) => {
|
|
3076
|
+
const key = normalizeVitePersistentCacheKey(file);
|
|
3077
|
+
const previous = results.get(key);
|
|
3078
|
+
const injectIntoMain = previous?.injectIntoMain === true ? true : options.injectIntoMain ?? previous?.injectIntoMain;
|
|
3079
|
+
touchMapEntry(results, key, {
|
|
3080
|
+
css,
|
|
3081
|
+
injectIntoMain,
|
|
3082
|
+
outputFile: options.outputFile ?? previous?.outputFile
|
|
3083
|
+
});
|
|
3084
|
+
};
|
|
3085
|
+
const get = (file) => results.get(normalizeVitePersistentCacheKey(file));
|
|
3086
|
+
const matchesIdentity = (candidate) => {
|
|
3087
|
+
return sourceFiles.has(path.resolve(cleanUrl$1(candidate)));
|
|
3088
|
+
};
|
|
3089
|
+
const prune = (activeFiles) => {
|
|
3090
|
+
for (const [key, result] of results) {
|
|
3091
|
+
const outputKey = result.outputFile ? normalizeVitePersistentCacheKey(result.outputFile) : void 0;
|
|
3092
|
+
if (!activeFiles.has(key) && (outputKey == null || !activeFiles.has(outputKey))) results.delete(key);
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
3095
|
+
return {
|
|
3096
|
+
entries: () => results.entries(),
|
|
3097
|
+
get,
|
|
3098
|
+
getStats: () => ({
|
|
3099
|
+
viteProcessedCssAssetResults: results.size,
|
|
3100
|
+
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(results)
|
|
3101
|
+
}),
|
|
3102
|
+
markSource,
|
|
3103
|
+
matchesIdentity,
|
|
3104
|
+
prune,
|
|
3105
|
+
record,
|
|
3106
|
+
sourceFiles
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
//#endregion
|
|
3110
|
+
//#region src/bundlers/vite/shared/framework-hmr-runtime-signature.ts
|
|
3111
|
+
const WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE = /@(?:theme|source|config|plugin|apply)\b/;
|
|
3112
|
+
function createFrameworkHmrRuntimeSignature(file, source) {
|
|
3113
|
+
if (!source || !WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE.test(source)) return "";
|
|
3114
|
+
return (isSfcStyleSourceFile(cleanUrl$1(file)) ? extractSfcStyleSources(source).filter((styleSource) => WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE.test(styleSource)) : [source]).map((styleSource) => createRuntimeAffectingSourceSignature(styleSource, "css")).join("\0");
|
|
3115
|
+
}
|
|
3116
|
+
function hasFrameworkHmrRuntimeSourceChange(file, previousSource, nextSource) {
|
|
3117
|
+
return createFrameworkHmrRuntimeSignature(file, previousSource) !== createFrameworkHmrRuntimeSignature(file, nextSource);
|
|
3118
|
+
}
|
|
3119
|
+
//#endregion
|
|
3120
|
+
//#region src/bundlers/vite/shared/framework-source-scan-session.ts
|
|
3121
|
+
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
3122
|
+
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3123
|
+
async function syncFrameworkSourceCandidatesForHotUpdate(sourceScanSession, ctx) {
|
|
3124
|
+
const source = typeof ctx.read === "function" ? await ctx.read().catch(() => void 0) : void 0;
|
|
3125
|
+
await sourceScanSession.syncChangedFile(ctx.file, source);
|
|
3126
|
+
await sourceScanSession.waitForPendingSyncs();
|
|
3127
|
+
}
|
|
3128
|
+
function createFrameworkSourceScanSession(options) {
|
|
3129
|
+
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3130
|
+
let sourceScanEntries;
|
|
3131
|
+
let sourceScanMatcher;
|
|
3132
|
+
let sourceScanBoundaryMatcher;
|
|
3133
|
+
let sourceScanRoots = [];
|
|
3134
|
+
let sourceScanOutDir;
|
|
3135
|
+
let sourceScanEligibleFiles = /* @__PURE__ */ new Set();
|
|
3136
|
+
let sourceScanEligibleFilesRefresh;
|
|
3137
|
+
const sourceScanIneligibleFiles = /* @__PURE__ */ new Set();
|
|
3138
|
+
let sourceScanDependencies = /* @__PURE__ */ new Set();
|
|
3139
|
+
let sourceScanExplicit = false;
|
|
3140
|
+
let sourceCandidateScanSignature;
|
|
3141
|
+
let sourceCandidateScanInvalidated = true;
|
|
3142
|
+
const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
|
|
3143
|
+
const pendingSourceCandidateSyncByFile = /* @__PURE__ */ new Map();
|
|
3144
|
+
const pendingHotUpdateChangeByFile = /* @__PURE__ */ new Map();
|
|
3145
|
+
const pendingChangedFiles = /* @__PURE__ */ new Map();
|
|
3146
|
+
let pendingChangedFilesFlush;
|
|
3147
|
+
let isFlushingChangedFiles = false;
|
|
3148
|
+
let cacheDirty = false;
|
|
3149
|
+
let cachedCollectorRevision;
|
|
3150
|
+
const normalizeDependency = (file) => path.normalize(path.resolve(cleanUrl$1(file)));
|
|
3151
|
+
const isDependency = (file) => sourceScanDependencies.has(normalizeDependency(file));
|
|
3152
|
+
const invalidate = () => {
|
|
3153
|
+
sourceCandidateScanInvalidated = true;
|
|
3154
|
+
sourceScanIneligibleFiles.clear();
|
|
3155
|
+
};
|
|
3156
|
+
const hasState = () => sourceCandidateScanSignature !== void 0;
|
|
3157
|
+
const collectRoots = (root, entries) => {
|
|
3158
|
+
if (entries?.length) return [{
|
|
3159
|
+
entries,
|
|
3160
|
+
explicit: sourceScanExplicit,
|
|
3161
|
+
root
|
|
3162
|
+
}];
|
|
3163
|
+
if (sourceScanExplicit && entries !== void 0) return [];
|
|
3164
|
+
const roots = [{
|
|
3165
|
+
entries,
|
|
3166
|
+
root
|
|
3167
|
+
}];
|
|
3168
|
+
const seenRoots = /* @__PURE__ */ new Set([path.resolve(root)]);
|
|
3169
|
+
const basedir = options.opts.tailwindcssBasedir ? path.resolve(options.opts.tailwindcssBasedir) : void 0;
|
|
3170
|
+
if (basedir && !seenRoots.has(basedir)) {
|
|
3171
|
+
roots.push({ root: basedir });
|
|
3172
|
+
seenRoots.add(basedir);
|
|
3173
|
+
}
|
|
3174
|
+
for (const cssEntry of options.opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
3175
|
+
if (!isTailwindV4CssEntry(cssEntry)) continue;
|
|
3176
|
+
const cssEntryRoot = path.dirname(path.resolve(cssEntry));
|
|
3177
|
+
if (seenRoots.has(cssEntryRoot)) continue;
|
|
3178
|
+
roots.push({ root: cssEntryRoot });
|
|
3179
|
+
seenRoots.add(cssEntryRoot);
|
|
3180
|
+
}
|
|
3181
|
+
return roots;
|
|
3182
|
+
};
|
|
3183
|
+
const cacheCurrent = () => {
|
|
3184
|
+
if (!sourceCandidateScanSignature) return;
|
|
3185
|
+
if (isFlushingChangedFiles) {
|
|
3186
|
+
cacheDirty = true;
|
|
3187
|
+
return;
|
|
3188
|
+
}
|
|
3189
|
+
const collectorRevision = options.sourceCandidateCollector.getRevision?.();
|
|
3190
|
+
if (!cacheDirty && cachedCollectorRevision !== void 0 && collectorRevision === cachedCollectorRevision) return;
|
|
3191
|
+
const entry = {
|
|
3192
|
+
eligibleFiles: [...sourceScanEligibleFiles],
|
|
3193
|
+
snapshot: options.sourceCandidateCollector.snapshot()
|
|
3194
|
+
};
|
|
3195
|
+
sourceCandidateScanCache.set(sourceCandidateScanSignature, entry);
|
|
3196
|
+
sourceCandidateScanSnapshotCache.set(sourceCandidateScanSignature, entry);
|
|
3197
|
+
cachedCollectorRevision = collectorRevision;
|
|
3198
|
+
cacheDirty = false;
|
|
3199
|
+
};
|
|
3200
|
+
const updateSourceScanMatchers = (eligibleFiles) => {
|
|
3201
|
+
sourceScanEligibleFiles = new Set(eligibleFiles);
|
|
3202
|
+
const matcherRoots = sourceScanRoots.map((scanRoot) => ({
|
|
3203
|
+
...scanRoot,
|
|
3204
|
+
outDir: sourceScanOutDir
|
|
3205
|
+
}));
|
|
3206
|
+
sourceScanBoundaryMatcher = createSourceCandidateEligibilityMatcher(matcherRoots);
|
|
3207
|
+
sourceScanMatcher = createSourceCandidateEligibilityMatcher(matcherRoots, sourceScanEligibleFiles);
|
|
3208
|
+
};
|
|
3209
|
+
const refreshSourceScanEligibleFiles = async () => {
|
|
3210
|
+
sourceScanEligibleFilesRefresh ?? (sourceScanEligibleFilesRefresh = Promise.all(sourceScanRoots.map((scanRoot) => options.sourceCandidateCollector.resolveScanFiles({
|
|
3211
|
+
entries: scanRoot.entries,
|
|
3212
|
+
explicit: scanRoot.explicit,
|
|
3213
|
+
root: scanRoot.root,
|
|
3214
|
+
outDir: sourceScanOutDir
|
|
3215
|
+
}))).then((files) => updateSourceScanMatchers(files.flat())).finally(() => {
|
|
3216
|
+
sourceScanEligibleFilesRefresh = void 0;
|
|
3217
|
+
}));
|
|
3218
|
+
await sourceScanEligibleFilesRefresh;
|
|
3219
|
+
};
|
|
3220
|
+
const shouldDiscoverAutoCssSources = (autoCssSourcesDiscovered) => {
|
|
3221
|
+
if (!autoCssSourcesDiscovered || !options.isWatchLikeBuild()) return true;
|
|
3222
|
+
return sourceCandidateScanInvalidated;
|
|
3223
|
+
};
|
|
3224
|
+
const sync = async (syncOptions = {}) => {
|
|
3225
|
+
if (!options.shouldOwnTailwindGeneration) return;
|
|
3226
|
+
if (!syncOptions.force && options.isWatchLikeBuild() && hasState() && !sourceCandidateScanInvalidated) {
|
|
3227
|
+
options.debug("reuse vite source candidate scan definition for watch rebuild");
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
const resolvedConfig = options.getResolvedConfig();
|
|
3231
|
+
const root = resolvedConfig?.root ?? process$1.cwd();
|
|
3232
|
+
const outDir = resolvedConfig?.build?.outDir;
|
|
3233
|
+
const sourceScan = await resolveSourceScanEntries(options.opts, options.runtimeState.tailwindRuntime, {
|
|
3234
|
+
outDir,
|
|
3235
|
+
root
|
|
3236
|
+
});
|
|
3237
|
+
sourceScanEntries = sourceScan?.entries;
|
|
3238
|
+
sourceScanExplicit = sourceScan?.explicit ?? false;
|
|
3239
|
+
sourceScanDependencies = new Set((sourceScan?.dependencies ?? []).map(normalizeDependency));
|
|
3240
|
+
const roots = collectRoots(root, sourceScanEntries);
|
|
3241
|
+
sourceScanRoots = roots;
|
|
3242
|
+
sourceScanOutDir = outDir;
|
|
3243
|
+
const nextScanSignature = createSourceCandidateScanSignature({
|
|
3244
|
+
inlineCandidates: sourceScan?.inlineCandidates,
|
|
3245
|
+
outDir,
|
|
3246
|
+
roots,
|
|
3247
|
+
scanAllSources: !sourceScanExplicit
|
|
3248
|
+
});
|
|
3249
|
+
if (hasState() && sourceCandidateScanSignature === nextScanSignature) {
|
|
3250
|
+
options.sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
3251
|
+
cacheCurrent();
|
|
3252
|
+
options.debug("reuse vite source candidate scan for watch rebuild");
|
|
3253
|
+
sourceCandidateScanInvalidated = false;
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
const cachedScan = options.isWatchLikeBuild() ? sourceCandidateScanCache.get(nextScanSignature) ?? sourceCandidateScanSnapshotCache.get(nextScanSignature) : void 0;
|
|
3257
|
+
if (cachedScan) {
|
|
3258
|
+
options.sourceCandidateCollector.restore(cachedScan.snapshot);
|
|
3259
|
+
sourceScanIneligibleFiles.clear();
|
|
3260
|
+
updateSourceScanMatchers(cachedScan.eligibleFiles);
|
|
3261
|
+
sourceCandidateScanSignature = nextScanSignature;
|
|
3262
|
+
options.debug("reuse cached vite source candidate scan for watch rebuild");
|
|
3263
|
+
sourceCandidateScanInvalidated = false;
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
if (options.isWatchLikeBuild()) options.sourceCandidateCollector.resetScan();
|
|
3267
|
+
else options.sourceCandidateCollector.clearScan();
|
|
3268
|
+
options.sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
3269
|
+
const eligibleFiles = /* @__PURE__ */ new Set();
|
|
3270
|
+
sourceScanIneligibleFiles.clear();
|
|
3271
|
+
await Promise.all(roots.map((scanRoot) => options.sourceCandidateCollector.scanRoot({
|
|
3272
|
+
entries: scanRoot.entries,
|
|
3273
|
+
explicit: scanRoot.explicit,
|
|
3274
|
+
root: scanRoot.root,
|
|
3275
|
+
outDir,
|
|
3276
|
+
onFilesResolved: (files) => files.forEach((file) => eligibleFiles.add(file))
|
|
3277
|
+
})));
|
|
3278
|
+
updateSourceScanMatchers(eligibleFiles);
|
|
3279
|
+
sourceCandidateScanSignature = nextScanSignature;
|
|
3280
|
+
sourceCandidateScanInvalidated = false;
|
|
3281
|
+
if (options.isWatchLikeBuild()) cacheCurrent();
|
|
3282
|
+
};
|
|
3283
|
+
const waitForPendingSyncs = async () => {
|
|
3284
|
+
while (true) {
|
|
3285
|
+
if (!pendingChangedFilesFlush && pendingChangedFiles.size === 0 && pendingSourceCandidateSyncs.size === 0) break;
|
|
3286
|
+
await pendingChangedFilesFlush;
|
|
3287
|
+
if (pendingChangedFiles.size > 0) await flushChangedFiles();
|
|
3288
|
+
if (pendingSourceCandidateSyncs.size > 0) await Promise.all(pendingSourceCandidateSyncs);
|
|
3289
|
+
}
|
|
3290
|
+
};
|
|
3291
|
+
const rememberHotUpdateChange = (change) => {
|
|
3292
|
+
if (!change) return;
|
|
3293
|
+
const previous = pendingHotUpdateChangeByFile.get(change.file);
|
|
3294
|
+
if (!previous) {
|
|
3295
|
+
const remembered = {
|
|
3296
|
+
...change,
|
|
3297
|
+
addedCandidates: new Set(change.addedCandidates),
|
|
3298
|
+
removedCandidates: new Set(change.removedCandidates)
|
|
3299
|
+
};
|
|
3300
|
+
pendingHotUpdateChangeByFile.set(change.file, remembered);
|
|
3301
|
+
return remembered;
|
|
3302
|
+
}
|
|
3303
|
+
for (const candidate of change.addedCandidates) {
|
|
3304
|
+
previous.addedCandidates.add(candidate);
|
|
3305
|
+
previous.removedCandidates.delete(candidate);
|
|
3306
|
+
}
|
|
3307
|
+
for (const candidate of change.removedCandidates) if (!previous.addedCandidates.delete(candidate)) previous.removedCandidates.add(candidate);
|
|
3308
|
+
previous.runtimeAffecting || (previous.runtimeAffecting = change.runtimeAffecting);
|
|
3309
|
+
return previous;
|
|
3310
|
+
};
|
|
3311
|
+
const syncChangedFileNow = async (id, sourceOverride, event = "update") => {
|
|
3312
|
+
if (!options.shouldOwnTailwindGeneration || !options.isCandidateRequest(id)) return;
|
|
3313
|
+
const file = cleanUrl$1(id);
|
|
3314
|
+
const runtimeAffectingByDependency = isDependency(file);
|
|
3315
|
+
if (runtimeAffectingByDependency) invalidate();
|
|
3316
|
+
const resolvedFile = resolveSourceScanPath(file);
|
|
3317
|
+
if (sourceScanMatcher && !sourceScanMatcher(file) && sourceScanBoundaryMatcher?.(file) && !sourceScanIneligibleFiles.has(resolvedFile)) {
|
|
3318
|
+
await refreshSourceScanEligibleFiles();
|
|
3319
|
+
if (!sourceScanMatcher(file)) sourceScanIneligibleFiles.add(resolvedFile);
|
|
3320
|
+
}
|
|
3321
|
+
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
3322
|
+
const change = options.sourceCandidateCollector.remove(file);
|
|
3323
|
+
cacheCurrent();
|
|
3324
|
+
return (isSourceStyleRequest(file) ? readFile(file, "utf8").then((source) => options.cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
3325
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ENOENT") options.debug("remembered css source watch refresh failed: %s %O", file, error);
|
|
3326
|
+
}) : Promise.resolve()).then(() => options.cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => rememberHotUpdateChange(options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, change, { runtimeAffecting: true }))));
|
|
3327
|
+
}
|
|
3328
|
+
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
3329
|
+
if (existingTask) {
|
|
3330
|
+
await existingTask;
|
|
3331
|
+
return syncChangedFile(id, sourceOverride);
|
|
3332
|
+
}
|
|
3333
|
+
const previousSource = options.sourceCandidateCollector.source(file);
|
|
3334
|
+
if (event === "delete") {
|
|
3335
|
+
const change = options.sourceCandidateCollector.remove(file);
|
|
3336
|
+
cacheDirty = true;
|
|
3337
|
+
const appliedChange = options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, change, { runtimeAffecting: runtimeAffectingByDependency }));
|
|
3338
|
+
return rememberHotUpdateChange(appliedChange);
|
|
3339
|
+
}
|
|
3340
|
+
const task = (sourceOverride === void 0 ? options.sourceCandidateCollector.syncCurrentFile(id) : options.sourceCandidateCollector.syncCurrentSource(id, sourceOverride)).catch((error) => {
|
|
3341
|
+
options.debug("source candidate watch sync failed: %s %O", id, error);
|
|
3342
|
+
}).then((change) => {
|
|
3343
|
+
cacheDirty = true;
|
|
3344
|
+
if (!isFlushingChangedFiles) cacheCurrent();
|
|
3345
|
+
const runtimeAffectingBySource = hasFrameworkHmrRuntimeSourceChange(file, previousSource, options.sourceCandidateCollector.source(file));
|
|
3346
|
+
const appliedChange = change ? options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, change, { runtimeAffecting: runtimeAffectingByDependency || runtimeAffectingBySource })) : void 0;
|
|
3347
|
+
return rememberHotUpdateChange(appliedChange) ?? pendingHotUpdateChangeByFile.get(file);
|
|
3348
|
+
}).finally(() => {
|
|
3349
|
+
pendingSourceCandidateSyncs.delete(task);
|
|
3350
|
+
pendingSourceCandidateSyncByFile.delete(file);
|
|
3351
|
+
});
|
|
3352
|
+
pendingSourceCandidateSyncs.add(task);
|
|
3353
|
+
pendingSourceCandidateSyncByFile.set(file, task);
|
|
3354
|
+
return task.then(async (change) => {
|
|
3355
|
+
await options.cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
3356
|
+
return change;
|
|
3357
|
+
});
|
|
3358
|
+
};
|
|
3359
|
+
const queueChangedFile = (change) => {
|
|
3360
|
+
const file = cleanUrl$1(change.id);
|
|
3361
|
+
const previous = pendingChangedFiles.get(file);
|
|
3362
|
+
if (!previous) {
|
|
3363
|
+
pendingChangedFiles.set(file, {
|
|
3364
|
+
...change,
|
|
3365
|
+
file
|
|
3366
|
+
});
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
previous.event = change.event;
|
|
3370
|
+
if (change.source !== void 0) previous.source = change.source;
|
|
3371
|
+
};
|
|
3372
|
+
const flushChangedFiles = async () => {
|
|
3373
|
+
if (pendingChangedFilesFlush) {
|
|
3374
|
+
const result = await pendingChangedFilesFlush;
|
|
3375
|
+
return pendingChangedFiles.size > 0 ? flushChangedFiles() : result;
|
|
3376
|
+
}
|
|
3377
|
+
if (pendingChangedFiles.size === 0) return /* @__PURE__ */ new Map();
|
|
3378
|
+
const changes = [...pendingChangedFiles.values()];
|
|
3379
|
+
pendingChangedFiles.clear();
|
|
3380
|
+
isFlushingChangedFiles = true;
|
|
3381
|
+
pendingChangedFilesFlush = Promise.all(changes.map(async (change) => [change.file, await syncChangedFileNow(change.file, change.source, change.event)])).then((entries) => new Map(entries)).finally(() => {
|
|
3382
|
+
isFlushingChangedFiles = false;
|
|
3383
|
+
pendingChangedFilesFlush = void 0;
|
|
3384
|
+
cacheCurrent();
|
|
3385
|
+
});
|
|
3386
|
+
return pendingChangedFilesFlush;
|
|
3387
|
+
};
|
|
3388
|
+
const syncChangedFile = async (id, sourceOverride) => {
|
|
3389
|
+
const file = cleanUrl$1(id);
|
|
3390
|
+
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
3391
|
+
if (existingTask) {
|
|
3392
|
+
await existingTask;
|
|
3393
|
+
return syncChangedFile(id, sourceOverride);
|
|
3394
|
+
}
|
|
3395
|
+
return syncChangedFileNow(file, sourceOverride);
|
|
3396
|
+
};
|
|
3397
|
+
return {
|
|
3398
|
+
cacheCurrent,
|
|
3399
|
+
consumeHotUpdateChange: (id) => pendingHotUpdateChangeByFile.delete(cleanUrl$1(id)),
|
|
3400
|
+
getStats: () => ({
|
|
3401
|
+
pendingSourceCandidateSyncByFile: pendingSourceCandidateSyncByFile.size,
|
|
3402
|
+
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
3403
|
+
pendingChangedFiles: pendingChangedFiles.size,
|
|
3404
|
+
pendingHotUpdateChangeByFile: pendingHotUpdateChangeByFile.size,
|
|
3405
|
+
sourceCandidateScanCache: sourceCandidateScanCache.size
|
|
3406
|
+
}),
|
|
3407
|
+
invalidate,
|
|
3408
|
+
isDependency,
|
|
3409
|
+
matches: (file) => sourceScanMatcher?.(file) ?? true,
|
|
3410
|
+
queueChangedFile,
|
|
3411
|
+
flushChangedFiles,
|
|
3412
|
+
shouldDiscoverAutoCssSources,
|
|
3413
|
+
sync,
|
|
3414
|
+
syncChangedFile,
|
|
3415
|
+
waitForPendingSyncs
|
|
3416
|
+
};
|
|
3417
|
+
}
|
|
3418
|
+
//#endregion
|
|
3419
|
+
//#region src/bundlers/vite/shared/framework-tailwind-root-css.ts
|
|
3420
|
+
function createFrameworkTailwindRootCss(options) {
|
|
3421
|
+
const hotSourceByFile = /* @__PURE__ */ new Map();
|
|
3422
|
+
const moduleIds = /* @__PURE__ */ new Set();
|
|
3423
|
+
const normalizeSourceFile = (id) => resolveViteModuleIdentity(id).key;
|
|
3424
|
+
const rememberModule = (id) => {
|
|
3425
|
+
if (!options.shouldOwnTailwindGeneration || typeof id !== "string" || id.length === 0) return;
|
|
3426
|
+
moduleIds.add(id);
|
|
3427
|
+
const identity = resolveViteModuleIdentity(id);
|
|
3428
|
+
if (isSourceStyleRequest(identity.cleanId)) for (const moduleId of identity.lookupIds) moduleIds.add(moduleId);
|
|
3429
|
+
};
|
|
3430
|
+
const register = async (id, code) => {
|
|
3431
|
+
rememberModule(id);
|
|
3432
|
+
const hotSource = hotSourceByFile.get(normalizeSourceFile(id));
|
|
3433
|
+
await options.registerAutoCssSource(id, hotSource ?? code);
|
|
3434
|
+
};
|
|
3435
|
+
const refreshSource = async (id, code) => {
|
|
3436
|
+
const file = cleanUrl$1(id);
|
|
3437
|
+
if (!moduleIds.has(id) && !moduleIds.has(file) && !hasTailwindRootDirectives(code, { importFallback: options.getImportFallback() })) return;
|
|
3438
|
+
hotSourceByFile.set(normalizeSourceFile(id), code);
|
|
3439
|
+
await register(id, code);
|
|
3440
|
+
options.sourceScanSession.invalidate();
|
|
3441
|
+
await options.refreshRuntimeState(true);
|
|
3442
|
+
await options.sourceScanSession.sync({ force: true });
|
|
3443
|
+
};
|
|
3444
|
+
return {
|
|
3445
|
+
refreshSource,
|
|
3446
|
+
register,
|
|
3447
|
+
rememberModule,
|
|
3448
|
+
moduleIds
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
//#endregion
|
|
3452
|
+
//#region src/style-injector/vite-web.ts
|
|
3453
|
+
function getHandler(hook) {
|
|
3454
|
+
if (typeof hook === "function") return hook;
|
|
3455
|
+
if (hook && typeof hook === "object" && typeof hook.handler === "function") return hook.handler;
|
|
3456
|
+
}
|
|
3457
|
+
/** Generic Web 专用 style injector,避免引入其他构建器和框架适配。 */
|
|
3458
|
+
function createBuiltinViteWebStyleInjectorPlugins(options) {
|
|
3459
|
+
const normalized = normalizeStyleInjectorOptions(options);
|
|
3460
|
+
if (!normalized) return [];
|
|
3461
|
+
const injector = weappStyleInjector(normalized);
|
|
3462
|
+
const transform = getHandler(injector.transform);
|
|
3463
|
+
const generateBundle = getHandler(injector.generateBundle);
|
|
3464
|
+
return [{
|
|
3465
|
+
name: "weapp-tailwindcss:web-style-injector-pre",
|
|
3466
|
+
apply: "build",
|
|
3467
|
+
enforce: "pre",
|
|
3468
|
+
configResolved(config) {
|
|
3469
|
+
injector.configResolved?.(config);
|
|
3470
|
+
},
|
|
3471
|
+
async buildStart() {
|
|
3472
|
+
await injector.buildStart?.call(this, {});
|
|
3473
|
+
},
|
|
3474
|
+
async transform(code, id, options2) {
|
|
3475
|
+
return transform?.call(this, code, id, options2);
|
|
3476
|
+
}
|
|
3477
|
+
}, {
|
|
3478
|
+
name: "weapp-tailwindcss:web-style-injector",
|
|
3479
|
+
apply: "build",
|
|
3480
|
+
enforce: "post",
|
|
3481
|
+
configResolved(config) {
|
|
3482
|
+
injector.configResolved?.(config);
|
|
3483
|
+
},
|
|
3484
|
+
async generateBundle(outputOptions, bundle, isWrite) {
|
|
3485
|
+
await generateBundle?.call(this, outputOptions, bundle, isWrite);
|
|
3486
|
+
}
|
|
3487
|
+
}];
|
|
3488
|
+
}
|
|
3489
|
+
//#endregion
|
|
3490
|
+
//#region src/bundlers/vite/shared/create-css-only-plugins-runtime.ts
|
|
3491
|
+
const debug = createDebug();
|
|
3492
|
+
function resolveWebGeneratorOptions(opts) {
|
|
3493
|
+
return normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3494
|
+
appType: void 0,
|
|
3495
|
+
platform: "web",
|
|
3496
|
+
tailwindcssMajorVersion: opts.tailwindRuntime.majorVersion,
|
|
3497
|
+
uniAppX: false
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
/** 创建不含 JS/template、分包和小程序 bundle 处理的 Generic Web Vite 插件。 */
|
|
3501
|
+
function createCssOnlyVitePlugins(options = {}) {
|
|
3502
|
+
const rawOptions = options;
|
|
3503
|
+
const opts = "tailwindRuntime" in options ? options : getCompilerContext({
|
|
3504
|
+
...rawOptions,
|
|
3505
|
+
appType: void 0,
|
|
3506
|
+
platform: "web",
|
|
3507
|
+
generator: rawOptions.generator && typeof rawOptions.generator === "object" ? {
|
|
3508
|
+
...rawOptions.generator,
|
|
3509
|
+
target: "web"
|
|
3510
|
+
} : { target: "web" },
|
|
3511
|
+
__internalDeferMissingCssEntriesWarning: true,
|
|
3512
|
+
__internalViteDeferRuntimeLogs: true
|
|
3513
|
+
});
|
|
3514
|
+
const disabled = opts.disabled === true || typeof opts.disabled === "object" && opts.disabled.plugin === true;
|
|
3515
|
+
const shouldGenerate = !disabled && resolveWebGeneratorOptions(opts).enabled;
|
|
3516
|
+
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
3517
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
3518
|
+
customAttributesEntities: opts.customAttributesEntities,
|
|
3519
|
+
disabledDefaultTemplateHandler: opts.disabledDefaultTemplateHandler
|
|
3520
|
+
});
|
|
3521
|
+
const cssMemory = createViteCssMemory({
|
|
3522
|
+
debug,
|
|
3523
|
+
getSourceCandidateSource: (file) => sourceCandidateCollector.source(file)
|
|
3524
|
+
});
|
|
3525
|
+
const hmrCssModuleVersions = createViteHmrCssModuleVersionTracker();
|
|
3526
|
+
const hmrTimingRecorder = createHmrTimingRecorder("vite");
|
|
3527
|
+
const { runtimeState, ensureRuntimeClassSet, refreshRuntimeState } = createViteRuntimeClassSet({
|
|
3528
|
+
opts,
|
|
3529
|
+
initialTailwindRuntime: opts.tailwindRuntime,
|
|
3530
|
+
refreshTailwindcssRuntime: opts.refreshTailwindcssRuntime,
|
|
3531
|
+
uniAppXEnabled: false,
|
|
3532
|
+
customAttributesEntities: opts.customAttributesEntities,
|
|
3533
|
+
disabledDefaultTemplateHandler: opts.disabledDefaultTemplateHandler,
|
|
3534
|
+
debug
|
|
3535
|
+
});
|
|
3536
|
+
const hmrCandidateState = createViteHmrCandidateState({
|
|
3537
|
+
cleanGeneratedCssByFile: /* @__PURE__ */ new Map(),
|
|
3538
|
+
generatedClassSetByFile: /* @__PURE__ */ new Map(),
|
|
3539
|
+
getCommand: () => resolvedConfig?.command,
|
|
3540
|
+
getGeneratorOptions: () => resolveWebGeneratorOptions(opts),
|
|
3541
|
+
isRuntimeAffectingSource: () => false
|
|
3542
|
+
});
|
|
3543
|
+
let resolvedConfig;
|
|
3544
|
+
let recordedCandidates;
|
|
3545
|
+
const processedCssRegistry = createFrameworkProcessedCssRegistry();
|
|
3546
|
+
const processedCssAssets = /* @__PURE__ */ new WeakSet();
|
|
3547
|
+
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
3548
|
+
const sourceScanSession = createFrameworkSourceScanSession({
|
|
3549
|
+
cssMemory,
|
|
3550
|
+
debug,
|
|
3551
|
+
getResolvedConfig: () => resolvedConfig,
|
|
3552
|
+
hmrCandidateState,
|
|
3553
|
+
isCandidateRequest: isSourceCandidateRequest,
|
|
3554
|
+
isWatchLikeBuild: () => resolvedConfig?.command === "serve" || resolvedConfig?.build.watch != null,
|
|
3555
|
+
opts,
|
|
3556
|
+
runtimeState,
|
|
3557
|
+
shouldOwnTailwindGeneration: shouldGenerate,
|
|
3558
|
+
sourceCandidateCollector
|
|
3559
|
+
});
|
|
3560
|
+
const { refreshSource: refreshTailwindRootCssSource, register: registerTailwindRootCss, rememberModule: rememberTailwindRootCssModule } = createFrameworkTailwindRootCss({
|
|
3561
|
+
getImportFallback: () => resolveWebGeneratorOptions(opts).importFallback,
|
|
3562
|
+
refreshRuntimeState: async () => {
|
|
3563
|
+
await refreshRuntimeState(true);
|
|
3564
|
+
},
|
|
3565
|
+
registerAutoCssSource: async (id, css) => {
|
|
3566
|
+
cssMemory.refreshRememberedCssSourceBySourceFile(id, normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(css, path.dirname(cleanUrl$1(id))), { importFallback: true }));
|
|
3567
|
+
},
|
|
3568
|
+
shouldOwnTailwindGeneration: shouldGenerate,
|
|
3569
|
+
sourceScanSession
|
|
3570
|
+
});
|
|
3571
|
+
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
3572
|
+
getAppType: () => void 0,
|
|
3573
|
+
mainCssChunkMatcher: opts.mainCssChunkMatcher,
|
|
3574
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
3575
|
+
getOutputRoot: () => resolvedConfig?.root
|
|
3576
|
+
});
|
|
3577
|
+
const generatedCssByFile = /* @__PURE__ */ new Map();
|
|
3578
|
+
const generateCss = createFrameworkCssGenerationQueue((id) => cleanUrl$1(id), async (id, code, hookContext) => {
|
|
3579
|
+
if (!shouldGenerate || !isCSSRequest(id)) return;
|
|
3580
|
+
await runtimeState.readyPromise;
|
|
3581
|
+
await sourceScanSession.waitForPendingSyncs();
|
|
3582
|
+
const file = cleanUrl$1(id);
|
|
3583
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, resolvedConfig?.root ?? process$1.cwd(), true, false, void 0);
|
|
3584
|
+
const runtime = hookContext?.sourceCandidates ? new Set(hookContext.sourceCandidates) : await ensureRuntimeClassSet();
|
|
3585
|
+
const generated = await generateTailwindV4Css({
|
|
3586
|
+
opts,
|
|
3587
|
+
runtimeState,
|
|
3588
|
+
runtime,
|
|
3589
|
+
compilerMode: "legacy",
|
|
3590
|
+
rawSource: normalizeEmptyTailwindCustomVariants(code),
|
|
3591
|
+
file,
|
|
3592
|
+
outputFile,
|
|
3593
|
+
cssHandlerOptions: cssHandlerOptions.getCssHandlerOptions(file),
|
|
3594
|
+
cssUserHandlerOptions: cssHandlerOptions.getCssUserHandlerOptions(file),
|
|
3595
|
+
getSourceCandidatesForEntries: (entries) => sourceCandidateCollector.valuesForEntries(entries),
|
|
3596
|
+
generatorPlatform: "web",
|
|
3597
|
+
styleHandler: opts.styleHandler,
|
|
3598
|
+
debug,
|
|
3599
|
+
cssStage: hookContext?.cssStage
|
|
3600
|
+
});
|
|
3601
|
+
if (!generated) return;
|
|
3602
|
+
const tracedCss = annotateCssSourceTrace(generated.css, {
|
|
3603
|
+
opts,
|
|
3604
|
+
tokenSources: isCssSourceTraceEnabled(opts) ? createCssTokenSourceMap(sourceCandidateCollector.sourcesForEntries(void 0), opts) : void 0
|
|
3605
|
+
});
|
|
3606
|
+
generatedCssByFile.set(file, tracedCss);
|
|
3607
|
+
processedCssRegistry.record(file, tracedCss, {
|
|
3608
|
+
injectIntoMain: opts.mainCssChunkMatcher(outputFile, void 0),
|
|
3609
|
+
outputFile
|
|
3610
|
+
});
|
|
3611
|
+
processedCssRegistry.markSource(file);
|
|
3612
|
+
recordedCandidates = new Set(runtime);
|
|
3613
|
+
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
3614
|
+
return `${createBundlerGeneratedCssMarker("vite", file)}\n${tracedCss}`;
|
|
3615
|
+
});
|
|
3616
|
+
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
3617
|
+
getAppType: () => void 0,
|
|
3618
|
+
generateTailwindCss: generateCss,
|
|
3619
|
+
rootImport: `${path.join(resolvePackageDir("weapp-tailwindcss"), "generator-placeholder.css").replaceAll(path.sep, "/")}`,
|
|
3620
|
+
onTailwindRootCss: registerTailwindRootCss,
|
|
3621
|
+
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
3622
|
+
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
3623
|
+
shouldDeferGeneration: () => false,
|
|
3624
|
+
shouldOwnTailwindGeneration: shouldGenerate,
|
|
3625
|
+
shouldRewrite: opts.rewriteCssImports === true,
|
|
3626
|
+
weappTailwindcssDirPosix: path.dirname(path.resolve(process$1.cwd(), "generator-placeholder.css")).replaceAll(path.sep, "/")
|
|
3627
|
+
});
|
|
3628
|
+
if (disabled) return rewritePlugins;
|
|
3629
|
+
const sourceCandidatesPlugin = createFrameworkSourceCandidatesPluginForCssOnly({
|
|
3630
|
+
cssMemory,
|
|
3631
|
+
hmrCandidateState,
|
|
3632
|
+
hmrCssModuleVersions,
|
|
3633
|
+
hmrTimingRecorder,
|
|
3634
|
+
invalidateRecordedGeneratorCandidates: () => {
|
|
3635
|
+
recordedCandidates = void 0;
|
|
3636
|
+
},
|
|
3637
|
+
prepareTailwindGeneration: () => sourceScanSession.sync(),
|
|
3638
|
+
refreshRuntimeStateForAutoCssSources: async () => {
|
|
3639
|
+
await refreshRuntimeState(true);
|
|
3640
|
+
},
|
|
3641
|
+
refreshTailwindRootCssSource,
|
|
3642
|
+
rememberTailwindRootCssModule,
|
|
3643
|
+
resolveCurrentGeneratorBranch: () => resolveGeneratorRuntimeBranch(resolveWebGeneratorOptions(opts), {
|
|
3644
|
+
appType: void 0,
|
|
3645
|
+
platform: "web",
|
|
3646
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3647
|
+
uniAppX: false
|
|
3648
|
+
}),
|
|
3649
|
+
resolveCurrentGeneratorOptions: () => resolveWebGeneratorOptions(opts),
|
|
3650
|
+
runtimeState,
|
|
3651
|
+
sourceCandidateCollector,
|
|
3652
|
+
sourceScanSession,
|
|
3653
|
+
tailwindRootCssModuleIds,
|
|
3654
|
+
viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles
|
|
3655
|
+
});
|
|
3656
|
+
const postPlugin = createFrameworkPostPlugin({
|
|
3657
|
+
debug,
|
|
3658
|
+
generateBundleHook: void 0,
|
|
3659
|
+
generatorPlaceholderCssFile: path.join(resolvePackageDir("weapp-tailwindcss"), "generator-placeholder.css"),
|
|
3660
|
+
hasExplicitTailwindcssBasedir: false,
|
|
3661
|
+
hasExplicitGeneratorTarget: true,
|
|
3662
|
+
frameworkName: "generic",
|
|
3663
|
+
hmrTimingRecorder,
|
|
3664
|
+
opts,
|
|
3665
|
+
resolveViteStylePlatform: () => "web",
|
|
3666
|
+
refreshRuntimeState: async () => {
|
|
3667
|
+
await refreshRuntimeState(true);
|
|
3668
|
+
},
|
|
3669
|
+
setResolvedConfig: (config) => {
|
|
3670
|
+
resolvedConfig = config;
|
|
3671
|
+
},
|
|
3672
|
+
shouldInferAppType: false,
|
|
3673
|
+
shouldOwnTailwindGeneration: shouldGenerate,
|
|
3674
|
+
syncCssEntriesFromAnchor: () => false
|
|
3675
|
+
});
|
|
3676
|
+
const finalizer = createViteWebCssFinalizerOutputPlugin({
|
|
3677
|
+
opts,
|
|
3678
|
+
runtimeState,
|
|
3679
|
+
ensureRuntimeClassSet,
|
|
3680
|
+
debug,
|
|
3681
|
+
frameworkName: "generic",
|
|
3682
|
+
getResolvedConfig: () => resolvedConfig,
|
|
3683
|
+
markCssAssetProcessed: (asset) => {
|
|
3684
|
+
processedCssAssets.add(asset);
|
|
3685
|
+
},
|
|
3686
|
+
isCssAssetProcessed: (asset) => processedCssAssets.has(asset),
|
|
3687
|
+
isViteProcessedCssAsset: () => true,
|
|
3688
|
+
resolveCssAssetIdentity: createViteCssAssetIdentityResolver({
|
|
3689
|
+
generatorPlaceholderFile: path.join(resolvePackageDir("weapp-tailwindcss"), "generator-placeholder.css"),
|
|
3690
|
+
isKnownProcessedSource: processedCssRegistry.matchesIdentity
|
|
3691
|
+
}),
|
|
3692
|
+
recordCssAssetResult: (file, css) => {
|
|
3693
|
+
generatedCssByFile.set(file, css);
|
|
3694
|
+
},
|
|
3695
|
+
recordViteProcessedCssAssetResult: processedCssRegistry.record,
|
|
3696
|
+
getViteProcessedCssAssetResults: processedCssRegistry.entries,
|
|
3697
|
+
getRecordedGeneratorCandidates: () => recordedCandidates,
|
|
3698
|
+
getSourceCandidates: () => sourceCandidateCollector.values(),
|
|
3699
|
+
getSourceCandidatesForEntries: (entries) => sourceCandidateCollector.valuesForEntries(entries),
|
|
3700
|
+
getSourceCandidateSourcesForEntries: (entries) => sourceCandidateCollector.sourcesForEntries(entries),
|
|
3701
|
+
waitForSourceCandidateSyncs: sourceScanSession.waitForPendingSyncs,
|
|
3702
|
+
hmrTimingRecorder
|
|
3703
|
+
});
|
|
3704
|
+
const plugins = [
|
|
3705
|
+
...rewritePlugins,
|
|
3706
|
+
sourceCandidatesPlugin,
|
|
3707
|
+
...createViteCssGenerationPlugins({
|
|
3708
|
+
generateCss,
|
|
3709
|
+
getCommand: () => resolvedConfig?.command,
|
|
3710
|
+
onTailwindRootCss: registerTailwindRootCss,
|
|
3711
|
+
shouldGenerate: () => shouldGenerate,
|
|
3712
|
+
shouldGenerateBuild: () => true
|
|
3713
|
+
}),
|
|
3714
|
+
postPlugin,
|
|
3715
|
+
finalizer,
|
|
3716
|
+
createViteHmrCssModuleVersionFilterPlugin(hmrCssModuleVersions)
|
|
3717
|
+
];
|
|
3718
|
+
const styleInjectorFactory = options.__internalViteWebStyleInjectorFactory;
|
|
3719
|
+
if (opts.styleInjector !== void 0 && typeof styleInjectorFactory === "function") plugins.push(...styleInjectorFactory(opts.styleInjector));
|
|
3720
|
+
return plugins;
|
|
3721
|
+
}
|
|
3722
|
+
function createFrameworkSourceCandidatesPluginForCssOnly(options) {
|
|
3723
|
+
return {
|
|
3724
|
+
name: `${vitePluginName}:source-candidates`,
|
|
3725
|
+
enforce: "pre",
|
|
3726
|
+
async transform(code, id) {
|
|
3727
|
+
if (!options.sourceCandidateCollector || !isSourceCandidateRequest(id)) return;
|
|
3728
|
+
options.cssMemory.rememberKnownSfcSource(id, code);
|
|
3729
|
+
if (isCSSRequest(id) && hasUserCssLayerBlocks(code)) options.rememberTailwindRootCssModule(id);
|
|
3730
|
+
await options.sourceCandidateCollector.merge(id, code);
|
|
3731
|
+
},
|
|
3732
|
+
async watchChange(id) {
|
|
3733
|
+
options.invalidateRecordedGeneratorCandidates();
|
|
3734
|
+
options.sourceScanSession.invalidate();
|
|
3735
|
+
await options.sourceScanSession.syncChangedFile(id);
|
|
3736
|
+
},
|
|
3737
|
+
async handleHotUpdate(ctx) {
|
|
3738
|
+
options.invalidateRecordedGeneratorCandidates();
|
|
3739
|
+
await options.sourceScanSession.syncChangedFile(ctx.file, await ctx.read?.());
|
|
3740
|
+
await options.sourceScanSession.waitForPendingSyncs();
|
|
3741
|
+
await options.refreshRuntimeStateForAutoCssSources(true);
|
|
3742
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
3743
|
+
const cssModules = await resolveHotTailwindCssModules(ctx, options.tailwindRootCssModuleIds, (modules) => options.hmrCssModuleVersions.filterModules(modules, ctx.timestamp, root));
|
|
3744
|
+
return cssModules.length > 0 ? mergeHotModulesByIdentity(root, ctx.modules, cssModules) : void 0;
|
|
3745
|
+
}
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3748
|
+
//#endregion
|
|
3749
|
+
//#region src/bundlers/vite/frameworks/generic/web.ts
|
|
3750
|
+
/** Generic Web CSS-only profile,供 `vite/web` 入口直接使用。 */
|
|
3751
|
+
function createGenericWebVitePlugins(options = {}) {
|
|
3752
|
+
const capability = createGenericWebViteCapabilityProfile(options);
|
|
3753
|
+
const owner = createViteSourceOutputRelationOwner();
|
|
3754
|
+
const plugins = withViteSourceOutputRelationOwner(owner, () => createCssOnlyVitePlugins({
|
|
3755
|
+
...options,
|
|
3756
|
+
__internalViteCapabilityProfile: capability,
|
|
3757
|
+
__internalViteWebStyleInjectorFactory: createBuiltinViteWebStyleInjectorPlugins
|
|
3758
|
+
}));
|
|
3759
|
+
if (!plugins) {
|
|
3760
|
+
owner.dispose();
|
|
3761
|
+
return;
|
|
3762
|
+
}
|
|
3763
|
+
return plugins.map((plugin) => {
|
|
3764
|
+
const wrapped = { ...plugin };
|
|
3765
|
+
if (plugin.watchChange) {
|
|
3766
|
+
const hook = plugin.watchChange;
|
|
3767
|
+
wrapped.watchChange = async function(...args) {
|
|
3768
|
+
const id = args[0];
|
|
3769
|
+
if (args[1]?.event === "delete") owner.removeSource(id);
|
|
3770
|
+
else if (typeof id === "string") owner.observeSource(id);
|
|
3771
|
+
return typeof hook === "function" ? hook.apply(this, args) : hook.handler?.apply(this, args);
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
if (plugin.handleHotUpdate) {
|
|
3775
|
+
const hook = plugin.handleHotUpdate;
|
|
3776
|
+
wrapped.handleHotUpdate = async function(...args) {
|
|
3777
|
+
const file = args[0]?.file;
|
|
3778
|
+
if (typeof file === "string") owner.observeSource(file);
|
|
3779
|
+
return typeof hook === "function" ? hook.apply(this, args) : hook.handler?.apply(this, args);
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
if (plugin.closeBundle) {
|
|
3783
|
+
const hook = plugin.closeBundle;
|
|
3784
|
+
wrapped.closeBundle = async function(...args) {
|
|
3785
|
+
try {
|
|
3786
|
+
return typeof hook === "function" ? await hook.apply(this, args) : await hook.handler?.apply(this, args);
|
|
3787
|
+
} finally {
|
|
3788
|
+
owner.dispose();
|
|
3789
|
+
}
|
|
3790
|
+
};
|
|
3791
|
+
}
|
|
3792
|
+
return wrapped;
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
//#endregion
|
|
3796
|
+
export { isMatchingCssSourceFile as $, createGenericWebProductionSourceCandidatesApply as A, resolveViteCssPipelineOutputFileFromSourceFile as At, parseVueRequest as B, createViteCssAssetIdentityResolver as Bt, collectViteProcessedCssSources as C, SOURCE_STYLE_OUTPUT_EXT_RE as Ct, registerGeneratorDependencies as D, resolveReplayCssOutputFile as Dt, inferPlatformFromViteOutDir as E, resolveMiniProgramStyleOutputExtension as Et, resolveHotSourceModulesByIds as F, normalizePath as Ft, hasSfcStyleSources as G, frameworkViteCapabilityProfile as Gt, shouldApplyViteWebCssCompat as H, getActiveViteSourceOutputRelationOwner as Ht, resolveHotTailwindCssModules as I, resolveViteCssPipelineRequestFile as It, normalizeSfcSourceFileForCompare as J, hasTailwindGenerationSource as K, sendFullReloadForUnresolvedHotUpdate as L, slash as Lt, hasSelfAcceptingNonStyleHotModule as M, formatPostcssSourceMap as Mt, mergeHotModulesByIdentity as N, isCSSRequest as Nt, shouldGenerateCssByGenerator as O, resolveViteCssOutputFile as Ot, resolveHotSourceModules as P, isHTMLRequest as Pt, hasMatchingStyleFileBase as Q, sendSupplementalCssHotUpdates as R, createCssHandlerOptionsCache as Rt, tryFinalizeGenericWebCss as S, CSS_SOURCE_OUTPUT_EXT_RE as St, finalizeWebCss as T, normalizeCssSourceForCompare as Tt, collectChunkModuleIds as U, withViteSourceOutputRelationOwner as Ut, resolveViteWebCssCompatOptions as V, createViteSourceOutputRelationOwner as Vt, extractSfcStyleBlocks as W, createGenericWebViteCapabilityProfile as Wt, resolveSfcStyleSourceFromOutputFile as X, resolveSfcStyleRequestFromKnownSource as Y, resolveSourceStyleSourceFromOutputFile as Z, summarizeStringCache as _, resolveViteProcessedCssAssetSource as _t, createFrameworkProcessedCssRegistry as a, createCssAssetPipelineContext as at, touchMapEntry as b, isRootStyleOutputFile as bt, createViteHmrCssModuleVersionTracker as c, hasNonCommentCss as ct, createViteCssGenerationPlugins as d, normalizeInjectableCssForTarget as dt, appendCss as et, createViteRuntimeClassSet as f, normalizeInjectableCssForTargetWithImports as ft, normalizeVitePersistentCacheKey as g, removeTailwindEntryDirectivesFromCss as gt, isMissingInternalCssSource as h, removeDuplicateUnlinkedRootCssAssetsReferencedByHtml as ht, syncFrameworkSourceCandidatesForHotUpdate as i, collectRootStyleBundleCssSources as it, shouldSkipGenericWebProductionSourceCandidates as j, cleanUrl$1 as jt, createGenericWebProductionBundleHooks as k, resolveViteCssPipelineOutputFile as kt, createViteHmrCandidateState as l, isMatchingGeneratedCssMarkerFile as lt, hasVitePipelineTailwindGenerationDirective as m, readAssetSource$1 as mt, createFrameworkTailwindRootCss as n, collectImportedStyleFiles as nt, createFrameworkPostPlugin as o, dedupeViteCssResults as ot, createRewriteCssImportsPlugins as p, normalizeMarkerOutputFile as pt, isSfcStyleSourceFile as q, createFrameworkSourceScanSession as r, collectMatchingGeneratedCssMarkerFiles as rt, createViteHmrCssModuleVersionFilterPlugin as s, getAssetFile as st, createGenericWebVitePlugins as t, clearAssetSource as tt, createFrameworkCssGenerationQueue as u, isStyleImportRequest as ut, createViteCssMemory as v, isCssOutputFile as vt, createCssHandlerOptions as w, canProcessViteSourceStyleAsCss as wt, createViteWebCssFinalizerOutputPlugin as x, posix as xt, shouldCollectTransformedSourceCandidates as y, isMiniProgramStyleOutputFile as yt, resolveViteModuleIdentity as z, resolveViteCssHandlerExtraOptions as zt };
|