weapp-tailwindcss 5.0.11 → 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-j9cB2Ff1.js → vite-BBGOjh9e.js} +289 -43
- package/dist/{vite-Bd8qf9dK.mjs → vite-CS5DE-HD.mjs} +288 -42
- 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();
|
|
@@ -2192,6 +2321,7 @@ function createGenerateBundleHook(context) {
|
|
|
2192
2321
|
const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
2193
2322
|
const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
2194
2323
|
const bundleFiles = Object.keys(bundle);
|
|
2324
|
+
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
2195
2325
|
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
2196
2326
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
2197
2327
|
const isMainPackageStyleOutputFile = (file) => currentSubpackageRoots != null && !isSubpackageOutputFile(file, currentSubpackageRoots);
|
|
@@ -2315,7 +2445,14 @@ function createGenerateBundleHook(context) {
|
|
|
2315
2445
|
});
|
|
2316
2446
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
2317
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
|
+
};
|
|
2318
2454
|
const tasks = [];
|
|
2455
|
+
const cssTaskFactories = [];
|
|
2319
2456
|
const jsTaskFactories = [];
|
|
2320
2457
|
for (const entry of snapshot.entries) {
|
|
2321
2458
|
const { file, output: originalSource, source: originalEntrySource, type } = entry;
|
|
@@ -2327,10 +2464,13 @@ function createGenerateBundleHook(context) {
|
|
|
2327
2464
|
}
|
|
2328
2465
|
if (!processFiles.html.has(file)) continue;
|
|
2329
2466
|
const rawSource = originalEntrySource;
|
|
2467
|
+
const cacheKey = file;
|
|
2468
|
+
const hashKey = `${file}:html:${runtimeSignature}`;
|
|
2469
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
2330
2470
|
tasks.push(timeTask("html", () => processCachedTask({
|
|
2331
2471
|
cache,
|
|
2332
|
-
cacheKey
|
|
2333
|
-
hashKey
|
|
2472
|
+
cacheKey,
|
|
2473
|
+
hashKey,
|
|
2334
2474
|
hash: getSnapshotHash(snapshot.sourceHashByFile, file, rawSource),
|
|
2335
2475
|
applyResult(source) {
|
|
2336
2476
|
originalSource.source = source;
|
|
@@ -2369,6 +2509,7 @@ function createGenerateBundleHook(context) {
|
|
|
2369
2509
|
metrics.css.total++;
|
|
2370
2510
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, file, outDir, opts);
|
|
2371
2511
|
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
2512
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2372
2513
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
2373
2514
|
delete bundle[file];
|
|
2374
2515
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
@@ -2453,8 +2594,10 @@ function createGenerateBundleHook(context) {
|
|
|
2453
2594
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
2454
2595
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2455
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"}`;
|
|
2456
2599
|
if (!shouldTrackGeneratorRuntime) {
|
|
2457
|
-
const lastCss = lastCssResultByFile
|
|
2600
|
+
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
2458
2601
|
if (lastCss != null) {
|
|
2459
2602
|
applyCssResult(lastCss);
|
|
2460
2603
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -2463,14 +2606,15 @@ function createGenerateBundleHook(context) {
|
|
|
2463
2606
|
continue;
|
|
2464
2607
|
}
|
|
2465
2608
|
}
|
|
2466
|
-
|
|
2609
|
+
rememberProcessCacheKey(cssCacheKey, cssHashKey);
|
|
2610
|
+
cssTaskFactories.push(() => timeTask("css", () => processCachedTask({
|
|
2467
2611
|
cache,
|
|
2468
|
-
cacheKey:
|
|
2469
|
-
hashKey:
|
|
2612
|
+
cacheKey: cssCacheKey,
|
|
2613
|
+
hashKey: cssHashKey,
|
|
2470
2614
|
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`,
|
|
2471
2615
|
applyResult(source) {
|
|
2472
2616
|
applyCssResult(source);
|
|
2473
|
-
lastCssResultByFile
|
|
2617
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
2474
2618
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
2475
2619
|
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
2476
2620
|
outputFile,
|
|
@@ -2507,7 +2651,7 @@ function createGenerateBundleHook(context) {
|
|
|
2507
2651
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2508
2652
|
styleHandler,
|
|
2509
2653
|
debug,
|
|
2510
|
-
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
|
|
2511
2655
|
});
|
|
2512
2656
|
if (generated) {
|
|
2513
2657
|
const tracedCss = annotateCss(generated.css);
|
|
@@ -2568,10 +2712,12 @@ function createGenerateBundleHook(context) {
|
|
|
2568
2712
|
jsTaskFactories.push(async () => {
|
|
2569
2713
|
await timeTask("js", async () => {
|
|
2570
2714
|
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2715
|
+
const hashKey = `${file}:js`;
|
|
2716
|
+
rememberProcessCacheKey(file, hashKey);
|
|
2571
2717
|
await processCachedTask({
|
|
2572
2718
|
cache,
|
|
2573
2719
|
cacheKey: file,
|
|
2574
|
-
hashKey
|
|
2720
|
+
hashKey,
|
|
2575
2721
|
hash: `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`,
|
|
2576
2722
|
applyResult(source) {
|
|
2577
2723
|
originalSource.code = source;
|
|
@@ -2610,9 +2756,11 @@ function createGenerateBundleHook(context) {
|
|
|
2610
2756
|
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
2611
2757
|
baseApplyLinkedUpdates(linked);
|
|
2612
2758
|
};
|
|
2759
|
+
const uniAppXJsHashKey = `${file}:js`;
|
|
2760
|
+
rememberProcessCacheKey(file, uniAppXJsHashKey);
|
|
2613
2761
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
2614
2762
|
cache,
|
|
2615
|
-
hashKey:
|
|
2763
|
+
hashKey: uniAppXJsHashKey,
|
|
2616
2764
|
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
2617
2765
|
createHandlerOptions,
|
|
2618
2766
|
debug,
|
|
@@ -2654,7 +2802,7 @@ function createGenerateBundleHook(context) {
|
|
|
2654
2802
|
}
|
|
2655
2803
|
}
|
|
2656
2804
|
if (useIncrementalMode || isNativeAppStyleTarget) {
|
|
2657
|
-
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
2805
|
+
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot);
|
|
2658
2806
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
2659
2807
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2660
2808
|
key: item.key,
|
|
@@ -2663,6 +2811,8 @@ function createGenerateBundleHook(context) {
|
|
|
2663
2811
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2664
2812
|
if (!rememberedCssSource) continue;
|
|
2665
2813
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
2814
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
2815
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(sourceFile));
|
|
2666
2816
|
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2667
2817
|
const cssHandlerOptions = {
|
|
2668
2818
|
...getCssHandlerOptions(sourceFile),
|
|
@@ -2676,11 +2826,14 @@ function createGenerateBundleHook(context) {
|
|
|
2676
2826
|
tokenSources: sourceTraceTokenSources
|
|
2677
2827
|
});
|
|
2678
2828
|
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
2679
|
-
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;
|
|
2680
2833
|
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2681
2834
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2682
2835
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
2683
|
-
|
|
2836
|
+
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2684
2837
|
const start = performance.now();
|
|
2685
2838
|
const generated = await generateCssByGenerator({
|
|
2686
2839
|
opts,
|
|
@@ -2692,9 +2845,11 @@ function createGenerateBundleHook(context) {
|
|
|
2692
2845
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2693
2846
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
2694
2847
|
styleHandler,
|
|
2695
|
-
debug
|
|
2848
|
+
debug,
|
|
2849
|
+
previousCss
|
|
2696
2850
|
});
|
|
2697
2851
|
const css = annotateCss(generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css);
|
|
2852
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
2698
2853
|
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
2699
2854
|
if (generated) {
|
|
2700
2855
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
@@ -2716,6 +2871,10 @@ function createGenerateBundleHook(context) {
|
|
|
2716
2871
|
}
|
|
2717
2872
|
}
|
|
2718
2873
|
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
2874
|
+
if (cssTaskFactories.length > 0) {
|
|
2875
|
+
const cssConcurrency = resolveViteCssTaskConcurrency(useIncrementalMode);
|
|
2876
|
+
tasks.push(runWithConcurrency(cssTaskFactories, cssConcurrency).then(() => void 0));
|
|
2877
|
+
}
|
|
2719
2878
|
const tasksStart = performance.now();
|
|
2720
2879
|
await Promise.all(tasks);
|
|
2721
2880
|
recordTimingDetail("tasks", tasksStart);
|
|
@@ -2770,7 +2929,7 @@ function createGenerateBundleHook(context) {
|
|
|
2770
2929
|
markCssAssetProcessed,
|
|
2771
2930
|
recordCssAssetResult,
|
|
2772
2931
|
recordViteProcessedCssAssetResult,
|
|
2773
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension),
|
|
2932
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot),
|
|
2774
2933
|
debug
|
|
2775
2934
|
});
|
|
2776
2935
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
@@ -2790,10 +2949,34 @@ function createGenerateBundleHook(context) {
|
|
|
2790
2949
|
const stateUpdateStart = performance.now();
|
|
2791
2950
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2792
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
|
+
});
|
|
2793
2961
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2794
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));
|
|
2795
2963
|
if (hmrTimingRecorder) {
|
|
2796
|
-
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
|
+
});
|
|
2797
2980
|
hmrTimingRecorder.emitTotal();
|
|
2798
2981
|
}
|
|
2799
2982
|
onEnd();
|
|
@@ -2857,6 +3040,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
2857
3040
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
2858
3041
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
2859
3042
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3043
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
2860
3044
|
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
2861
3045
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2862
3046
|
opts,
|
|
@@ -2869,7 +3053,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
2869
3053
|
markCssAssetProcessed,
|
|
2870
3054
|
recordCssAssetResult,
|
|
2871
3055
|
recordViteProcessedCssAssetResult,
|
|
2872
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
|
|
3056
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot),
|
|
2873
3057
|
debug
|
|
2874
3058
|
});
|
|
2875
3059
|
};
|
|
@@ -3423,7 +3607,10 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
3423
3607
|
const debug = createDebug();
|
|
3424
3608
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
3425
3609
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
3426
|
-
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;
|
|
3427
3614
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3428
3615
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
3429
3616
|
function normalizeSignaturePath(value) {
|
|
@@ -3468,6 +3655,21 @@ function normalizeCssSourceIdentity(sourceFile) {
|
|
|
3468
3655
|
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
3469
3656
|
return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
|
|
3470
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
|
+
}
|
|
3471
3673
|
/**
|
|
3472
3674
|
* @name WeappTailwindcss
|
|
3473
3675
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -3564,7 +3766,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3564
3766
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
3565
3767
|
extractor: sourceCandidateExtractor
|
|
3566
3768
|
});
|
|
3567
|
-
const sourceCandidateScanCache =
|
|
3769
|
+
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
3568
3770
|
let sourceScanEntries;
|
|
3569
3771
|
let sourceScanMatcher;
|
|
3570
3772
|
let sourceScanDependencies = /* @__PURE__ */ new Set();
|
|
@@ -3760,12 +3962,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
3760
3962
|
const file = cleanUrl(id);
|
|
3761
3963
|
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
3762
3964
|
if (!hasSfcStyleBlocks(code)) return;
|
|
3763
|
-
knownSfcSources
|
|
3965
|
+
touchMapEntry(knownSfcSources, normalizeKnownSfcSourceKey(file), code);
|
|
3966
|
+
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
3764
3967
|
};
|
|
3765
3968
|
const getKnownSfcSource = (file) => {
|
|
3766
3969
|
const scanSource = sourceCandidateCollector.source(file);
|
|
3767
3970
|
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
3768
|
-
|
|
3971
|
+
const key = normalizeKnownSfcSourceKey(file);
|
|
3972
|
+
const source = knownSfcSources.get(key);
|
|
3973
|
+
if (source != null) touchMapEntry(knownSfcSources, key, source);
|
|
3974
|
+
return source;
|
|
3769
3975
|
};
|
|
3770
3976
|
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
3771
3977
|
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
@@ -3773,10 +3979,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
3773
3979
|
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
3774
3980
|
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
3775
3981
|
const previous = rememberedCssSources.get(key);
|
|
3776
|
-
rememberedCssSources
|
|
3982
|
+
touchMapEntry(rememberedCssSources, key, entry);
|
|
3777
3983
|
for (const [rememberedKey, remembered] of rememberedCssSources) {
|
|
3778
3984
|
if (rememberedKey === key || normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
|
|
3779
|
-
rememberedCssSources
|
|
3985
|
+
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
3780
3986
|
...remembered,
|
|
3781
3987
|
rawSource: entry.rawSource,
|
|
3782
3988
|
sourceFile: entry.sourceFile
|
|
@@ -3785,6 +3991,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
3785
3991
|
}
|
|
3786
3992
|
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
3787
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
|
+
});
|
|
3788
3997
|
};
|
|
3789
3998
|
const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
|
|
3790
3999
|
if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
|
|
@@ -3793,7 +4002,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3793
4002
|
rawSource,
|
|
3794
4003
|
sourceFile
|
|
3795
4004
|
};
|
|
3796
|
-
rememberedCssSources
|
|
4005
|
+
touchMapEntry(rememberedCssSources, rememberedKey, nextRemembered);
|
|
3797
4006
|
rememberedCssSignatureByFile.delete(rememberedKey);
|
|
3798
4007
|
return nextRemembered;
|
|
3799
4008
|
};
|
|
@@ -3874,19 +4083,53 @@ function WeappTailwindcss(options = {}) {
|
|
|
3874
4083
|
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
3875
4084
|
};
|
|
3876
4085
|
const recordCssAssetResult = (file, css) => {
|
|
3877
|
-
viteGeneratedCssByFile
|
|
4086
|
+
touchMapEntry(viteGeneratedCssByFile, normalizeVitePersistentCacheKey(file), css);
|
|
3878
4087
|
};
|
|
3879
4088
|
const recordViteProcessedCssAssetResult = (file, css, options = {}) => {
|
|
3880
|
-
const key =
|
|
4089
|
+
const key = normalizeVitePersistentCacheKey(file);
|
|
3881
4090
|
const previous = viteProcessedCssAssetResults.get(key);
|
|
3882
|
-
viteProcessedCssAssetResults
|
|
4091
|
+
touchMapEntry(viteProcessedCssAssetResults, key, {
|
|
3883
4092
|
css,
|
|
3884
4093
|
injectIntoMain: options.injectIntoMain ?? previous?.injectIntoMain,
|
|
3885
4094
|
outputFile: options.outputFile ?? previous?.outputFile
|
|
3886
4095
|
});
|
|
3887
4096
|
};
|
|
3888
4097
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
3889
|
-
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
|
+
};
|
|
3890
4133
|
const normalizeViteProcessedCssFile = (file) => path.resolve(cleanUrl(file));
|
|
3891
4134
|
const markViteProcessedCssSource = (file) => {
|
|
3892
4135
|
viteProcessedCssSourceFiles.add(normalizeViteProcessedCssFile(file));
|
|
@@ -3996,7 +4239,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
3996
4239
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3997
4240
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
3998
4241
|
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
3999
|
-
const
|
|
4242
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig);
|
|
4243
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, generatorOptions.target === "web", isNativeAppStyleTarget, sourceRoot);
|
|
4000
4244
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4001
4245
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4002
4246
|
const cssHandlerOptions = {
|
|
@@ -4087,6 +4331,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4087
4331
|
setRememberedCssSignature,
|
|
4088
4332
|
getKnownSfcSource,
|
|
4089
4333
|
recordGeneratorCandidates,
|
|
4334
|
+
pruneViteCssCaches,
|
|
4335
|
+
getViteCssCacheStats,
|
|
4090
4336
|
hmrTimingRecorder
|
|
4091
4337
|
});
|
|
4092
4338
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_vite = require("./vite-
|
|
2
|
+
const require_vite = require("./vite-BBGOjh9e.js");
|
|
3
3
|
exports.WeappTailwindcss = require_vite.WeappTailwindcss;
|
|
4
4
|
exports.weappTailwindcss = require_vite.WeappTailwindcss;
|