weapp-tailwindcss 5.0.10 → 5.0.12
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/dist/{bundle-state-CXzPknlT.mjs → bundle-state-BxMNKjBV.mjs} +2 -34
- package/dist/{bundle-state-BwtEqxvU.js → bundle-state-DU2ATDhw.js} +1 -39
- package/dist/bundlers/gulp/vinyl-transform.d.ts +1 -1
- package/dist/bundlers/shared/hmr-timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/types.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/source-candidates.d.ts +6 -0
- package/dist/bundlers/vite/weapp-vite-config.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +10 -8
- package/dist/cache/index.d.ts +4 -0
- package/dist/cli.js +7 -0
- package/dist/cli.mjs +7 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.js +8 -5
- package/dist/core.mjs +8 -5
- package/dist/{generator-ChgOWNOj.js → generator-Cb1Zp3Al.js} +1 -1
- package/dist/{generator-h2XRiJ9-.mjs → generator-mvNFUvns.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-Be88jhoY.mjs → gulp-BfZpaYSQ.mjs} +97 -11
- package/dist/{gulp-CHtZF-oT.js → gulp-CxGZU0-v.js} +97 -11
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BkivBZvN.js → hmr-timing-DFR51wgo.js} +61 -9
- package/dist/{hmr-timing-Ct5w4hdM.mjs → hmr-timing-DNjF8bWA.mjs} +49 -10
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +9 -10
- package/dist/postcss.mjs +7 -5
- package/dist/{precheck-CY9oaH49.js → precheck-30zNPRlI.js} +13 -3
- package/dist/{precheck-BpHxsWRd.mjs → precheck-CsFr1q2l.mjs} +14 -4
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/tailwindcss/source-scan.d.ts +1 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +17 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v3-engine/types.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +19 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/{tailwindcss-Bfy2egdX.mjs → tailwindcss-CK84uGBp.mjs} +1 -1
- package/dist/{tailwindcss-DbbAKAZP.js → tailwindcss-Clpkz1oR.js} +1 -1
- package/dist/{transform-Cd634UZV.js → transform-CaVEBOuR.js} +1 -1
- package/dist/{transform-r5evL6Hn.mjs → transform-Cju08-aJ.mjs} +1 -1
- package/dist/{v3-engine-D0yA9ZkF.js → v3-engine-CQE5JJNZ.js} +142 -29
- package/dist/{v3-engine-CFkP6dWF.mjs → v3-engine-DKBaKWGL.mjs} +131 -30
- package/dist/{vite-Bh-BNp5g.js → vite-BBGOjh9e.js} +301 -56
- package/dist/{vite-BM_iIFmS.mjs → vite-CS5DE-HD.mjs} +300 -55
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +130 -31
- package/dist/{webpack-CJAOcYEO.js → webpack-DIWrcpRo.js} +93 -12
- package/dist/{webpack-DPdrcC2X.mjs → webpack-SPcri_D8.mjs} +92 -11
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
3
|
-
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, p as replaceWxml, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-
|
|
1
|
+
import { A as normalizeTailwindSourceForGenerator, D as hasTailwindSourceDirectives, E as hasTailwindRootDirectives, J as getTailwindV4IncrementalGenerateCacheStats, M as parseImportRequest, N as removeTailwindSourceDirectives, O as normalizeTailwindConfigDirectives, R as hasTailwindGeneratedCssMarkers, T as hasTailwindApplyDirective, Z as filterUnsupportedMiniProgramTailwindV4Candidates, a as getTailwindV3IncrementalGenerateCacheStats, at as createDebug, ct as findTailwindConfig, ft as findNearestPackageRoot, g as discoverTailwindV4CssEntries, h as resolveViteSourceScanEntries, ht as omitUndefined, lt as resolveTailwindcssOptions, m as createViteSourceScanMatcher, rt as resolveTailwindV4CssSourceBase, u as getRuntimeClassSetSignature, v as resolveTailwindV4EntriesFromCssCached, w as hasLocalCssImport, y as resolveViteTailwindV4CssDependencies } from "./v3-engine-DKBaKWGL.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-mvNFUvns.mjs";
|
|
3
|
+
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, p as replaceWxml, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-CsFr1q2l.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DsaS975I.mjs";
|
|
5
|
-
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-
|
|
6
|
-
import { a as createTailwindV3DefaultExtractor, c as validateCandidatesByGenerator,
|
|
7
|
-
import {
|
|
5
|
+
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-CK84uGBp.mjs";
|
|
6
|
+
import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, c as validateCandidatesByGenerator, d as extractMarkedUserLayerComponentsCss, f as mergeMarkedUserLayerComponentsCss, g as annotateCssSourceTrace, i as isSourceCandidateRequest, l as pushConcurrentTaskFactories, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, t as createHmrTimingRecorder, u as runWithConcurrency, v as createCssTokenSourceMap } from "./hmr-timing-DNjF8bWA.mjs";
|
|
7
|
+
import { S as toAbsoluteOutputPath, _ as slash, a as applyLinkedResults, b as normalizeOutputPathKey, c as hasBundlerGeneratedCssMarker, d as resolvePackageDir, f as resolvePluginDisabledState, g as normalizePath, h as isCSSRequest, i as createRuntimeAffectingSourceSignature, l as parseBundlerGeneratedCssMarkerBlocks, m as formatPostcssSourceMap, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as cleanUrl, r as updateBundleBuildState, s as createBundlerGeneratedCssMarker, t as buildBundleSnapshot, u as stripBundlerGeneratedCssMarkers, v as isSourceStyleRequest, y as stripRequestQuery } from "./bundle-state-BxMNKjBV.mjs";
|
|
8
8
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
9
9
|
import { containsCssAfterMinify, filterExistingCssRules, getPostcssPluginName, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
|
|
10
|
+
import { LRUCache } from "lru-cache";
|
|
10
11
|
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
11
12
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
12
13
|
import path from "node:path";
|
|
@@ -474,7 +475,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
474
475
|
//#region src/uni-app-x/vite.ts
|
|
475
476
|
let transformUVuePromise;
|
|
476
477
|
function loadTransformUVue() {
|
|
477
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
478
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-Cju08-aJ.mjs").then((mod) => mod.transformUVue));
|
|
478
479
|
return transformUVuePromise;
|
|
479
480
|
}
|
|
480
481
|
const preprocessorLangs = new Set([
|
|
@@ -789,12 +790,24 @@ function resolveReplayCssOutputFile(rootDir, file) {
|
|
|
789
790
|
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
790
791
|
return normalizedFile;
|
|
791
792
|
}
|
|
793
|
+
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
794
|
+
if (typeof sourceRoot !== "string" || sourceRoot.trim().length === 0) return;
|
|
795
|
+
return normalizeOutputPathKey(path.isAbsolute(sourceRoot) ? path.relative(rootDir, sourceRoot) : sourceRoot).replace(/\/+$/, "");
|
|
796
|
+
}
|
|
797
|
+
function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
798
|
+
const outputFile = resolveReplayCssOutputFile(rootDir, file);
|
|
799
|
+
const normalizedSourceRoot = normalizeViteSourceRoot(rootDir, sourceRoot);
|
|
800
|
+
if (!normalizedSourceRoot) return outputFile;
|
|
801
|
+
if (outputFile === normalizedSourceRoot) return path.posix.basename(outputFile);
|
|
802
|
+
if (outputFile.startsWith(`${normalizedSourceRoot}/`)) return outputFile.slice(normalizedSourceRoot.length + 1);
|
|
803
|
+
return outputFile;
|
|
804
|
+
}
|
|
792
805
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false) {
|
|
793
806
|
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
794
807
|
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, ".wxss");
|
|
795
808
|
}
|
|
796
|
-
function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false) {
|
|
797
|
-
const normalizedFile =
|
|
809
|
+
function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot) {
|
|
810
|
+
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot);
|
|
798
811
|
if (isWebGeneratorTarget || preserveCssExtension || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
799
812
|
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".wxss");
|
|
800
813
|
}
|
|
@@ -1265,10 +1278,10 @@ function mergeRememberedCssSources(sources, outputFile) {
|
|
|
1265
1278
|
sourceFile: sources[0]?.sourceFile ?? outputFile
|
|
1266
1279
|
};
|
|
1267
1280
|
}
|
|
1268
|
-
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension) {
|
|
1281
|
+
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot) {
|
|
1269
1282
|
const groups = /* @__PURE__ */ new Map();
|
|
1270
1283
|
for (const [key, remembered] of sources ?? []) {
|
|
1271
|
-
const outputKey = normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension));
|
|
1284
|
+
const outputKey = normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot));
|
|
1272
1285
|
const group = groups.get(outputKey) ?? [];
|
|
1273
1286
|
group.push({
|
|
1274
1287
|
key,
|
|
@@ -1986,13 +1999,31 @@ function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
|
1986
1999
|
}
|
|
1987
2000
|
return importedSources;
|
|
1988
2001
|
}
|
|
2002
|
+
function collectBundleAssetFiles(bundle) {
|
|
2003
|
+
const files = /* @__PURE__ */ new Set();
|
|
2004
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2005
|
+
if (output.type !== "asset") continue;
|
|
2006
|
+
files.add(normalizeOutputPathKey(getAssetFile(bundleFile, output)));
|
|
2007
|
+
}
|
|
2008
|
+
return files;
|
|
2009
|
+
}
|
|
2010
|
+
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2011
|
+
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2012
|
+
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2013
|
+
}
|
|
1989
2014
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
1990
2015
|
let collected = 0;
|
|
2016
|
+
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
1991
2017
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1992
2018
|
if (output.type !== "asset") continue;
|
|
1993
2019
|
const file = getAssetFile(bundleFile, output);
|
|
1994
2020
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
1995
2021
|
const rawSource = readAssetSource(output);
|
|
2022
|
+
if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) {
|
|
2023
|
+
delete bundle[bundleFile];
|
|
2024
|
+
options.debug?.("skip covered vite-generated source css asset: %s", file);
|
|
2025
|
+
continue;
|
|
2026
|
+
}
|
|
1996
2027
|
const nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
1997
2028
|
if (nextCss !== rawSource) output.source = nextCss;
|
|
1998
2029
|
options.markCssAssetProcessed?.(output, file);
|
|
@@ -2098,7 +2129,19 @@ function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
|
2098
2129
|
};
|
|
2099
2130
|
}
|
|
2100
2131
|
//#endregion
|
|
2132
|
+
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
2133
|
+
function resolveWeappViteSourceRoot(config) {
|
|
2134
|
+
const srcRoot = config?.weapp?.srcRoot;
|
|
2135
|
+
return typeof srcRoot === "string" && srcRoot.trim().length > 0 ? srcRoot : void 0;
|
|
2136
|
+
}
|
|
2137
|
+
//#endregion
|
|
2101
2138
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
2139
|
+
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2140
|
+
function resolveViteCssTaskConcurrency(useIncrementalMode) {
|
|
2141
|
+
const configured = Number.parseInt(process$1.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2142
|
+
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2143
|
+
return useIncrementalMode ? 1 : 2;
|
|
2144
|
+
}
|
|
2102
2145
|
function addSiblingCssFile(files, file) {
|
|
2103
2146
|
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
2104
2147
|
else if (file.endsWith(".js")) files.add(file.replace(/\.js$/, ".wxss"));
|
|
@@ -2109,6 +2152,90 @@ function collectRuntimeLinkedCssFiles(snapshot) {
|
|
|
2109
2152
|
for (const file of snapshot.runtimeAffectingChangedByType.js) addSiblingCssFile(files, file);
|
|
2110
2153
|
return files;
|
|
2111
2154
|
}
|
|
2155
|
+
function normalizeViteCssCacheKey(file) {
|
|
2156
|
+
return normalizeOutputPathKey(file);
|
|
2157
|
+
}
|
|
2158
|
+
function rememberLastCssResult(resultByFile, sourceHashByFile, file, css, sourceHash) {
|
|
2159
|
+
const key = normalizeViteCssCacheKey(file);
|
|
2160
|
+
resultByFile.delete(key);
|
|
2161
|
+
sourceHashByFile.delete(key);
|
|
2162
|
+
resultByFile.set(key, css);
|
|
2163
|
+
sourceHashByFile.set(key, sourceHash);
|
|
2164
|
+
while (resultByFile.size > VITE_LAST_CSS_RESULT_CACHE_MAX) {
|
|
2165
|
+
const oldestKey = resultByFile.keys().next().value;
|
|
2166
|
+
if (typeof oldestKey !== "string") break;
|
|
2167
|
+
resultByFile.delete(oldestKey);
|
|
2168
|
+
sourceHashByFile.delete(oldestKey);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
function getLastCssResult(resultByFile, ...files) {
|
|
2172
|
+
for (const file of files) {
|
|
2173
|
+
if (!file) continue;
|
|
2174
|
+
const key = normalizeViteCssCacheKey(file);
|
|
2175
|
+
const css = resultByFile.get(key);
|
|
2176
|
+
if (css == null) continue;
|
|
2177
|
+
resultByFile.delete(key);
|
|
2178
|
+
resultByFile.set(key, css);
|
|
2179
|
+
return css;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
function getLastCssSourceHash(sourceHashByFile, file) {
|
|
2183
|
+
return sourceHashByFile.get(normalizeViteCssCacheKey(file));
|
|
2184
|
+
}
|
|
2185
|
+
function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
2186
|
+
for (const key of resultByFile.keys()) {
|
|
2187
|
+
if (activeFiles.has(key)) continue;
|
|
2188
|
+
resultByFile.delete(key);
|
|
2189
|
+
sourceHashByFile.delete(key);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function toMb(bytes) {
|
|
2193
|
+
return Math.round(bytes / 1024 / 1024);
|
|
2194
|
+
}
|
|
2195
|
+
function summarizeStringMapCache(map) {
|
|
2196
|
+
let bytes = 0;
|
|
2197
|
+
for (const value of map.values()) bytes += value.length;
|
|
2198
|
+
return {
|
|
2199
|
+
bytes,
|
|
2200
|
+
mb: toMb(bytes),
|
|
2201
|
+
size: map.size
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
function resolveViteMemoryDebugStats(context) {
|
|
2205
|
+
if (process$1.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2206
|
+
const memory = process$1.memoryUsage();
|
|
2207
|
+
return {
|
|
2208
|
+
phase: context.phase,
|
|
2209
|
+
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2210
|
+
process: {
|
|
2211
|
+
rssMb: toMb(memory.rss),
|
|
2212
|
+
heapTotalMb: toMb(memory.heapTotal),
|
|
2213
|
+
heapUsedMb: toMb(memory.heapUsed),
|
|
2214
|
+
externalMb: toMb(memory.external),
|
|
2215
|
+
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
2216
|
+
},
|
|
2217
|
+
runtime: {
|
|
2218
|
+
sourceCandidates: context.sourceCandidatesSize,
|
|
2219
|
+
runtime: context.runtimeSize,
|
|
2220
|
+
transformRuntime: context.transformRuntimeSize,
|
|
2221
|
+
generatorRuntime: context.generatorRuntimeSize
|
|
2222
|
+
},
|
|
2223
|
+
processCache: {
|
|
2224
|
+
instance: context.cache.instance.size,
|
|
2225
|
+
hashMap: context.cache.hashMap.size,
|
|
2226
|
+
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2227
|
+
activeHashKeys: context.activeProcessHashKeys.size
|
|
2228
|
+
},
|
|
2229
|
+
viteCss: {
|
|
2230
|
+
...context.getViteCssCacheStats?.(),
|
|
2231
|
+
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2232
|
+
},
|
|
2233
|
+
tailwind: {
|
|
2234
|
+
v3: getTailwindV3IncrementalGenerateCacheStats(),
|
|
2235
|
+
v4: getTailwindV4IncrementalGenerateCacheStats()
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2112
2239
|
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
2113
2240
|
if (!getSourceCandidatesForEntries || !rawSource.includes("@source")) return fallbackSignature;
|
|
2114
2241
|
const resolved = await resolveTailwindV4EntriesFromCssCached(rawSource, path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, ""))));
|
|
@@ -2119,6 +2246,7 @@ async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fa
|
|
|
2119
2246
|
function createGenerateBundleHook(context) {
|
|
2120
2247
|
const state = createBundleBuildState();
|
|
2121
2248
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
2249
|
+
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
2122
2250
|
let currentOutDir;
|
|
2123
2251
|
let currentSubpackageRoots;
|
|
2124
2252
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
@@ -2130,7 +2258,7 @@ function createGenerateBundleHook(context) {
|
|
|
2130
2258
|
});
|
|
2131
2259
|
return async function generateBundle(_opt, bundle) {
|
|
2132
2260
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
2133
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, hmrTimingRecorder } = context;
|
|
2261
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
2134
2262
|
const getBundlerSfcSource = (sourceFile) => {
|
|
2135
2263
|
const code = this.getModuleInfo?.(sourceFile)?.code;
|
|
2136
2264
|
return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
|
|
@@ -2148,6 +2276,7 @@ function createGenerateBundleHook(context) {
|
|
|
2148
2276
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget && runtimeState.twPatcher.majorVersion === 3;
|
|
2149
2277
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
2150
2278
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
2279
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
2151
2280
|
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
2152
2281
|
await runtimeState.readyPromise;
|
|
2153
2282
|
debug("start");
|
|
@@ -2159,7 +2288,7 @@ function createGenerateBundleHook(context) {
|
|
|
2159
2288
|
markCssAssetProcessed,
|
|
2160
2289
|
recordCssAssetResult,
|
|
2161
2290
|
recordViteProcessedCssAssetResult,
|
|
2162
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension),
|
|
2291
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot),
|
|
2163
2292
|
debug
|
|
2164
2293
|
});
|
|
2165
2294
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -2175,6 +2304,16 @@ function createGenerateBundleHook(context) {
|
|
|
2175
2304
|
recordTimingDetail(`tasks.${name}`, start);
|
|
2176
2305
|
}
|
|
2177
2306
|
};
|
|
2307
|
+
const emitOrReplayCssAsset = (fileName, source) => {
|
|
2308
|
+
const replayAsset = createReplayCssAsset(fileName, source);
|
|
2309
|
+
if (typeof this.emitFile === "function") this.emitFile({
|
|
2310
|
+
type: "asset",
|
|
2311
|
+
fileName,
|
|
2312
|
+
source
|
|
2313
|
+
});
|
|
2314
|
+
else bundle[fileName] = replayAsset;
|
|
2315
|
+
return replayAsset;
|
|
2316
|
+
};
|
|
2178
2317
|
const metrics = createEmptyMetrics();
|
|
2179
2318
|
const forceRuntimeRefreshByEnv = process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
2180
2319
|
const disableDirtyOptimization = process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1";
|
|
@@ -2182,6 +2321,7 @@ function createGenerateBundleHook(context) {
|
|
|
2182
2321
|
const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
2183
2322
|
const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
2184
2323
|
const bundleFiles = Object.keys(bundle);
|
|
2324
|
+
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
2185
2325
|
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
2186
2326
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
2187
2327
|
const isMainPackageStyleOutputFile = (file) => currentSubpackageRoots != null && !isSubpackageOutputFile(file, currentSubpackageRoots);
|
|
@@ -2305,7 +2445,14 @@ function createGenerateBundleHook(context) {
|
|
|
2305
2445
|
});
|
|
2306
2446
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
2307
2447
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
2448
|
+
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
2449
|
+
const activeProcessHashKeys = /* @__PURE__ */ new Set();
|
|
2450
|
+
const rememberProcessCacheKey = (cacheKey, hashKey = cacheKey) => {
|
|
2451
|
+
activeProcessCacheKeys.add(cacheKey);
|
|
2452
|
+
activeProcessHashKeys.add(hashKey);
|
|
2453
|
+
};
|
|
2308
2454
|
const tasks = [];
|
|
2455
|
+
const cssTaskFactories = [];
|
|
2309
2456
|
const jsTaskFactories = [];
|
|
2310
2457
|
for (const entry of snapshot.entries) {
|
|
2311
2458
|
const { file, output: originalSource, source: originalEntrySource, type } = entry;
|
|
@@ -2317,10 +2464,13 @@ function createGenerateBundleHook(context) {
|
|
|
2317
2464
|
}
|
|
2318
2465
|
if (!processFiles.html.has(file)) continue;
|
|
2319
2466
|
const rawSource = originalEntrySource;
|
|
2467
|
+
const cacheKey = file;
|
|
2468
|
+
const hashKey = `${file}:html:${runtimeSignature}`;
|
|
2469
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
2320
2470
|
tasks.push(timeTask("html", () => processCachedTask({
|
|
2321
2471
|
cache,
|
|
2322
|
-
cacheKey
|
|
2323
|
-
hashKey
|
|
2472
|
+
cacheKey,
|
|
2473
|
+
hashKey,
|
|
2324
2474
|
hash: getSnapshotHash(snapshot.sourceHashByFile, file, rawSource),
|
|
2325
2475
|
applyResult(source) {
|
|
2326
2476
|
originalSource.source = source;
|
|
@@ -2359,6 +2509,7 @@ function createGenerateBundleHook(context) {
|
|
|
2359
2509
|
metrics.css.total++;
|
|
2360
2510
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, file, outDir, opts);
|
|
2361
2511
|
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
2512
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2362
2513
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
2363
2514
|
delete bundle[file];
|
|
2364
2515
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
@@ -2367,12 +2518,7 @@ function createGenerateBundleHook(context) {
|
|
|
2367
2518
|
const applyCssResult = (source) => {
|
|
2368
2519
|
if (outputFile !== file) {
|
|
2369
2520
|
delete bundle[file];
|
|
2370
|
-
|
|
2371
|
-
type: "asset",
|
|
2372
|
-
fileName: outputFile,
|
|
2373
|
-
source
|
|
2374
|
-
});
|
|
2375
|
-
else bundle[outputFile] = createReplayCssAsset(outputFile, source);
|
|
2521
|
+
emitOrReplayCssAsset(outputFile, source);
|
|
2376
2522
|
originalSource.fileName = outputFile;
|
|
2377
2523
|
}
|
|
2378
2524
|
originalSource.source = source;
|
|
@@ -2448,8 +2594,10 @@ function createGenerateBundleHook(context) {
|
|
|
2448
2594
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
2449
2595
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2450
2596
|
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}:${sourceTraceSignature}`;
|
|
2597
|
+
const cssCacheKey = file;
|
|
2598
|
+
const cssHashKey = `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`;
|
|
2451
2599
|
if (!shouldTrackGeneratorRuntime) {
|
|
2452
|
-
const lastCss = lastCssResultByFile
|
|
2600
|
+
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
2453
2601
|
if (lastCss != null) {
|
|
2454
2602
|
applyCssResult(lastCss);
|
|
2455
2603
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -2458,14 +2606,15 @@ function createGenerateBundleHook(context) {
|
|
|
2458
2606
|
continue;
|
|
2459
2607
|
}
|
|
2460
2608
|
}
|
|
2461
|
-
|
|
2609
|
+
rememberProcessCacheKey(cssCacheKey, cssHashKey);
|
|
2610
|
+
cssTaskFactories.push(() => timeTask("css", () => processCachedTask({
|
|
2462
2611
|
cache,
|
|
2463
|
-
cacheKey:
|
|
2464
|
-
hashKey:
|
|
2612
|
+
cacheKey: cssCacheKey,
|
|
2613
|
+
hashKey: cssHashKey,
|
|
2465
2614
|
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`,
|
|
2466
2615
|
applyResult(source) {
|
|
2467
2616
|
applyCssResult(source);
|
|
2468
|
-
lastCssResultByFile
|
|
2617
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
2469
2618
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
2470
2619
|
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
2471
2620
|
outputFile,
|
|
@@ -2502,7 +2651,7 @@ function createGenerateBundleHook(context) {
|
|
|
2502
2651
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2503
2652
|
styleHandler,
|
|
2504
2653
|
debug,
|
|
2505
|
-
previousCss: !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile
|
|
2654
|
+
previousCss: !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0
|
|
2506
2655
|
});
|
|
2507
2656
|
if (generated) {
|
|
2508
2657
|
const tracedCss = annotateCss(generated.css);
|
|
@@ -2563,10 +2712,12 @@ function createGenerateBundleHook(context) {
|
|
|
2563
2712
|
jsTaskFactories.push(async () => {
|
|
2564
2713
|
await timeTask("js", async () => {
|
|
2565
2714
|
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2715
|
+
const hashKey = `${file}:js`;
|
|
2716
|
+
rememberProcessCacheKey(file, hashKey);
|
|
2566
2717
|
await processCachedTask({
|
|
2567
2718
|
cache,
|
|
2568
2719
|
cacheKey: file,
|
|
2569
|
-
hashKey
|
|
2720
|
+
hashKey,
|
|
2570
2721
|
hash: `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`,
|
|
2571
2722
|
applyResult(source) {
|
|
2572
2723
|
originalSource.code = source;
|
|
@@ -2605,9 +2756,11 @@ function createGenerateBundleHook(context) {
|
|
|
2605
2756
|
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2606
2757
|
baseApplyLinkedUpdates(linked);
|
|
2607
2758
|
};
|
|
2759
|
+
const uniAppXJsHashKey = `${file}:js`;
|
|
2760
|
+
rememberProcessCacheKey(file, uniAppXJsHashKey);
|
|
2608
2761
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2609
2762
|
cache,
|
|
2610
|
-
hashKey:
|
|
2763
|
+
hashKey: uniAppXJsHashKey,
|
|
2611
2764
|
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2612
2765
|
createHandlerOptions,
|
|
2613
2766
|
debug,
|
|
@@ -2649,7 +2802,7 @@ function createGenerateBundleHook(context) {
|
|
|
2649
2802
|
}
|
|
2650
2803
|
}
|
|
2651
2804
|
if (useIncrementalMode || isNativeAppStyleTarget) {
|
|
2652
|
-
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
2805
|
+
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot);
|
|
2653
2806
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2654
2807
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2655
2808
|
key: item.key,
|
|
@@ -2658,6 +2811,8 @@ function createGenerateBundleHook(context) {
|
|
|
2658
2811
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2659
2812
|
if (!rememberedCssSource) continue;
|
|
2660
2813
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
2814
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2815
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(sourceFile));
|
|
2661
2816
|
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2662
2817
|
const cssHandlerOptions = {
|
|
2663
2818
|
...getCssHandlerOptions(sourceFile),
|
|
@@ -2671,11 +2826,14 @@ function createGenerateBundleHook(context) {
|
|
|
2671
2826
|
tokenSources: sourceTraceTokenSources
|
|
2672
2827
|
});
|
|
2673
2828
|
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
2674
|
-
const
|
|
2829
|
+
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, { includeFallbackSignature: cssHandlerOptions.isMainChunk }));
|
|
2830
|
+
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2831
|
+
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2832
|
+
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2675
2833
|
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2676
2834
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2677
2835
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
2678
|
-
|
|
2836
|
+
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2679
2837
|
const start = performance.now();
|
|
2680
2838
|
const generated = await generateCssByGenerator({
|
|
2681
2839
|
opts,
|
|
@@ -2687,9 +2845,11 @@ function createGenerateBundleHook(context) {
|
|
|
2687
2845
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2688
2846
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2689
2847
|
styleHandler,
|
|
2690
|
-
debug
|
|
2848
|
+
debug,
|
|
2849
|
+
previousCss
|
|
2691
2850
|
});
|
|
2692
2851
|
const css = annotateCss(generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css);
|
|
2852
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
2693
2853
|
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
2694
2854
|
if (generated) {
|
|
2695
2855
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
@@ -2701,13 +2861,7 @@ function createGenerateBundleHook(context) {
|
|
|
2701
2861
|
});
|
|
2702
2862
|
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
2703
2863
|
}
|
|
2704
|
-
const replayAsset =
|
|
2705
|
-
bundle[outputFile] = replayAsset;
|
|
2706
|
-
if (typeof this.emitFile === "function") this.emitFile({
|
|
2707
|
-
type: "asset",
|
|
2708
|
-
fileName: outputFile,
|
|
2709
|
-
source: css
|
|
2710
|
-
});
|
|
2864
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
2711
2865
|
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
2712
2866
|
metrics.css.elapsed += measureElapsed(start);
|
|
2713
2867
|
metrics.css.transformed++;
|
|
@@ -2717,6 +2871,10 @@ function createGenerateBundleHook(context) {
|
|
|
2717
2871
|
}
|
|
2718
2872
|
}
|
|
2719
2873
|
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
2874
|
+
if (cssTaskFactories.length > 0) {
|
|
2875
|
+
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2876
|
+
tasks.push(runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2877
|
+
}
|
|
2720
2878
|
const tasksStart = performance.now();
|
|
2721
2879
|
await Promise.all(tasks);
|
|
2722
2880
|
recordTimingDetail("tasks", tasksStart);
|
|
@@ -2771,7 +2929,7 @@ function createGenerateBundleHook(context) {
|
|
|
2771
2929
|
markCssAssetProcessed,
|
|
2772
2930
|
recordCssAssetResult,
|
|
2773
2931
|
recordViteProcessedCssAssetResult,
|
|
2774
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension),
|
|
2932
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot),
|
|
2775
2933
|
debug
|
|
2776
2934
|
});
|
|
2777
2935
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
@@ -2791,10 +2949,34 @@ function createGenerateBundleHook(context) {
|
|
|
2791
2949
|
const stateUpdateStart = performance.now();
|
|
2792
2950
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2793
2951
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2952
|
+
if (useIncrementalMode && !snapshot.hasOmittedKnownFiles) cache.prune?.({
|
|
2953
|
+
cacheKeys: activeProcessCacheKeys,
|
|
2954
|
+
hashKeys: activeProcessHashKeys
|
|
2955
|
+
});
|
|
2956
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2957
|
+
pruneViteCssCaches?.({
|
|
2958
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2959
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2960
|
+
});
|
|
2794
2961
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2795
2962
|
debug("metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)", useIncrementalMode ? state.iteration : 0, formatMs(metrics.runtimeSet), metrics.html.total, metrics.html.transformed, metrics.html.cacheHits, formatCacheHitRate(metrics.html), formatMs(metrics.html.elapsed), metrics.js.total, metrics.js.transformed, metrics.js.cacheHits, formatCacheHitRate(metrics.js), formatMs(metrics.js.elapsed), metrics.css.total, metrics.css.transformed, metrics.css.cacheHits, formatCacheHitRate(metrics.css), formatMs(metrics.css.elapsed));
|
|
2796
2963
|
if (hmrTimingRecorder) {
|
|
2797
|
-
hmrTimingRecorder.record("generateBundle", performance.now() - hmrTimingStartedAt,
|
|
2964
|
+
hmrTimingRecorder.record("generateBundle", performance.now() - hmrTimingStartedAt, {
|
|
2965
|
+
...timingDetails,
|
|
2966
|
+
memoryDebug: resolveViteMemoryDebugStats({
|
|
2967
|
+
activeProcessCacheKeys,
|
|
2968
|
+
activeProcessHashKeys,
|
|
2969
|
+
cache,
|
|
2970
|
+
generatorRuntimeSize: generatorRuntime.size,
|
|
2971
|
+
getViteCssCacheStats,
|
|
2972
|
+
lastCssResultByFile,
|
|
2973
|
+
phase: "generateBundle",
|
|
2974
|
+
runtimeSize: runtime.size,
|
|
2975
|
+
sourceCandidatesSize: sourceCandidates.size,
|
|
2976
|
+
transformRuntimeSize: transformRuntime.size,
|
|
2977
|
+
useIncrementalMode
|
|
2978
|
+
})
|
|
2979
|
+
});
|
|
2798
2980
|
hmrTimingRecorder.emitTotal();
|
|
2799
2981
|
}
|
|
2800
2982
|
onEnd();
|
|
@@ -2858,6 +3040,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
2858
3040
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
2859
3041
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
2860
3042
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3043
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
2861
3044
|
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
2862
3045
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2863
3046
|
opts,
|
|
@@ -2870,7 +3053,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
2870
3053
|
markCssAssetProcessed,
|
|
2871
3054
|
recordCssAssetResult,
|
|
2872
3055
|
recordViteProcessedCssAssetResult,
|
|
2873
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
|
|
3056
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot),
|
|
2874
3057
|
debug
|
|
2875
3058
|
});
|
|
2876
3059
|
};
|
|
@@ -3424,7 +3607,10 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
3424
3607
|
const debug = createDebug();
|
|
3425
3608
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
3426
3609
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
3427
|
-
const
|
|
3610
|
+
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
3611
|
+
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3612
|
+
const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
3613
|
+
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3428
3614
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3429
3615
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
3430
3616
|
function normalizeSignaturePath(value) {
|
|
@@ -3469,6 +3655,21 @@ function normalizeCssSourceIdentity(sourceFile) {
|
|
|
3469
3655
|
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
3470
3656
|
return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
|
|
3471
3657
|
}
|
|
3658
|
+
function touchMapEntry(map, key, value) {
|
|
3659
|
+
map.delete(key);
|
|
3660
|
+
map.set(key, value);
|
|
3661
|
+
}
|
|
3662
|
+
function pruneMapToMaxSize(map, maxSize, onDelete) {
|
|
3663
|
+
while (map.size > maxSize) {
|
|
3664
|
+
const key = map.keys().next().value;
|
|
3665
|
+
if (key === void 0) break;
|
|
3666
|
+
map.delete(key);
|
|
3667
|
+
onDelete?.(key);
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
function normalizeVitePersistentCacheKey(file) {
|
|
3671
|
+
return normalizeOutputPathKey(file);
|
|
3672
|
+
}
|
|
3472
3673
|
/**
|
|
3473
3674
|
* @name WeappTailwindcss
|
|
3474
3675
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -3565,7 +3766,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3565
3766
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
3566
3767
|
extractor: sourceCandidateExtractor
|
|
3567
3768
|
});
|
|
3568
|
-
const sourceCandidateScanCache =
|
|
3769
|
+
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3569
3770
|
let sourceScanEntries;
|
|
3570
3771
|
let sourceScanMatcher;
|
|
3571
3772
|
let sourceScanDependencies = /* @__PURE__ */ new Set();
|
|
@@ -3761,12 +3962,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
3761
3962
|
const file = cleanUrl(id);
|
|
3762
3963
|
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
3763
3964
|
if (!hasSfcStyleBlocks(code)) return;
|
|
3764
|
-
knownSfcSources
|
|
3965
|
+
touchMapEntry(knownSfcSources, normalizeKnownSfcSourceKey(file), code);
|
|
3966
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
3765
3967
|
};
|
|
3766
3968
|
const getKnownSfcSource = (file) => {
|
|
3767
3969
|
const scanSource = sourceCandidateCollector.source(file);
|
|
3768
3970
|
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
3769
|
-
|
|
3971
|
+
const key = normalizeKnownSfcSourceKey(file);
|
|
3972
|
+
const source = knownSfcSources.get(key);
|
|
3973
|
+
if (source != null) touchMapEntry(knownSfcSources, key, source);
|
|
3974
|
+
return source;
|
|
3770
3975
|
};
|
|
3771
3976
|
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3772
3977
|
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
@@ -3774,10 +3979,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
3774
3979
|
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3775
3980
|
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
3776
3981
|
const previous = rememberedCssSources.get(key);
|
|
3777
|
-
rememberedCssSources
|
|
3982
|
+
touchMapEntry(rememberedCssSources, key, entry);
|
|
3778
3983
|
for (const [rememberedKey, remembered] of rememberedCssSources) {
|
|
3779
3984
|
if (rememberedKey === key || normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
|
|
3780
|
-
rememberedCssSources
|
|
3985
|
+
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
3781
3986
|
...remembered,
|
|
3782
3987
|
rawSource: entry.rawSource,
|
|
3783
3988
|
sourceFile: entry.sourceFile
|
|
@@ -3786,6 +3991,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
3786
3991
|
}
|
|
3787
3992
|
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
3788
3993
|
else if (previous?.rawSource !== entry.rawSource || previous?.sourceFile !== entry.sourceFile) rememberedCssSignatureByFile.delete(key);
|
|
3994
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
3995
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
3996
|
+
});
|
|
3789
3997
|
};
|
|
3790
3998
|
const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
|
|
3791
3999
|
if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
|
|
@@ -3794,7 +4002,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3794
4002
|
rawSource,
|
|
3795
4003
|
sourceFile
|
|
3796
4004
|
};
|
|
3797
|
-
rememberedCssSources
|
|
4005
|
+
touchMapEntry(rememberedCssSources, rememberedKey, nextRemembered);
|
|
3798
4006
|
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
3799
4007
|
return nextRemembered;
|
|
3800
4008
|
};
|
|
@@ -3875,19 +4083,53 @@ function WeappTailwindcss(options = {}) {
|
|
|
3875
4083
|
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
3876
4084
|
};
|
|
3877
4085
|
const recordCssAssetResult = (file, css) => {
|
|
3878
|
-
viteGeneratedCssByFile
|
|
4086
|
+
touchMapEntry(viteGeneratedCssByFile, normalizeVitePersistentCacheKey(file), css);
|
|
3879
4087
|
};
|
|
3880
4088
|
const recordViteProcessedCssAssetResult = (file, css, options = {}) => {
|
|
3881
|
-
const key =
|
|
4089
|
+
const key = normalizeVitePersistentCacheKey(file);
|
|
3882
4090
|
const previous = viteProcessedCssAssetResults.get(key);
|
|
3883
|
-
viteProcessedCssAssetResults
|
|
4091
|
+
touchMapEntry(viteProcessedCssAssetResults, key, {
|
|
3884
4092
|
css,
|
|
3885
4093
|
injectIntoMain: options.injectIntoMain ?? previous?.injectIntoMain,
|
|
3886
4094
|
outputFile: options.outputFile ?? previous?.outputFile
|
|
3887
4095
|
});
|
|
3888
4096
|
};
|
|
3889
4097
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
3890
|
-
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(
|
|
4098
|
+
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
4099
|
+
const getViteCssCacheStats = () => ({
|
|
4100
|
+
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
4101
|
+
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
4102
|
+
rememberedCssSources: rememberedCssSources.size,
|
|
4103
|
+
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4104
|
+
knownSfcSources: knownSfcSources.size,
|
|
4105
|
+
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4106
|
+
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
4107
|
+
pendingSourceCandidateSyncByFile: pendingSourceCandidateSyncByFile.size
|
|
4108
|
+
});
|
|
4109
|
+
const pruneViteCssCaches = (options) => {
|
|
4110
|
+
const activeFiles = new Set([...options.activeFiles].map(normalizeVitePersistentCacheKey));
|
|
4111
|
+
for (const key of viteGeneratedCssByFile.keys()) if (!activeFiles.has(key)) viteGeneratedCssByFile.delete(key);
|
|
4112
|
+
for (const [key, record] of viteProcessedCssAssetResults) {
|
|
4113
|
+
const outputKey = typeof record.outputFile === "string" ? normalizeVitePersistentCacheKey(record.outputFile) : void 0;
|
|
4114
|
+
if (!activeFiles.has(key) && (outputKey == null || !activeFiles.has(outputKey))) viteProcessedCssAssetResults.delete(key);
|
|
4115
|
+
}
|
|
4116
|
+
for (const [key, remembered] of rememberedCssSources) {
|
|
4117
|
+
const outputKey = normalizeVitePersistentCacheKey(remembered.outputFile);
|
|
4118
|
+
const sourceKey = normalizeVitePersistentCacheKey(remembered.sourceFile);
|
|
4119
|
+
if (!activeFiles.has(key) && !activeFiles.has(outputKey) && !activeFiles.has(sourceKey)) {
|
|
4120
|
+
rememberedCssSources.delete(key);
|
|
4121
|
+
rememberedCssSignatureByFile.delete(key);
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
if (options.activeKnownSfcFiles) {
|
|
4125
|
+
const activeKnownSfcFiles = new Set([...options.activeKnownSfcFiles].map((file) => normalizeKnownSfcSourceKey(file)).filter((file) => SFC_COMPONENT_FILE_RE.test(file)));
|
|
4126
|
+
for (const key of knownSfcSources.keys()) if (!activeKnownSfcFiles.has(key)) knownSfcSources.delete(key);
|
|
4127
|
+
}
|
|
4128
|
+
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4129
|
+
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4130
|
+
});
|
|
4131
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4132
|
+
};
|
|
3891
4133
|
const normalizeViteProcessedCssFile = (file) => path.resolve(cleanUrl(file));
|
|
3892
4134
|
const markViteProcessedCssSource = (file) => {
|
|
3893
4135
|
viteProcessedCssSourceFiles.add(normalizeViteProcessedCssFile(file));
|
|
@@ -3997,7 +4239,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
3997
4239
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3998
4240
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
3999
4241
|
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4000
|
-
const
|
|
4242
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
4243
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, generatorOptions.target === "web", isNativeAppStyleTarget, sourceRoot);
|
|
4001
4244
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4002
4245
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4003
4246
|
const cssHandlerOptions = {
|
|
@@ -4088,6 +4331,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4088
4331
|
setRememberedCssSignature,
|
|
4089
4332
|
getKnownSfcSource,
|
|
4090
4333
|
recordGeneratorCandidates,
|
|
4334
|
+
pruneViteCssCaches,
|
|
4335
|
+
getViteCssCacheStats,
|
|
4091
4336
|
hmrTimingRecorder
|
|
4092
4337
|
});
|
|
4093
4338
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|