weapp-tailwindcss 5.1.13 → 5.1.15
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/auto-2dg_uhEJ.mjs +13 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +2 -0
- package/dist/bundlers/gulp/index.d.ts +2 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -0
- package/dist/bundlers/shared/generated-css-marker.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/types.d.ts +5 -0
- package/dist/bundlers/shared/style-requests.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -0
- package/dist/bundlers/vite/frameworks/taro/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app-x/index.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/bundle-markup-candidates.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +18 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +7 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +3 -2
- package/dist/bundlers/vite/serve-root-import-shell.d.ts +8 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
- package/dist/bundlers/vite/source-candidates.d.ts +3 -0
- package/dist/bundlers/vite/watch-css-post.d.ts +10 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-generation-loader.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -0
- package/dist/{context-xSJE588m.mjs → context-BgGWVAmN.mjs} +5 -3
- package/dist/{context-DRRgW7i2.js → context-VeFq_8vW.js} +5 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{generator-CS10c9g1.js → generator-CEnUsjed.js} +17 -3
- package/dist/{generator-BvPcmqxU.mjs → generator-CEo920So.mjs} +18 -4
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/{gulp-DNZZvUMq.js → gulp-3m1dAiig.js} +92 -54
- package/dist/{gulp-BEOzXrbp.mjs → gulp-DP71z1jG.mjs} +92 -54
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-hRhRAjYV.mjs → hmr-timing-1aS6--U7.mjs} +272 -56
- package/dist/{hmr-timing-DW1g3zjl.js → hmr-timing-B8p4f0ca.js} +323 -53
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/shared/mpx.d.ts +4 -1
- package/dist/{source-candidate-scan-signature-CMgu5bJk.js → source-candidate-scan-signature-BAahhiwb.js} +20 -139
- package/dist/{source-candidate-scan-signature-t4XKAQ04.mjs → source-candidate-scan-signature-Cf7259PR.mjs} +21 -104
- package/dist/tailwindcss/candidates.d.ts +4 -0
- package/dist/{tailwindcss-z9JMF-qU.js → tailwindcss-KBYPJ2DW.js} +1 -1
- package/dist/{tailwindcss-DZT_pWrd.mjs → tailwindcss-xs704TRw.mjs} +1 -1
- package/dist/{transform-D5JUgMpE.mjs → transform-B_KM9sLX.mjs} +47 -5
- package/dist/{transform-COFRlmDF.js → transform-CcYptivi.js} +47 -5
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +1 -1
- package/dist/{vite-DnkObu2L.js → vite-DUVjMduj.js} +807 -320
- package/dist/{vite-Tpgi77vE.mjs → vite-nXZEiwG0.mjs} +757 -270
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-generation-loader.js +12 -0
- package/dist/weapp-tw-css-import-rewrite-loader-DNk0IxAt.js +10198 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +6 -8209
- package/dist/{webpack-CTYm19zA.mjs → webpack-C_UUFRgj.mjs} +228 -58
- package/dist/{webpack-CzXjfvYS.js → webpack-nppysF4B.js} +240 -70
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +11 -3
- package/dist/auto-CrJJc5rK.mjs +0 -13
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import { At as resolveTailwindV4CssSourceBase, E as resolveTailwindcssOptions, J as hasTailwindApplyDirective, K as stripMiniProgramCssSpecificityPlaceholders, N as normalizeEmptyTailwindCustomVariants, Nt as filterUnsupportedMiniProgramTailwindV4Candidates, Q as normalizeTailwindConfigDirectives, U as hasMiniProgramCssSpecificityPlaceholders, X as hasTailwindRootDirectives, Y as hasTailwindNonRootGenerationDirectives, Z as hasTailwindSourceDirectives, a as resolveGeneratorRuntimeBranch, b as normalizeCssEntries, c as shouldUseNativeAppCssBranch, ct as hasTailwindGeneratedCssMarkers, et as normalizeTailwindSourceForGenerator, ft as stripGeneratorPlaceholderMarkers, g as upsertTailwindV4CssSource, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, j as hasUserCssLayerBlocks, l as resolveUniUtsPlatform, m as filterTailwindV4CssSourceRoots, nt as removeTailwindSourceDirectives, q as hasLocalCssImport, s as shouldUseMiniProgramCssBranch, tt as parseImportRequest, vt as getTailwindV4IncrementalGenerateCacheStats, x as findNearestPackageRoot, y as isTailwindV4CssEntry } from "./generator-
|
|
2
|
+
import { At as resolveTailwindV4CssSourceBase, E as resolveTailwindcssOptions, J as hasTailwindApplyDirective, K as stripMiniProgramCssSpecificityPlaceholders, N as normalizeEmptyTailwindCustomVariants, Nt as filterUnsupportedMiniProgramTailwindV4Candidates, Q as normalizeTailwindConfigDirectives, R as splitUserCssLayerBlocks, Tt as isFileMatchedByTailwindSourceEntries, U as hasMiniProgramCssSpecificityPlaceholders, X as hasTailwindRootDirectives, Y as hasTailwindNonRootGenerationDirectives, Z as hasTailwindSourceDirectives, a as resolveGeneratorRuntimeBranch, b as normalizeCssEntries, c as shouldUseNativeAppCssBranch, ct as hasTailwindGeneratedCssMarkers, et as normalizeTailwindSourceForGenerator, ft as stripGeneratorPlaceholderMarkers, g as upsertTailwindV4CssSource, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, j as hasUserCssLayerBlocks, l as resolveUniUtsPlatform, m as filterTailwindV4CssSourceRoots, nt as removeTailwindSourceDirectives, q as hasLocalCssImport, s as shouldUseMiniProgramCssBranch, tt as parseImportRequest, vt as getTailwindV4IncrementalGenerateCacheStats, x as findNearestPackageRoot, y as isTailwindV4CssEntry } from "./generator-CEo920So.mjs";
|
|
3
3
|
import { t as omitUndefined } from "./object-BJSWl-E5.mjs";
|
|
4
|
-
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-
|
|
4
|
+
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-xs704TRw.mjs";
|
|
5
5
|
import "./utils-MVwpU07P.mjs";
|
|
6
6
|
import { g as replaceWxml, y as createDebug } from "./wxml-DdGdeqaH.mjs";
|
|
7
|
-
import { a as vitePluginName, c as collectRuntimeClassSet, d as refreshTailwindRuntimeState, f as normalizeFrameworkStylePlatform, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, s as toCustomAttributesEntities, t as getCompilerContext } from "./context-
|
|
8
|
-
import {
|
|
9
|
-
import { A as
|
|
7
|
+
import { a as vitePluginName, c as collectRuntimeClassSet, d as refreshTailwindRuntimeState, f as normalizeFrameworkStylePlatform, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, s as toCustomAttributesEntities, t as getCompilerContext } from "./context-BgGWVAmN.mjs";
|
|
8
|
+
import { C as scoreTailwindV4CssSourceFileMatch, F as annotateCssSourceTrace, I as createCssSourceTraceCacheSignature, L as createCssTokenSourceMap, M as hasBundlerGeneratedCssMarker, N as parseBundlerGeneratedCssMarkerBlocks, O as isSourceStyleRequest, P as stripBundlerGeneratedCssMarkers, _ as mergeMarkedUserLayerComponentsCss, a as isSourceCandidateRequest, b as isPureLocalCssImportWrapper, c as createBundleRuntimeClassSetManager, f as validateCandidatesByGenerator, g as extractMarkedUserLayerComponentsCss, h as runWithConcurrency, j as createBundlerGeneratedCssMarker, k as stripRequestQuery, r as createSourceCandidateCollector, s as extractCandidatesFromSource, t as createHmrTimingRecorder, v as normalizeMiniProgramGeneratorCssSource, y as normalizeMiniProgramImportShell, z as processCachedTask } from "./hmr-timing-1aS6--U7.mjs";
|
|
9
|
+
import { A as createBuiltinViteStyleInjectorPlugins, C as createBundleModuleGraphOptions, D as toAbsoluteOutputPath, M as viteStyleInjectorDelegates, O as resolvePackageDir, P as resolveViteFrameworkProfile, S as applyLinkedResults, T as normalizeOutputPathKey, _ as isCSSRequest, a as createCandidateSignature, b as slash, c as getSnapshotHash, d as buildBundleSnapshot, g as formatPostcssSourceMap, h as cleanUrl, i as createScopedGeneratorSourceTraceMap, k as resolvePluginDisabledState, l as hasRuntimeAffectingSourceChanges, m as updateBundleBuildState, n as createScopedGeneratorCandidateSignature, o as createJsHashSalt, p as createBundleBuildState, r as createScopedGeneratorRuntime, s as createLinkedImpactSignature, t as createSourceCandidateScanSignature, u as summarizeStringDiff, v as isHTMLRequest, w as generateTailwindV4Css, x as createRuntimeAffectingSourceSignature, y as normalizePath } from "./source-candidate-scan-signature-Cf7259PR.mjs";
|
|
10
10
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
11
11
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
12
12
|
import path from "node:path";
|
|
@@ -190,8 +190,28 @@ function createStyleValueFromApplySources(sources, utilityStyles) {
|
|
|
190
190
|
}
|
|
191
191
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
|
|
193
|
+
function resolveReferencePaths(styleSource, sourceId) {
|
|
194
|
+
if (!sourceId || !styleSource.includes("@reference")) return styleSource;
|
|
195
|
+
let root;
|
|
196
|
+
try {
|
|
197
|
+
root = postcss.parse(styleSource);
|
|
198
|
+
} catch {
|
|
199
|
+
return styleSource;
|
|
200
|
+
}
|
|
201
|
+
const cleanSourceId = sourceId.replace(/\?.*$/, "");
|
|
202
|
+
root.walkAtRules("reference", (rule) => {
|
|
203
|
+
const quote = rule.params[0];
|
|
204
|
+
if (quote !== "\"" && quote !== "'") return;
|
|
205
|
+
const closingQuoteIndex = rule.params.indexOf(quote, 1);
|
|
206
|
+
if (closingQuoteIndex <= 1) return;
|
|
207
|
+
const referencePath = rule.params.slice(1, closingQuoteIndex);
|
|
208
|
+
if (!referencePath.startsWith(".")) return;
|
|
209
|
+
rule.params = `${quote}${path.resolve(path.dirname(cleanSourceId), referencePath)}${quote}${rule.params.slice(closingQuoteIndex + 1)}`;
|
|
210
|
+
});
|
|
211
|
+
return root.toString();
|
|
212
|
+
}
|
|
213
|
+
function collectUniAppXHarmonyApplyStyleSourcesFromSource(source, sourceId) {
|
|
214
|
+
return (source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source]).map((styleSource) => resolveReferencePaths(styleSource.trim(), sourceId)).filter((styleSource) => styleSource.length > 0 && styleSource.includes("@apply"));
|
|
195
215
|
}
|
|
196
216
|
function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) {
|
|
197
217
|
const utilities = /* @__PURE__ */ new Set();
|
|
@@ -236,7 +256,18 @@ const STYLE_DECL_RE = /const\s+(_style_\d+)\s*=\s*\{/g;
|
|
|
236
256
|
const EXPORT_SFC_RE = /_export_sfc\(_sfc_main\s*,\s*\[/;
|
|
237
257
|
const UNI_APP_X_STYLE_PLACEHOLDER_VERSION = "uni-app-x-style-placeholder-v2";
|
|
238
258
|
function createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, _applyUtilities) {
|
|
239
|
-
return applyStyleSources.
|
|
259
|
+
return applyStyleSources.map((source) => {
|
|
260
|
+
let root;
|
|
261
|
+
try {
|
|
262
|
+
root = postcss.parse(source);
|
|
263
|
+
} catch {
|
|
264
|
+
return source;
|
|
265
|
+
}
|
|
266
|
+
root.walkAtRules("reference", (rule) => {
|
|
267
|
+
if (rule.params.match(/^(['"])(.+?)\1/)?.[2]?.startsWith(".")) rule.remove();
|
|
268
|
+
});
|
|
269
|
+
return root.toString();
|
|
270
|
+
}).join("\n");
|
|
240
271
|
}
|
|
241
272
|
function collectUniAppXHarmonyApplyUtilities(bundle) {
|
|
242
273
|
const utilities = /* @__PURE__ */ new Set();
|
|
@@ -465,6 +496,127 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
|
465
496
|
};
|
|
466
497
|
}
|
|
467
498
|
//#endregion
|
|
499
|
+
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
500
|
+
function toArray(value) {
|
|
501
|
+
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
502
|
+
}
|
|
503
|
+
function normalizeSourceId(id) {
|
|
504
|
+
const file = cleanUrl(id);
|
|
505
|
+
return path.isAbsolute(file) ? path.resolve(file) : void 0;
|
|
506
|
+
}
|
|
507
|
+
function collectChunkModuleIds$2(chunk) {
|
|
508
|
+
const ids = /* @__PURE__ */ new Set();
|
|
509
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
510
|
+
const normalized = normalizeSourceId(id);
|
|
511
|
+
if (normalized) ids.add(normalized);
|
|
512
|
+
}
|
|
513
|
+
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
514
|
+
const normalized = normalizeSourceId(id);
|
|
515
|
+
if (normalized) ids.add(normalized);
|
|
516
|
+
}
|
|
517
|
+
return ids;
|
|
518
|
+
}
|
|
519
|
+
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
520
|
+
const ids = /* @__PURE__ */ new Set();
|
|
521
|
+
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
522
|
+
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
523
|
+
for (const candidate of candidates) {
|
|
524
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
525
|
+
const cleanCandidate = cleanUrl(candidate);
|
|
526
|
+
const resolved = path.isAbsolute(cleanCandidate) ? path.resolve(cleanCandidate) : path.resolve(rootDir, cleanCandidate);
|
|
527
|
+
ids.add(resolved);
|
|
528
|
+
}
|
|
529
|
+
return ids;
|
|
530
|
+
}
|
|
531
|
+
function isStringRuleMatched(rule, id, rootDir) {
|
|
532
|
+
const normalizedId = slash(id);
|
|
533
|
+
const normalizedRule = slash(rule);
|
|
534
|
+
if (path.isAbsolute(rule)) return micromatch.isMatch(normalizedId, normalizedRule);
|
|
535
|
+
const relative = slash(path.relative(rootDir, id));
|
|
536
|
+
return relative.length > 0 && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizedRule);
|
|
537
|
+
}
|
|
538
|
+
function isRuleMatched(rule, id, rootDir) {
|
|
539
|
+
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
540
|
+
if (rule instanceof RegExp) {
|
|
541
|
+
rule.lastIndex = 0;
|
|
542
|
+
return rule.test(slash(id));
|
|
543
|
+
}
|
|
544
|
+
return rule(id) === true;
|
|
545
|
+
}
|
|
546
|
+
function createTransformMatcher(rules, rootDir) {
|
|
547
|
+
const normalizedRules = toArray(rules);
|
|
548
|
+
if (normalizedRules.length === 0) return;
|
|
549
|
+
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
550
|
+
}
|
|
551
|
+
function shouldSkipSourceIds(sourceIds, filter) {
|
|
552
|
+
if (sourceIds.size === 0) return false;
|
|
553
|
+
if (filter.exclude) {
|
|
554
|
+
let excluded = true;
|
|
555
|
+
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
556
|
+
excluded = false;
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
if (excluded) return true;
|
|
560
|
+
}
|
|
561
|
+
if (filter.include) {
|
|
562
|
+
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
function createTransformFilter(options, rootDir) {
|
|
568
|
+
const include = createTransformMatcher(options?.include, rootDir);
|
|
569
|
+
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
570
|
+
if (!include && !exclude) return;
|
|
571
|
+
return {
|
|
572
|
+
include,
|
|
573
|
+
exclude
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
577
|
+
if (!filter) return false;
|
|
578
|
+
return shouldSkipSourceIds(collectChunkModuleIds$2(chunk), filter);
|
|
579
|
+
}
|
|
580
|
+
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
581
|
+
if (!filter) return false;
|
|
582
|
+
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
583
|
+
}
|
|
584
|
+
function createRuleSignature(rules) {
|
|
585
|
+
return toArray(rules).map((rule) => {
|
|
586
|
+
if (typeof rule === "string") return `s:${rule}`;
|
|
587
|
+
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
588
|
+
return "f";
|
|
589
|
+
}).join("|") || "none";
|
|
590
|
+
}
|
|
591
|
+
function createTransformFilterSignature(options) {
|
|
592
|
+
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
593
|
+
}
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/bundlers/vite/generate-bundle/bundle-markup-candidates.ts
|
|
596
|
+
async function collectBundleMarkupCandidates(options) {
|
|
597
|
+
const { extractSourceCandidates, previousCandidatesByFile, preserveMissingFiles, resolveSourceCandidateFile, rootDir, snapshot, transformFilter } = options;
|
|
598
|
+
const candidatesByFile = preserveMissingFiles ? new Map([...previousCandidatesByFile ?? []].map(([file, candidates]) => [file, new Set(candidates)])) : /* @__PURE__ */ new Map();
|
|
599
|
+
await Promise.all(snapshot.entries.map(async (entry) => {
|
|
600
|
+
if (!extractSourceCandidates || entry.type !== "html" || entry.output.type !== "asset" || shouldSkipViteAssetTransform(entry.output, entry.file, rootDir, transformFilter)) return;
|
|
601
|
+
const sourceFile = resolveSourceCandidateFile(entry.file) ?? path.resolve(rootDir, entry.file);
|
|
602
|
+
candidatesByFile.set(sourceFile, await extractSourceCandidates(sourceFile, entry.source));
|
|
603
|
+
}));
|
|
604
|
+
const valuesForEntries = (entries, filterOptions = {}) => {
|
|
605
|
+
const values = /* @__PURE__ */ new Set();
|
|
606
|
+
for (const [file, candidates] of candidatesByFile) {
|
|
607
|
+
if (entries !== void 0 && !isFileMatchedByTailwindSourceEntries(file, entries)) continue;
|
|
608
|
+
if (filterOptions.excludeEntries?.length && isFileMatchedByTailwindSourceEntries(file, filterOptions.excludeEntries)) continue;
|
|
609
|
+
for (const candidate of candidates) values.add(candidate);
|
|
610
|
+
}
|
|
611
|
+
return values;
|
|
612
|
+
};
|
|
613
|
+
return {
|
|
614
|
+
candidatesByFile,
|
|
615
|
+
values: valuesForEntries(void 0),
|
|
616
|
+
valuesForEntries
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
//#endregion
|
|
468
620
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
469
621
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
470
622
|
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
@@ -548,7 +700,8 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
548
700
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
549
701
|
function createCssAssetEmitter(context, bundle) {
|
|
550
702
|
return (fileName, source) => {
|
|
551
|
-
const
|
|
703
|
+
const fileNameKey = normalizeOutputPathKey(fileName);
|
|
704
|
+
const existing = bundle?.[fileName] ?? Object.entries(bundle ?? {}).find(([bundleFile, output]) => output != null && typeof output === "object" && "type" in output && output.type === "asset" && normalizeOutputPathKey("fileName" in output && typeof output.fileName === "string" ? output.fileName : bundleFile) === fileNameKey)?.[1];
|
|
552
705
|
if (existing && typeof existing === "object" && "type" in existing && existing.type === "asset") {
|
|
553
706
|
existing.source = source;
|
|
554
707
|
return existing;
|
|
@@ -645,8 +798,9 @@ function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
|
645
798
|
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
646
799
|
}
|
|
647
800
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
648
|
-
const
|
|
649
|
-
|
|
801
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
802
|
+
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(cleanFile) ? path.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(cleanFile)) : cleanFile);
|
|
803
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(cleanFile));
|
|
650
804
|
return normalizedFile;
|
|
651
805
|
}
|
|
652
806
|
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
@@ -662,9 +816,10 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
662
816
|
return outputFile;
|
|
663
817
|
}
|
|
664
818
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
819
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
820
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !isCSSRequest(file)) return cleanFile;
|
|
821
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
822
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
668
823
|
cssMatcher: opts.cssMatcher,
|
|
669
824
|
fallback: styleOutputExtension,
|
|
670
825
|
files: styleOutputFiles,
|
|
@@ -672,20 +827,40 @@ function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssE
|
|
|
672
827
|
}));
|
|
673
828
|
}
|
|
674
829
|
function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
675
|
-
const
|
|
676
|
-
const cleanFile =
|
|
830
|
+
const sourceStyleRequest = isCSSRequest(file);
|
|
831
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot).replace(/[?#].*$/, "");
|
|
832
|
+
const sourceExtension = path.extname(cleanFile);
|
|
833
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
834
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
835
|
+
return `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
836
|
+
cssMatcher: opts.cssMatcher,
|
|
837
|
+
fallback: styleOutputExtension,
|
|
838
|
+
files: styleOutputFiles,
|
|
839
|
+
stem
|
|
840
|
+
})}`;
|
|
841
|
+
}
|
|
677
842
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
678
843
|
const matchedStyleExtension = !isWebGeneratorTarget && !preserveCssExtension ? resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) : void 0;
|
|
679
|
-
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) &&
|
|
680
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(
|
|
844
|
+
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) && sourceStyleRequest) return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, matchedStyleExtension);
|
|
845
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
681
846
|
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
682
|
-
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(
|
|
683
|
-
return
|
|
847
|
+
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(cleanFile)) return cleanFile;
|
|
848
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
684
849
|
}
|
|
685
850
|
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
686
|
-
const
|
|
687
|
-
const cleanFile =
|
|
688
|
-
|
|
851
|
+
const sourceStyleRequest = isCSSRequest(sourceFile);
|
|
852
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot).replace(/[?#].*$/, "");
|
|
853
|
+
const sourceExtension = path.extname(cleanFile);
|
|
854
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
855
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
856
|
+
return resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
857
|
+
cssMatcher: opts.cssMatcher,
|
|
858
|
+
fallback: styleOutputExtension,
|
|
859
|
+
files: styleOutputFiles,
|
|
860
|
+
stem
|
|
861
|
+
})}`;
|
|
862
|
+
}
|
|
863
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
689
864
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
690
865
|
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
691
866
|
if (matchedStyleFile) return matchedStyleFile;
|
|
@@ -695,7 +870,7 @@ function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDi
|
|
|
695
870
|
files: styleOutputFiles,
|
|
696
871
|
stem
|
|
697
872
|
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
698
|
-
return
|
|
873
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
699
874
|
}
|
|
700
875
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
701
876
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
@@ -847,7 +1022,8 @@ function createCssHandlerOptionsCache(options) {
|
|
|
847
1022
|
const appType = options.getAppType();
|
|
848
1023
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
849
1024
|
const outputRoot = options.getOutputRoot?.();
|
|
850
|
-
const
|
|
1025
|
+
const sourceFile = stripRequestQuery(file);
|
|
1026
|
+
const from = path.isAbsolute(sourceFile) ? sourceFile : outputRoot ? path.resolve(outputRoot, sourceFile) : sourceFile;
|
|
851
1027
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
852
1028
|
const dynamicCssOptions = options.getDynamicCssOptions?.() ?? {};
|
|
853
1029
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}:${JSON.stringify(dynamicCssOptions)}`;
|
|
@@ -859,7 +1035,10 @@ function createCssHandlerOptionsCache(options) {
|
|
|
859
1035
|
...dynamicCssOptions,
|
|
860
1036
|
postcssOptions: { options: { from } },
|
|
861
1037
|
majorVersion: normalizeStyleHandlerMajorVersion(majorVersion),
|
|
862
|
-
sourceOptions: {
|
|
1038
|
+
sourceOptions: {
|
|
1039
|
+
outputRoot,
|
|
1040
|
+
...sourceFile === file ? {} : { requestFile: file }
|
|
1041
|
+
}
|
|
863
1042
|
};
|
|
864
1043
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
865
1044
|
return created;
|
|
@@ -899,6 +1078,21 @@ function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
|
899
1078
|
function createCssImportShell$1(targetFile, importedFile) {
|
|
900
1079
|
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
901
1080
|
}
|
|
1081
|
+
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
1082
|
+
let importedFile;
|
|
1083
|
+
try {
|
|
1084
|
+
postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
1085
|
+
if (importedFile !== void 0) return;
|
|
1086
|
+
const request = parseImportRequest(atRule.params);
|
|
1087
|
+
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
1088
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
1089
|
+
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
1090
|
+
const targetDir = path.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
1091
|
+
importedFile = normalizeOutputPathKey(path.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1092
|
+
});
|
|
1093
|
+
} catch {}
|
|
1094
|
+
return importedFile;
|
|
1095
|
+
}
|
|
902
1096
|
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
903
1097
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
904
1098
|
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
@@ -907,6 +1101,28 @@ function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
|
907
1101
|
function shouldKeepRootMiniProgramStyleAsImportShell(enabled) {
|
|
908
1102
|
return enabled === true;
|
|
909
1103
|
}
|
|
1104
|
+
function shouldPreserveFrameworkRootMiniProgramImportShell(options) {
|
|
1105
|
+
return !options.isWebGeneratorTarget && options.matchesCss && isRootMiniProgramStyleOutputFile$1(options.file) && isPureLocalCssImportWrapper(options.css) && shouldKeepRootMiniProgramStyleAsImportShell(options.shouldKeep());
|
|
1106
|
+
}
|
|
1107
|
+
function restoreFrameworkRootMiniProgramImportShellAssets(bundle, options) {
|
|
1108
|
+
if (options.isWebGeneratorTarget || options.targetByFile.size === 0) return 0;
|
|
1109
|
+
let restored = 0;
|
|
1110
|
+
for (const [sourceFile, targetFile] of options.targetByFile) {
|
|
1111
|
+
if (!options.matchesCss(sourceFile) || !options.matchesCss(targetFile) || !isRootMiniProgramStyleOutputFile$1(sourceFile) || !isRootMiniProgramStyleOutputFile$1(targetFile) || normalizeOutputPathKey(sourceFile) === normalizeOutputPathKey(targetFile)) continue;
|
|
1112
|
+
const output = Object.entries(bundle).find(([bundleFile, candidate]) => candidate.type === "asset" && normalizeOutputPathKey(candidate.fileName || bundleFile) === normalizeOutputPathKey(sourceFile))?.[1];
|
|
1113
|
+
if (output?.type !== "asset") continue;
|
|
1114
|
+
const rawSource = output.source.toString();
|
|
1115
|
+
if (!shouldKeepRootMiniProgramStyleAsImportShell(options.shouldKeep(sourceFile, rawSource))) continue;
|
|
1116
|
+
const nextSource = createCssImportShell$1(sourceFile, targetFile);
|
|
1117
|
+
if (rawSource === nextSource) continue;
|
|
1118
|
+
output.source = nextSource;
|
|
1119
|
+
options.recordCssAssetResult?.(sourceFile, nextSource);
|
|
1120
|
+
options.onUpdate?.(sourceFile, rawSource, nextSource);
|
|
1121
|
+
options.debug?.("restore framework root css import shell: %s -> %s", sourceFile, targetFile);
|
|
1122
|
+
restored++;
|
|
1123
|
+
}
|
|
1124
|
+
return restored;
|
|
1125
|
+
}
|
|
910
1126
|
function shouldMoveRootMiniProgramStyleToImportShellOrigin(enabled) {
|
|
911
1127
|
return enabled === true;
|
|
912
1128
|
}
|
|
@@ -925,6 +1141,7 @@ function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceF
|
|
|
925
1141
|
const source = rawSource.trim();
|
|
926
1142
|
if (source.length === 0) return false;
|
|
927
1143
|
if (canProcessViteSourceStyleAsCss(source, file)) return false;
|
|
1144
|
+
if (SOURCE_STYLE_OUTPUT_EXT_RE.test(assetSourceFile.replace(/[?#].*$/, ""))) return true;
|
|
928
1145
|
const isKnownStyleSource = isSourceStyleRequest(assetSourceFile) || cssMatcher?.(assetSourceFile) === true;
|
|
929
1146
|
return outputFile !== file || !isKnownStyleSource;
|
|
930
1147
|
}
|
|
@@ -1493,6 +1710,10 @@ const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
|
1493
1710
|
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1494
1711
|
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1495
1712
|
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1713
|
+
function isSfcStyleSourceFile(file) {
|
|
1714
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1715
|
+
return SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => normalizedFile.endsWith(extension));
|
|
1716
|
+
}
|
|
1496
1717
|
function extractSfcStyleBlocks(source) {
|
|
1497
1718
|
const styleSources = [];
|
|
1498
1719
|
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
@@ -1538,7 +1759,7 @@ function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
|
1538
1759
|
if (lang) params.set("lang", lang);
|
|
1539
1760
|
return `${sourceFile}?${params.toString()}`;
|
|
1540
1761
|
}
|
|
1541
|
-
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource) {
|
|
1762
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource, currentRequest) {
|
|
1542
1763
|
if (!sfcSource) return sourceFile;
|
|
1543
1764
|
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
1544
1765
|
if (styleBlocks.length === 0) return sourceFile;
|
|
@@ -1547,7 +1768,8 @@ function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSourc
|
|
|
1547
1768
|
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
1548
1769
|
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
1549
1770
|
});
|
|
1550
|
-
const
|
|
1771
|
+
const requestIndex = currentRequest ? Number.parseInt(new URLSearchParams(currentRequest.split("?", 2)[1] ?? "").get("index") ?? "", 10) : NaN;
|
|
1772
|
+
const styleBlock = (Number.isInteger(requestIndex) ? styleBlocks.find((styleBlock) => styleBlock.index === requestIndex) : void 0) ?? (matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0);
|
|
1551
1773
|
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1552
1774
|
}
|
|
1553
1775
|
function hasTailwindGenerationSource(source, options = {}) {
|
|
@@ -1585,7 +1807,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1585
1807
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1586
1808
|
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1587
1809
|
}
|
|
1588
|
-
function collectChunkModuleIds$
|
|
1810
|
+
function collectChunkModuleIds$1(output) {
|
|
1589
1811
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1590
1812
|
return [
|
|
1591
1813
|
output.facadeModuleId,
|
|
@@ -1609,7 +1831,7 @@ function resolveSiblingJsChunkFile(outputFile, cssMatcher) {
|
|
|
1609
1831
|
}
|
|
1610
1832
|
function normalizeSfcModuleId(id) {
|
|
1611
1833
|
const file = id.replace(/[?#].*$/, "");
|
|
1612
|
-
if (!
|
|
1834
|
+
if (!isSfcStyleSourceFile(file)) return;
|
|
1613
1835
|
if (!path.isAbsolute(file)) return;
|
|
1614
1836
|
return path.resolve(file);
|
|
1615
1837
|
}
|
|
@@ -1625,7 +1847,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1625
1847
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1626
1848
|
return;
|
|
1627
1849
|
}
|
|
1628
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1850
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1629
1851
|
if (sourceFiles.length === 0) {
|
|
1630
1852
|
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1631
1853
|
return;
|
|
@@ -1656,7 +1878,7 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1656
1878
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1657
1879
|
return;
|
|
1658
1880
|
}
|
|
1659
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1881
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1660
1882
|
if (sourceFiles.length === 0) {
|
|
1661
1883
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1662
1884
|
return;
|
|
@@ -1775,7 +1997,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1775
1997
|
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1776
1998
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
|
|
1777
1999
|
if (!matchedSubpackageRoot) continue;
|
|
1778
|
-
for (const moduleId of collectChunkModuleIds$
|
|
2000
|
+
for (const moduleId of collectChunkModuleIds$1(entry.output)) {
|
|
1779
2001
|
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1780
2002
|
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1781
2003
|
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
@@ -2257,11 +2479,17 @@ function isMiniProgramStyleOutputFile(file) {
|
|
|
2257
2479
|
}
|
|
2258
2480
|
function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
|
|
2259
2481
|
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2260
|
-
return context !== void 0 &&
|
|
2261
|
-
...context,
|
|
2482
|
+
return context !== void 0 && shouldPreserveFrameworkRootMiniProgramImportShell({
|
|
2262
2483
|
css,
|
|
2263
|
-
file
|
|
2264
|
-
|
|
2484
|
+
file,
|
|
2485
|
+
isWebGeneratorTarget: context.currentGeneratorBranch?.isWeb === true,
|
|
2486
|
+
matchesCss: options.opts.cssMatcher(file),
|
|
2487
|
+
shouldKeep: () => options.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
2488
|
+
...context,
|
|
2489
|
+
css,
|
|
2490
|
+
file
|
|
2491
|
+
})
|
|
2492
|
+
});
|
|
2265
2493
|
}
|
|
2266
2494
|
function resolvePreservedImportShellInjectionTarget(options, bundle, file, css) {
|
|
2267
2495
|
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
@@ -3031,21 +3259,6 @@ function resolveRootMiniProgramOriginStyleFile(file) {
|
|
|
3031
3259
|
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
3032
3260
|
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
3033
3261
|
}
|
|
3034
|
-
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
3035
|
-
let importedFile;
|
|
3036
|
-
try {
|
|
3037
|
-
postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
3038
|
-
if (importedFile !== void 0) return;
|
|
3039
|
-
const request = parseImportRequest(atRule.params);
|
|
3040
|
-
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
3041
|
-
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
3042
|
-
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
3043
|
-
const targetDir = path.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
3044
|
-
importedFile = normalizeOutputPathKey(path.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
3045
|
-
});
|
|
3046
|
-
} catch {}
|
|
3047
|
-
return importedFile;
|
|
3048
|
-
}
|
|
3049
3262
|
function normalizeRootMiniProgramImportShellAssets(bundle, options) {
|
|
3050
3263
|
if (!options.enabled) return 0;
|
|
3051
3264
|
let updated = 0;
|
|
@@ -3315,11 +3528,12 @@ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
|
3315
3528
|
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
3316
3529
|
function processHtmlBundleEntry(options) {
|
|
3317
3530
|
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
3318
|
-
const
|
|
3319
|
-
const
|
|
3320
|
-
const
|
|
3531
|
+
const currentBundleSource = originalEntrySource;
|
|
3532
|
+
const candidateSource = resolveCurrentSourceCandidateSource(file) ?? currentBundleSource;
|
|
3533
|
+
const currentRawDynamicCandidates = /* @__PURE__ */ new Set([...collectUnescapedDynamicCandidates(candidateSource), ...collectUnescapedDynamicCandidates(currentBundleSource)]);
|
|
3534
|
+
const templateRuntime = currentRawDynamicCandidates.size > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3321
3535
|
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
3322
|
-
const htmlProcessHash = `${cache.computeHash(
|
|
3536
|
+
const htmlProcessHash = `${cache.computeHash(currentBundleSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(currentBundleSource, "html"))}:${templateRuntimeSignature}`;
|
|
3323
3537
|
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3324
3538
|
const hashKey = cacheKey;
|
|
3325
3539
|
rememberProcessCacheKey(cacheKey, hashKey);
|
|
@@ -3337,7 +3551,7 @@ function processHtmlBundleEntry(options) {
|
|
|
3337
3551
|
},
|
|
3338
3552
|
async transform() {
|
|
3339
3553
|
const start = performance.now();
|
|
3340
|
-
let transformed = await templateHandler(
|
|
3554
|
+
let transformed = await templateHandler(currentBundleSource, { runtimeSet: templateRuntime });
|
|
3341
3555
|
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3342
3556
|
let retryRuntimeSet;
|
|
3343
3557
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
@@ -3348,13 +3562,13 @@ function processHtmlBundleEntry(options) {
|
|
|
3348
3562
|
}
|
|
3349
3563
|
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
3350
3564
|
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3351
|
-
transformed = await templateHandler(
|
|
3565
|
+
transformed = await templateHandler(currentBundleSource, { runtimeSet: retryRuntimeSet });
|
|
3352
3566
|
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3353
3567
|
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3354
3568
|
}
|
|
3355
3569
|
metrics.html.elapsed += measureElapsed(start);
|
|
3356
3570
|
metrics.html.transformed++;
|
|
3357
|
-
onUpdate(file,
|
|
3571
|
+
onUpdate(file, currentBundleSource, transformed);
|
|
3358
3572
|
debug("html handle: %s", file);
|
|
3359
3573
|
return { result: transformed };
|
|
3360
3574
|
}
|
|
@@ -3460,7 +3674,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
3460
3674
|
//#region src/uni-app-x/vite.ts
|
|
3461
3675
|
let transformUVuePromise;
|
|
3462
3676
|
function loadTransformUVue() {
|
|
3463
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
3677
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-B_KM9sLX.mjs").then((mod) => mod.transformUVue));
|
|
3464
3678
|
return transformUVuePromise;
|
|
3465
3679
|
}
|
|
3466
3680
|
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
@@ -3501,8 +3715,8 @@ function createUniAppXPlugins(options) {
|
|
|
3501
3715
|
let componentLocalStyleEnabled;
|
|
3502
3716
|
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
3503
3717
|
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
3504
|
-
function rememberHarmonyApplySource(code) {
|
|
3505
|
-
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
3718
|
+
function rememberHarmonyApplySource(code, id) {
|
|
3719
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code, id);
|
|
3506
3720
|
if (styleSources.length === 0) return;
|
|
3507
3721
|
for (const styleSource of styleSources) {
|
|
3508
3722
|
harmonyApplyStyleSources.add(styleSource);
|
|
@@ -3535,7 +3749,7 @@ function createUniAppXPlugins(options) {
|
|
|
3535
3749
|
if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
3536
3750
|
if (isCssModuleExport(code)) return;
|
|
3537
3751
|
const shouldGenerateCss = hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
3538
|
-
rememberHarmonyApplySource(code);
|
|
3752
|
+
rememberHarmonyApplySource(code, id);
|
|
3539
3753
|
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
3540
3754
|
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
3541
3755
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
@@ -3595,7 +3809,7 @@ function createUniAppXPlugins(options) {
|
|
|
3595
3809
|
async transform(code, id) {
|
|
3596
3810
|
if (!isEnabled()) return;
|
|
3597
3811
|
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3598
|
-
rememberHarmonyApplySource(code);
|
|
3812
|
+
rememberHarmonyApplySource(code, id);
|
|
3599
3813
|
const resolvedConfig = getResolvedConfig();
|
|
3600
3814
|
const isServeCommand = resolvedConfig?.command === "serve";
|
|
3601
3815
|
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
@@ -3604,13 +3818,19 @@ function createUniAppXPlugins(options) {
|
|
|
3604
3818
|
const transformUVue = await loadTransformUVue();
|
|
3605
3819
|
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
3606
3820
|
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
3607
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle)
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3821
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) {
|
|
3822
|
+
const result = transformUVue(code, id, jsHandler, currentRuntimeSet, omitUndefined({
|
|
3823
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
3824
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
3825
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
3826
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
3827
|
+
}));
|
|
3828
|
+
if (result?.code) rememberHarmonyApplySource(result.code, id);
|
|
3829
|
+
return result;
|
|
3830
|
+
}
|
|
3831
|
+
const result = transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
3832
|
+
if (result?.code) rememberHarmonyApplySource(result.code, id);
|
|
3833
|
+
return result;
|
|
3614
3834
|
},
|
|
3615
3835
|
async handleHotUpdate(ctx) {
|
|
3616
3836
|
if (!isEnabled()) return;
|
|
@@ -3640,7 +3860,7 @@ function createUniAppXPlugins(options) {
|
|
|
3640
3860
|
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3641
3861
|
if (isHarmonyTarget) {
|
|
3642
3862
|
const cssSources = [];
|
|
3643
|
-
const applyStyleSources = [...harmonyApplyStyleSources
|
|
3863
|
+
const applyStyleSources = harmonyApplyStyleSources.size > 0 ? [...harmonyApplyStyleSources] : collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3644
3864
|
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
3645
3865
|
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
3646
3866
|
const harmonyApplyCssFile = path.resolve(getResolvedConfig()?.root ?? process$1.cwd(), "uni-app-x-harmony-apply.css");
|
|
@@ -3918,17 +4138,25 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3918
4138
|
}
|
|
3919
4139
|
//#endregion
|
|
3920
4140
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
4141
|
+
function shouldSkipRawRememberedCssSource(rawSource, sourceFile) {
|
|
4142
|
+
const cleanSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
4143
|
+
return SOURCE_STYLE_OUTPUT_EXT_RE.test(cleanSourceFile) && !canProcessViteSourceStyleAsCss(rawSource, sourceFile);
|
|
4144
|
+
}
|
|
3921
4145
|
async function processRememberedCssReplay(options) {
|
|
3922
|
-
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, changedCssFiles = /* @__PURE__ */ new Set(), createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssRawSourceHashByFile = /* @__PURE__ */ new Map(), lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
4146
|
+
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, changedCssFiles = /* @__PURE__ */ new Set(), createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, cssPipelineContext, cssPipelineStrategy, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssRawSourceHashByFile = /* @__PURE__ */ new Map(), lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3923
4147
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3924
4148
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3925
4149
|
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
3926
|
-
const
|
|
4150
|
+
const replayableRememberedGroup = (await Promise.all(rememberedGroup.map(async (item) => ({
|
|
3927
4151
|
key: item.key,
|
|
3928
4152
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
3929
|
-
})))
|
|
3930
|
-
|
|
3931
|
-
|
|
4153
|
+
})))).filter(({ remembered }) => {
|
|
4154
|
+
const shouldSkip = shouldSkipRawRememberedCssSource(remembered.rawSource, remembered.sourceFile);
|
|
4155
|
+
if (shouldSkip) debug("css replay skip raw source style: %s -> %s", remembered.sourceFile, outputFile);
|
|
4156
|
+
return !shouldSkip;
|
|
4157
|
+
});
|
|
4158
|
+
const rememberedKeys = replayableRememberedGroup.map((item) => item.key);
|
|
4159
|
+
const rememberedCssSource = mergeRememberedCssSources(replayableRememberedGroup.map((item) => item.remembered), outputFile);
|
|
3932
4160
|
if (!rememberedCssSource) continue;
|
|
3933
4161
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
3934
4162
|
const generatorRawSource = isWebGeneratorTarget ? rawSource : normalizeMiniProgramGeneratorCssSource(rawSource, outputFile);
|
|
@@ -3963,7 +4191,17 @@ async function processRememberedCssReplay(options) {
|
|
|
3963
4191
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
3964
4192
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
3965
4193
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
3966
|
-
if (
|
|
4194
|
+
if (shouldPreserveFrameworkRootMiniProgramImportShell({
|
|
4195
|
+
css: rawSource,
|
|
4196
|
+
file: outputFile,
|
|
4197
|
+
isWebGeneratorTarget,
|
|
4198
|
+
matchesCss: opts.cssMatcher(outputFile),
|
|
4199
|
+
shouldKeep: () => cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
4200
|
+
...cssPipelineContext,
|
|
4201
|
+
css: rawSource,
|
|
4202
|
+
file: outputFile
|
|
4203
|
+
})
|
|
4204
|
+
}) || !isRootMiniProgramStyleOutputFile$1(outputFile) && !isWebGeneratorTarget && isPureLocalCssImportWrapper(rawSource)) {
|
|
3967
4205
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
3968
4206
|
const start = performance.now();
|
|
3969
4207
|
const css = annotateCss(normalizeMiniProgramImportShell(rawSource));
|
|
@@ -4223,13 +4461,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
4223
4461
|
function normalizeSourceCandidatePathKey(file) {
|
|
4224
4462
|
return normalizeOutputPathKey(path.resolve(file));
|
|
4225
4463
|
}
|
|
4226
|
-
function
|
|
4227
|
-
const { file,
|
|
4464
|
+
function createSourceCandidateFiles(options) {
|
|
4465
|
+
const { file, outDir, rootDir, sourceRoot } = options;
|
|
4228
4466
|
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
4229
|
-
const normalizedFile = normalizeOutputPathKey(cleanedFile);
|
|
4230
4467
|
const absoluteFile = path.isAbsolute(cleanedFile) ? cleanedFile : path.resolve(rootDir, cleanedFile);
|
|
4231
4468
|
const relativeFromOutDir = normalizeOutputPathKey(path.relative(outDir, absoluteFile));
|
|
4232
|
-
|
|
4469
|
+
return [
|
|
4233
4470
|
sourceRoot ? path.resolve(sourceRoot, file) : void 0,
|
|
4234
4471
|
path.resolve(rootDir, file),
|
|
4235
4472
|
path.resolve(path.dirname(outDir), file),
|
|
@@ -4238,6 +4475,33 @@ function resolveCurrentSourceCandidateSource(options) {
|
|
|
4238
4475
|
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(path.dirname(outDir), relativeFromOutDir) : void 0,
|
|
4239
4476
|
file
|
|
4240
4477
|
];
|
|
4478
|
+
}
|
|
4479
|
+
function resolveCurrentSourceCandidateFile(options) {
|
|
4480
|
+
const sourceCandidates = createSourceCandidateFiles(options);
|
|
4481
|
+
for (const candidate of sourceCandidates) if (candidate && options.getSourceCandidateSource?.(candidate) !== void 0) return candidate;
|
|
4482
|
+
const normalizedFile = normalizeOutputPathKey(options.file.replace(/[?#].*$/, ""));
|
|
4483
|
+
let bestMatch;
|
|
4484
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
4485
|
+
absolute: path.isAbsolute(candidate),
|
|
4486
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
4487
|
+
}));
|
|
4488
|
+
for (const [sourceFile] of options.getSourceCandidateSources?.() ?? []) {
|
|
4489
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
4490
|
+
let score = normalizedSourceCandidates.reduce((current, candidate) => {
|
|
4491
|
+
return normalizedSourceFile === candidate.key ? Math.max(current, candidate.absolute ? 100 : 80) : current;
|
|
4492
|
+
}, 0);
|
|
4493
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
4494
|
+
if (score > (bestMatch?.score ?? 0)) bestMatch = {
|
|
4495
|
+
file: sourceFile,
|
|
4496
|
+
score
|
|
4497
|
+
};
|
|
4498
|
+
}
|
|
4499
|
+
return bestMatch?.file;
|
|
4500
|
+
}
|
|
4501
|
+
function resolveCurrentSourceCandidateSource(options) {
|
|
4502
|
+
const { file, getSourceCandidateSource, getSourceCandidateSources } = options;
|
|
4503
|
+
const normalizedFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4504
|
+
const sourceCandidates = createSourceCandidateFiles(options);
|
|
4241
4505
|
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
4242
4506
|
if (source || !candidate) return source;
|
|
4243
4507
|
return getSourceCandidateSource?.(candidate);
|
|
@@ -4496,102 +4760,6 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
4496
4760
|
};
|
|
4497
4761
|
}
|
|
4498
4762
|
//#endregion
|
|
4499
|
-
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
4500
|
-
function toArray(value) {
|
|
4501
|
-
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
4502
|
-
}
|
|
4503
|
-
function normalizeSourceId(id) {
|
|
4504
|
-
const file = cleanUrl(id);
|
|
4505
|
-
return path.isAbsolute(file) ? path.resolve(file) : void 0;
|
|
4506
|
-
}
|
|
4507
|
-
function collectChunkModuleIds$1(chunk) {
|
|
4508
|
-
const ids = /* @__PURE__ */ new Set();
|
|
4509
|
-
for (const id of chunk.moduleIds ?? []) {
|
|
4510
|
-
const normalized = normalizeSourceId(id);
|
|
4511
|
-
if (normalized) ids.add(normalized);
|
|
4512
|
-
}
|
|
4513
|
-
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
4514
|
-
const normalized = normalizeSourceId(id);
|
|
4515
|
-
if (normalized) ids.add(normalized);
|
|
4516
|
-
}
|
|
4517
|
-
return ids;
|
|
4518
|
-
}
|
|
4519
|
-
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
4520
|
-
const ids = /* @__PURE__ */ new Set();
|
|
4521
|
-
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
4522
|
-
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
4523
|
-
for (const candidate of candidates) {
|
|
4524
|
-
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
4525
|
-
const cleanCandidate = cleanUrl(candidate);
|
|
4526
|
-
const resolved = path.isAbsolute(cleanCandidate) ? path.resolve(cleanCandidate) : path.resolve(rootDir, cleanCandidate);
|
|
4527
|
-
ids.add(resolved);
|
|
4528
|
-
}
|
|
4529
|
-
return ids;
|
|
4530
|
-
}
|
|
4531
|
-
function isStringRuleMatched(rule, id, rootDir) {
|
|
4532
|
-
const normalizedId = slash(id);
|
|
4533
|
-
const normalizedRule = slash(rule);
|
|
4534
|
-
if (path.isAbsolute(rule)) return micromatch.isMatch(normalizedId, normalizedRule);
|
|
4535
|
-
const relative = slash(path.relative(rootDir, id));
|
|
4536
|
-
return relative.length > 0 && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizedRule);
|
|
4537
|
-
}
|
|
4538
|
-
function isRuleMatched(rule, id, rootDir) {
|
|
4539
|
-
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
4540
|
-
if (rule instanceof RegExp) {
|
|
4541
|
-
rule.lastIndex = 0;
|
|
4542
|
-
return rule.test(slash(id));
|
|
4543
|
-
}
|
|
4544
|
-
return rule(id) === true;
|
|
4545
|
-
}
|
|
4546
|
-
function createTransformMatcher(rules, rootDir) {
|
|
4547
|
-
const normalizedRules = toArray(rules);
|
|
4548
|
-
if (normalizedRules.length === 0) return;
|
|
4549
|
-
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
4550
|
-
}
|
|
4551
|
-
function shouldSkipSourceIds(sourceIds, filter) {
|
|
4552
|
-
if (sourceIds.size === 0) return false;
|
|
4553
|
-
if (filter.exclude) {
|
|
4554
|
-
let excluded = true;
|
|
4555
|
-
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
4556
|
-
excluded = false;
|
|
4557
|
-
break;
|
|
4558
|
-
}
|
|
4559
|
-
if (excluded) return true;
|
|
4560
|
-
}
|
|
4561
|
-
if (filter.include) {
|
|
4562
|
-
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
4563
|
-
return true;
|
|
4564
|
-
}
|
|
4565
|
-
return false;
|
|
4566
|
-
}
|
|
4567
|
-
function createTransformFilter(options, rootDir) {
|
|
4568
|
-
const include = createTransformMatcher(options?.include, rootDir);
|
|
4569
|
-
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
4570
|
-
if (!include && !exclude) return;
|
|
4571
|
-
return {
|
|
4572
|
-
include,
|
|
4573
|
-
exclude
|
|
4574
|
-
};
|
|
4575
|
-
}
|
|
4576
|
-
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
4577
|
-
if (!filter) return false;
|
|
4578
|
-
return shouldSkipSourceIds(collectChunkModuleIds$1(chunk), filter);
|
|
4579
|
-
}
|
|
4580
|
-
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
4581
|
-
if (!filter) return false;
|
|
4582
|
-
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
4583
|
-
}
|
|
4584
|
-
function createRuleSignature(rules) {
|
|
4585
|
-
return toArray(rules).map((rule) => {
|
|
4586
|
-
if (typeof rule === "string") return `s:${rule}`;
|
|
4587
|
-
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
4588
|
-
return "f";
|
|
4589
|
-
}).join("|") || "none";
|
|
4590
|
-
}
|
|
4591
|
-
function createTransformFilterSignature(options) {
|
|
4592
|
-
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
4593
|
-
}
|
|
4594
|
-
//#endregion
|
|
4595
4763
|
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
4596
4764
|
function resolveSourceRootCandidate(root, value) {
|
|
4597
4765
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
@@ -4674,6 +4842,7 @@ function createGenerateBundleHook(context) {
|
|
|
4674
4842
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4675
4843
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4676
4844
|
const lastCssRawSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4845
|
+
const frameworkRootImportShellTargetByFile = context.frameworkRootImportShellTargetByFile ?? /* @__PURE__ */ new Map();
|
|
4677
4846
|
let currentOutDir;
|
|
4678
4847
|
let currentSubpackageRoots;
|
|
4679
4848
|
const createInitialCssPipelineContext = (file) => {
|
|
@@ -4711,8 +4880,11 @@ function createGenerateBundleHook(context) {
|
|
|
4711
4880
|
})
|
|
4712
4881
|
});
|
|
4713
4882
|
return async function generateBundle(_opt, bundle) {
|
|
4883
|
+
if (context.shouldProcessBundle?.() === false) return;
|
|
4884
|
+
const processMarkupAndScripts = context.processMarkupAndScripts !== false;
|
|
4885
|
+
const processStyles = context.shouldProcessStyles?.() ?? context.processStyles !== false;
|
|
4714
4886
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
4715
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownCssSource, getKnownSfcSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
4887
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, extractSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownCssSource, getKnownSfcSource, getOriginalCssLayerSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
4716
4888
|
const getBundlerSfcSource = (sourceFile) => {
|
|
4717
4889
|
const code = this.getModuleInfo?.(sourceFile)?.code;
|
|
4718
4890
|
return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
|
|
@@ -4797,16 +4969,38 @@ function createGenerateBundleHook(context) {
|
|
|
4797
4969
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
4798
4970
|
const bundleFiles = Object.keys(bundle);
|
|
4799
4971
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
4800
|
-
const
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4972
|
+
const normalizeSystemAliasPathKey = (file) => file.startsWith("/private/var/") ? file.slice(8) : file;
|
|
4973
|
+
const normalizeConfiguredCssSourceCacheKey = (file) => normalizeSystemAliasPathKey(normalizeOutputPathKey(path.resolve(file.replace(/[?#].*$/, ""))));
|
|
4974
|
+
const runtimeTailwindcssOptions = resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions);
|
|
4975
|
+
const tailwindRuntimeOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
4976
|
+
const configuredTailwindV4ExplicitCssEntryFiles = [...new Set([
|
|
4977
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
4978
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
4979
|
+
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4980
|
+
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4981
|
+
].filter((file) => typeof file === "string" && file.length > 0))];
|
|
4982
|
+
const getConfiguredTailwindV4CssSourceEntries = () => {
|
|
4983
|
+
const collectedEntries = collectConfiguredTailwindV4CssSourceEntries({
|
|
4984
|
+
...opts,
|
|
4985
|
+
tailwindcssRuntimeOptions: {
|
|
4986
|
+
...opts.tailwindcssRuntimeOptions ?? {},
|
|
4987
|
+
tailwindcss: {
|
|
4988
|
+
...resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions) ?? {},
|
|
4989
|
+
...resolveTailwindcssOptions(runtimeState.tailwindRuntime.options) ?? {}
|
|
4990
|
+
}
|
|
4807
4991
|
}
|
|
4808
|
-
}
|
|
4809
|
-
|
|
4992
|
+
}, opts.tailwindcssBasedir ?? rootDir);
|
|
4993
|
+
const cachedEntries = configuredTailwindV4ExplicitCssEntryFiles.flatMap((file) => {
|
|
4994
|
+
const resolvedFile = path.isAbsolute(file) ? path.resolve(file) : path.resolve(opts.tailwindcssBasedir ?? rootDir, file);
|
|
4995
|
+
const source = getCssSource(resolvedFile);
|
|
4996
|
+
return typeof source === "string" && source.length > 0 ? [{
|
|
4997
|
+
file: resolvedFile,
|
|
4998
|
+
source
|
|
4999
|
+
}] : [];
|
|
5000
|
+
});
|
|
5001
|
+
const cachedFileKeys = new Set(cachedEntries.map((entry) => normalizeConfiguredCssSourceCacheKey(entry.file)));
|
|
5002
|
+
return [...cachedEntries, ...collectedEntries.filter((entry) => !cachedFileKeys.has(normalizeConfiguredCssSourceCacheKey(entry.file)))];
|
|
5003
|
+
};
|
|
4810
5004
|
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
4811
5005
|
const resolveMatchedCssSourceOutputFile = (sourceFile) => resolveOutputFileFromMatchedCssSource({
|
|
4812
5006
|
bundleFiles,
|
|
@@ -4827,20 +5021,12 @@ function createGenerateBundleHook(context) {
|
|
|
4827
5021
|
const snapshotStart = performance.now();
|
|
4828
5022
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
4829
5023
|
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
4830
|
-
const normalizeSystemAliasPathKey = (file) => file.startsWith("/private/var/") ? file.slice(8) : file;
|
|
4831
5024
|
const normalizeConfiguredTailwindV4CssEntryFileKey = (file) => {
|
|
4832
5025
|
const cleanFile = file.replace(/[?#].*$/, "");
|
|
4833
5026
|
return normalizeSystemAliasPathKey(normalizeOutputPathKey(path.isAbsolute(cleanFile) ? path.resolve(cleanFile) : path.resolve(opts.tailwindcssBasedir ?? rootDir, cleanFile)));
|
|
4834
5027
|
};
|
|
4835
|
-
const runtimeTailwindcssOptions = resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions);
|
|
4836
|
-
const tailwindRuntimeOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
4837
5028
|
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)));
|
|
4838
|
-
const configuredTailwindV4ExplicitCssEntryFileKeysForScope = new Set(
|
|
4839
|
-
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
4840
|
-
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
4841
|
-
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4842
|
-
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4843
|
-
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
5029
|
+
const configuredTailwindV4ExplicitCssEntryFileKeysForScope = new Set(configuredTailwindV4ExplicitCssEntryFiles.map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4844
5030
|
const isRootStyleOutputFile = (file) => {
|
|
4845
5031
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4846
5032
|
return normalized.endsWith(".css") && !normalized.includes("/");
|
|
@@ -4870,9 +5056,11 @@ function createGenerateBundleHook(context) {
|
|
|
4870
5056
|
const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
|
|
4871
5057
|
const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
|
|
4872
5058
|
if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
|
|
4873
|
-
if (!shouldSelectConfiguredRootCssOutput(outputFile)) return;
|
|
4874
5059
|
const shouldRequireExplicitConfiguredEntry = !cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile);
|
|
4875
5060
|
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source) && (!shouldRequireExplicitConfiguredEntry || configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(entry.file))));
|
|
5061
|
+
const matchedOutputEntries = generationEntries.filter((entry) => normalizeOutputPathKey(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file).replace(/[?#].*$/, "")) === normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")));
|
|
5062
|
+
if (matchedOutputEntries.length === 1) return matchedOutputEntries[0];
|
|
5063
|
+
if (!shouldSelectConfiguredRootCssOutput(outputFile)) return;
|
|
4876
5064
|
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4877
5065
|
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
4878
5066
|
return !normalizeOutputPathKey(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file).replace(/[?#].*$/, "")).includes("/");
|
|
@@ -4914,18 +5102,6 @@ function createGenerateBundleHook(context) {
|
|
|
4914
5102
|
return !normalizeOutputPathKey(entryOutputFile.replace(/[?#].*$/, "")).includes("/") || currentSubpackageRoots != null && !isSubpackageOutputFile(entryOutputFile, currentSubpackageRoots);
|
|
4915
5103
|
});
|
|
4916
5104
|
};
|
|
4917
|
-
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4918
|
-
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4919
|
-
getSourceCandidateSourcesForEntries,
|
|
4920
|
-
getSourceCandidatesForEntries,
|
|
4921
|
-
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
4922
|
-
rootDir,
|
|
4923
|
-
snapshot,
|
|
4924
|
-
sourceRoot,
|
|
4925
|
-
subpackageRoots: currentSubpackageRoots,
|
|
4926
|
-
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
4927
|
-
useIncrementalMode
|
|
4928
|
-
});
|
|
4929
5105
|
recordTimingDetail("snapshot", snapshotStart);
|
|
4930
5106
|
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
4931
5107
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -4939,11 +5115,41 @@ function createGenerateBundleHook(context) {
|
|
|
4939
5115
|
const sourceCandidateWaitStart = performance.now();
|
|
4940
5116
|
await waitForSourceCandidateSyncs?.();
|
|
4941
5117
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
4942
|
-
const
|
|
5118
|
+
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
5119
|
+
const bundleMarkupCandidates = await collectBundleMarkupCandidates({
|
|
5120
|
+
extractSourceCandidates: processMarkupAndScripts && !isWebGeneratorTarget ? extractSourceCandidates : void 0,
|
|
5121
|
+
previousCandidatesByFile: useIncrementalMode ? state.bundleMarkupCandidatesByFile : void 0,
|
|
5122
|
+
preserveMissingFiles: useIncrementalMode && snapshot.hasOmittedKnownFiles,
|
|
5123
|
+
resolveSourceCandidateFile: (file) => resolveCurrentSourceCandidateFile({
|
|
5124
|
+
file,
|
|
5125
|
+
getSourceCandidateSource,
|
|
5126
|
+
getSourceCandidateSources,
|
|
5127
|
+
outDir,
|
|
5128
|
+
rootDir,
|
|
5129
|
+
sourceRoot
|
|
5130
|
+
}),
|
|
5131
|
+
rootDir,
|
|
5132
|
+
snapshot,
|
|
5133
|
+
transformFilter
|
|
5134
|
+
});
|
|
5135
|
+
const getCombinedSourceCandidatesForEntries = getSourceCandidatesForEntries || bundleMarkupCandidates.values.size > 0 ? (entries, options) => /* @__PURE__ */ new Set([...getSourceCandidatesForEntries?.(entries, options) ?? [], ...bundleMarkupCandidates.valuesForEntries(entries, options)]) : void 0;
|
|
5136
|
+
const sourceCandidates = /* @__PURE__ */ new Set([...getSourceCandidates?.() ?? [], ...bundleMarkupCandidates.values]);
|
|
5137
|
+
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
5138
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
5139
|
+
getSourceCandidateSourcesForEntries,
|
|
5140
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5141
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
5142
|
+
rootDir,
|
|
5143
|
+
snapshot,
|
|
5144
|
+
sourceRoot,
|
|
5145
|
+
subpackageRoots: currentSubpackageRoots,
|
|
5146
|
+
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
5147
|
+
useIncrementalMode
|
|
5148
|
+
});
|
|
4943
5149
|
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => createScopedGeneratorRuntime({
|
|
4944
5150
|
cssHandlerOptions,
|
|
4945
5151
|
fallbackRuntime: runtime,
|
|
4946
|
-
getSourceCandidatesForEntries,
|
|
5152
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
4947
5153
|
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4948
5154
|
outputFile,
|
|
4949
5155
|
rawSource,
|
|
@@ -4953,7 +5159,6 @@ function createGenerateBundleHook(context) {
|
|
|
4953
5159
|
});
|
|
4954
5160
|
const jsEntries = snapshot.jsEntries;
|
|
4955
5161
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
4956
|
-
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
4957
5162
|
const transformFilterSignature = createTransformFilterSignature(opts.transform);
|
|
4958
5163
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
4959
5164
|
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -5103,7 +5308,7 @@ function createGenerateBundleHook(context) {
|
|
|
5103
5308
|
const jsTaskFactories = [];
|
|
5104
5309
|
for (const entry of snapshot.entries) {
|
|
5105
5310
|
const { file, output: originalSource, source: originalEntrySource, type } = entry;
|
|
5106
|
-
if (type === "html" && originalSource.type === "asset") {
|
|
5311
|
+
if (processMarkupAndScripts && type === "html" && originalSource.type === "asset") {
|
|
5107
5312
|
metrics.html.total++;
|
|
5108
5313
|
if (isWebGeneratorTarget) {
|
|
5109
5314
|
debug("html skip web target: %s", file);
|
|
@@ -5142,14 +5347,59 @@ function createGenerateBundleHook(context) {
|
|
|
5142
5347
|
});
|
|
5143
5348
|
continue;
|
|
5144
5349
|
}
|
|
5145
|
-
if (type === "css" && originalSource.type === "asset") {
|
|
5350
|
+
if (processStyles && type === "css" && originalSource.type === "asset") {
|
|
5146
5351
|
metrics.css.total++;
|
|
5147
5352
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
5148
5353
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
5354
|
+
const currentRawSourceHasExplicitScanContext = rawSource.includes("@source") || rawSource.includes("@config");
|
|
5149
5355
|
const cssPipelineContext = {
|
|
5150
5356
|
...createInitialCssPipelineContext(file),
|
|
5151
5357
|
bundle
|
|
5152
5358
|
};
|
|
5359
|
+
const rootImportShellOutputFile = resolveReplayCssOutputFile(outDir, originalSource.fileName || file);
|
|
5360
|
+
let rememberedFrameworkRootImportTarget = frameworkRootImportShellTargetByFile.get(rootImportShellOutputFile);
|
|
5361
|
+
const isCurrentFrameworkRootImportShell = shouldPreserveFrameworkRootMiniProgramImportShell({
|
|
5362
|
+
css: rawSource,
|
|
5363
|
+
file: rootImportShellOutputFile,
|
|
5364
|
+
isWebGeneratorTarget,
|
|
5365
|
+
matchesCss: opts.cssMatcher(rootImportShellOutputFile) || opts.cssMatcher(file),
|
|
5366
|
+
shouldKeep: () => context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5367
|
+
...cssPipelineContext,
|
|
5368
|
+
css: rawSource,
|
|
5369
|
+
file: rootImportShellOutputFile
|
|
5370
|
+
})
|
|
5371
|
+
});
|
|
5372
|
+
if (isCurrentFrameworkRootImportShell) {
|
|
5373
|
+
const importedFile = resolveSingleCssImportOutputFile(rootImportShellOutputFile, rawSource);
|
|
5374
|
+
if (importedFile && isRootMiniProgramStyleOutputFile$1(importedFile)) frameworkRootImportShellTargetByFile.set(rootImportShellOutputFile, importedFile);
|
|
5375
|
+
}
|
|
5376
|
+
if (!rememberedFrameworkRootImportTarget && !isCurrentFrameworkRootImportShell && !isWebGeneratorTarget && isRootMiniProgramStyleOutputFile$1(rootImportShellOutputFile) && normalizeOutputPathKey(assetSourceFile) === normalizeOutputPathKey(file) && opts.mainCssChunkMatcher(rootImportShellOutputFile, opts.appType) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5377
|
+
...cssPipelineContext,
|
|
5378
|
+
css: rawSource,
|
|
5379
|
+
file: rootImportShellOutputFile
|
|
5380
|
+
})) && !shouldMoveRootMiniProgramStyleToImportShellOrigin(context.cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
5381
|
+
...cssPipelineContext,
|
|
5382
|
+
file: rootImportShellOutputFile
|
|
5383
|
+
}))) {
|
|
5384
|
+
const rootGeneratedTargets = /* @__PURE__ */ new Set();
|
|
5385
|
+
for (const entry of getConfiguredTailwindV4CssSourceEntries()) {
|
|
5386
|
+
const targetFile = resolveMatchedCssSourceOutputFile(entry.file);
|
|
5387
|
+
if (targetFile && isRootMiniProgramStyleOutputFile$1(targetFile) && normalizeOutputPathKey(targetFile) !== normalizeOutputPathKey(rootImportShellOutputFile)) rootGeneratedTargets.add(targetFile);
|
|
5388
|
+
}
|
|
5389
|
+
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) {
|
|
5390
|
+
if (typeof record === "string" || record.injectIntoMain !== true || !record.outputFile) continue;
|
|
5391
|
+
const targetFile = resolveViteCssPipelineOutputFile(record.outputFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
5392
|
+
if (isRootMiniProgramStyleOutputFile$1(targetFile) && normalizeOutputPathKey(targetFile) !== normalizeOutputPathKey(rootImportShellOutputFile)) rootGeneratedTargets.add(targetFile);
|
|
5393
|
+
}
|
|
5394
|
+
if (rootGeneratedTargets.size === 1) {
|
|
5395
|
+
const [targetFile] = rootGeneratedTargets;
|
|
5396
|
+
if (targetFile) {
|
|
5397
|
+
rememberedFrameworkRootImportTarget = targetFile;
|
|
5398
|
+
frameworkRootImportShellTargetByFile.set(rootImportShellOutputFile, targetFile);
|
|
5399
|
+
debug("css remember framework root generated target: %s -> %s", rootImportShellOutputFile, targetFile);
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5153
5403
|
let outputFile = resolveCssBundleOutputFile({
|
|
5154
5404
|
bundleFiles,
|
|
5155
5405
|
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
@@ -5160,6 +5410,14 @@ function createGenerateBundleHook(context) {
|
|
|
5160
5410
|
pipelineContext: cssPipelineContext,
|
|
5161
5411
|
shouldPreserveAppCssExtension
|
|
5162
5412
|
});
|
|
5413
|
+
if (rememberedFrameworkRootImportTarget && !isWebGeneratorTarget && (opts.cssMatcher(rootImportShellOutputFile) || opts.cssMatcher(file)) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5414
|
+
...cssPipelineContext,
|
|
5415
|
+
css: rawSource,
|
|
5416
|
+
file: rootImportShellOutputFile
|
|
5417
|
+
}))) {
|
|
5418
|
+
outputFile = rememberedFrameworkRootImportTarget;
|
|
5419
|
+
debug("css reuse framework root import shell target: %s -> %s", rootImportShellOutputFile, outputFile);
|
|
5420
|
+
}
|
|
5163
5421
|
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
5164
5422
|
assetSourceFile,
|
|
5165
5423
|
file,
|
|
@@ -5218,6 +5476,7 @@ function createGenerateBundleHook(context) {
|
|
|
5218
5476
|
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
5219
5477
|
}));
|
|
5220
5478
|
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
5479
|
+
if (currentRawSourceHasExplicitScanContext && !remembered.rawSource.includes("@source") && !remembered.rawSource.includes("@config")) return false;
|
|
5221
5480
|
if (hasExplicitConfiguredRootCssEntryForOutput(outputFile) && !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return false;
|
|
5222
5481
|
if (!configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return true;
|
|
5223
5482
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(remembered.sourceFile);
|
|
@@ -5237,7 +5496,7 @@ function createGenerateBundleHook(context) {
|
|
|
5237
5496
|
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
5238
5497
|
const configuredRootSourceStyle = resolveConfiguredRootCssSourceStyle(outputFile, getConfiguredTailwindV4CssSourceEntries(), originalSource.originalFileNames);
|
|
5239
5498
|
const hasExplicitRememberedRootSource = rememberedCssSources.some((remembered) => configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile)));
|
|
5240
|
-
if (configuredRootSourceStyle && (!hasUsableRememberedTailwindSource || !hasExplicitRememberedRootSource)) {
|
|
5499
|
+
if (configuredRootSourceStyle != null && (!currentRawSourceHasExplicitScanContext || hasTailwindGenerationSource(configuredRootSourceStyle.rawSource)) && (!hasUsableRememberedTailwindSource || !hasExplicitRememberedRootSource)) {
|
|
5241
5500
|
rememberedCssSources = [configuredRootSourceStyle];
|
|
5242
5501
|
hasUsableRememberedTailwindSource = true;
|
|
5243
5502
|
debug("source style source inferred from configured root tailwind v4 css source: %s -> %s", outputFile, configuredRootSourceStyle.sourceFile);
|
|
@@ -5352,6 +5611,12 @@ function createGenerateBundleHook(context) {
|
|
|
5352
5611
|
}
|
|
5353
5612
|
}
|
|
5354
5613
|
}
|
|
5614
|
+
if (currentRawSourceHasExplicitScanContext) rememberedCssSources = rememberedCssSources.filter((remembered) => remembered.rawSource.includes("@source") || remembered.rawSource.includes("@config"));
|
|
5615
|
+
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
5616
|
+
const shouldSkip = shouldSkipRawRememberedCssSource(remembered.rawSource, remembered.sourceFile);
|
|
5617
|
+
if (shouldSkip) debug("css skip raw remembered source style: %s -> %s", remembered.sourceFile, outputFile);
|
|
5618
|
+
return !shouldSkip;
|
|
5619
|
+
});
|
|
5355
5620
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
5356
5621
|
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
5357
5622
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
@@ -5365,6 +5630,17 @@ function createGenerateBundleHook(context) {
|
|
|
5365
5630
|
};
|
|
5366
5631
|
}
|
|
5367
5632
|
}
|
|
5633
|
+
if (!isWebGeneratorTarget && isRootMiniProgramStyleOutputFile$1(rootImportShellOutputFile) && isRootMiniProgramStyleOutputFile$1(outputFile) && normalizeOutputPathKey(rootImportShellOutputFile) !== normalizeOutputPathKey(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5634
|
+
...cssPipelineContext,
|
|
5635
|
+
css: rawSource,
|
|
5636
|
+
file: rootImportShellOutputFile
|
|
5637
|
+
})) && !shouldMoveRootMiniProgramStyleToImportShellOrigin(context.cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
5638
|
+
...cssPipelineContext,
|
|
5639
|
+
file: rootImportShellOutputFile
|
|
5640
|
+
}))) {
|
|
5641
|
+
frameworkRootImportShellTargetByFile.set(rootImportShellOutputFile, outputFile);
|
|
5642
|
+
debug("css remember framework root import shell target: %s -> %s", rootImportShellOutputFile, outputFile);
|
|
5643
|
+
}
|
|
5368
5644
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
5369
5645
|
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
5370
5646
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
@@ -5385,6 +5661,8 @@ function createGenerateBundleHook(context) {
|
|
|
5385
5661
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
5386
5662
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
5387
5663
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
5664
|
+
const originalGeneratorLayerSource = vitePipelineCssAsset ? getOriginalCssLayerSource?.(generatorSourceFile) : void 0;
|
|
5665
|
+
const generatorUserLayerRawSource = originalGeneratorLayerSource && normalizeCssSourceForCompare(originalGeneratorLayerSource) !== normalizeCssSourceForCompare(generatorRawSource) && hasUserCssLayerBlocks(originalGeneratorLayerSource) ? normalizeMiniProgramGeneratorRawSource(normalizeGeneratorUserRawSource(originalGeneratorLayerSource, generatorSourceFile, assetSourceFile), outputFile) : void 0;
|
|
5388
5666
|
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveConfiguredCssEntryRootInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
5389
5667
|
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
5390
5668
|
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
@@ -5515,7 +5793,10 @@ function createGenerateBundleHook(context) {
|
|
|
5515
5793
|
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !generatorCandidatesChanged && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
5516
5794
|
const generatorTransformRawSource = generatorRawSource;
|
|
5517
5795
|
const previousGeneratorCss = previousCss && !isWebGeneratorTarget ? normalizeMiniProgramGeneratorRawSource(previousCss, outputFile) : previousCss;
|
|
5518
|
-
const
|
|
5796
|
+
const shouldGenerateCssWithCore = hasTailwindGenerationSource(generatorTransformRawSource) || hasBundlerGeneratedCssMarker(rawSource);
|
|
5797
|
+
const bundleUserRawSource = vitePipelineCssAsset && !hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? normalizeMiniProgramGeneratorRawSource(normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile), outputFile) : void 0;
|
|
5798
|
+
const generatorUserRawSource = [generatorUserLayerRawSource, bundleUserRawSource].filter((source) => typeof source === "string" && source.trim().length > 0).join("\n");
|
|
5799
|
+
const generated = shouldGenerateCssWithCore ? await generateTailwindV4Css({
|
|
5519
5800
|
opts,
|
|
5520
5801
|
runtimeState,
|
|
5521
5802
|
runtime: scopedGeneratorRuntime,
|
|
@@ -5530,7 +5811,7 @@ function createGenerateBundleHook(context) {
|
|
|
5530
5811
|
styleHandler,
|
|
5531
5812
|
debug,
|
|
5532
5813
|
previousCss: previousGeneratorCss,
|
|
5533
|
-
...
|
|
5814
|
+
...generatorUserRawSource ? { userRawSource: generatorUserRawSource } : {},
|
|
5534
5815
|
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
5535
5816
|
}) : void 0;
|
|
5536
5817
|
if (generated) {
|
|
@@ -5587,6 +5868,7 @@ function createGenerateBundleHook(context) {
|
|
|
5587
5868
|
continue;
|
|
5588
5869
|
}
|
|
5589
5870
|
if (type !== "js") continue;
|
|
5871
|
+
if (!processMarkupAndScripts) continue;
|
|
5590
5872
|
if (!shouldTransformJsBundle) {
|
|
5591
5873
|
debug("js skip web target: %s", file);
|
|
5592
5874
|
continue;
|
|
@@ -5620,7 +5902,7 @@ function createGenerateBundleHook(context) {
|
|
|
5620
5902
|
useIncrementalMode
|
|
5621
5903
|
});
|
|
5622
5904
|
}
|
|
5623
|
-
if (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget) await processRememberedCssReplay({
|
|
5905
|
+
if (processStyles && (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget)) await processRememberedCssReplay({
|
|
5624
5906
|
addWatchFile,
|
|
5625
5907
|
activeViteCssCacheFiles,
|
|
5626
5908
|
bundle,
|
|
@@ -5628,6 +5910,8 @@ function createGenerateBundleHook(context) {
|
|
|
5628
5910
|
cache,
|
|
5629
5911
|
changedCssFiles: snapshot.changedByType.css,
|
|
5630
5912
|
cssTaskFactories,
|
|
5913
|
+
cssPipelineContext,
|
|
5914
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
5631
5915
|
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
5632
5916
|
createScopedSourceCandidateGetter,
|
|
5633
5917
|
createScopedSourceCandidateSourceGetter,
|
|
@@ -5680,7 +5964,7 @@ function createGenerateBundleHook(context) {
|
|
|
5680
5964
|
generatorRuntime,
|
|
5681
5965
|
getCssHandlerOptions,
|
|
5682
5966
|
getSourceCandidateSourcesForEntries,
|
|
5683
|
-
getSourceCandidatesForEntries,
|
|
5967
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5684
5968
|
getViteCssCacheStats,
|
|
5685
5969
|
getViteProcessedCssAssetResults,
|
|
5686
5970
|
hmrTimingRecorder,
|
|
@@ -5720,6 +6004,7 @@ function createGenerateBundleHook(context) {
|
|
|
5720
6004
|
transformWebTargetCss,
|
|
5721
6005
|
useIncrementalMode
|
|
5722
6006
|
});
|
|
6007
|
+
state.bundleMarkupCandidatesByFile = bundleMarkupCandidates.candidatesByFile;
|
|
5723
6008
|
};
|
|
5724
6009
|
}
|
|
5725
6010
|
//#endregion
|
|
@@ -5792,7 +6077,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5792
6077
|
generateBundle: {
|
|
5793
6078
|
order: "post",
|
|
5794
6079
|
async handler(_options, bundle) {
|
|
5795
|
-
const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
6080
|
+
const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset, frameworkRootImportShellTargetByFile } = context;
|
|
5796
6081
|
const resolvedConfig = getResolvedConfig();
|
|
5797
6082
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
5798
6083
|
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
@@ -5825,6 +6110,19 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5825
6110
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
5826
6111
|
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
5827
6112
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
6113
|
+
restoreFrameworkRootMiniProgramImportShellAssets(bundle, {
|
|
6114
|
+
debug,
|
|
6115
|
+
isWebGeneratorTarget,
|
|
6116
|
+
matchesCss: opts.cssMatcher,
|
|
6117
|
+
onUpdate: opts.onUpdate,
|
|
6118
|
+
recordCssAssetResult,
|
|
6119
|
+
shouldKeep: (file, css) => cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
6120
|
+
...createCssPipelineContext(file),
|
|
6121
|
+
css,
|
|
6122
|
+
file
|
|
6123
|
+
}),
|
|
6124
|
+
targetByFile: frameworkRootImportShellTargetByFile ?? /* @__PURE__ */ new Map()
|
|
6125
|
+
});
|
|
5828
6126
|
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
5829
6127
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
5830
6128
|
opts,
|
|
@@ -5926,10 +6224,15 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5926
6224
|
const file = output.fileName || bundleFile;
|
|
5927
6225
|
const rawSource = output.source.toString();
|
|
5928
6226
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
5929
|
-
const
|
|
6227
|
+
const cleanRawSource = stripBundlerGeneratedCssMarkers(rawSource);
|
|
6228
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
6229
|
+
...createCssPipelineContext(file),
|
|
6230
|
+
file
|
|
6231
|
+
}) ?? {});
|
|
6232
|
+
const nextCss = annotateCss(generatorBranch.isWeb ? finalizeWebCss(cleanRawSource, {
|
|
5930
6233
|
...createCssPipelineContext(file),
|
|
5931
6234
|
file
|
|
5932
|
-
}, cssPipelineStrategy));
|
|
6235
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(cleanRawSource, cssHandlerOptions)).css);
|
|
5933
6236
|
output.source = nextCss;
|
|
5934
6237
|
markCssAssetProcessed(output, file);
|
|
5935
6238
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -6745,52 +7048,74 @@ function isViteServeStyleRequest(id, command) {
|
|
|
6745
7048
|
function isViteServeCssRootRequest(id, command) {
|
|
6746
7049
|
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
6747
7050
|
}
|
|
7051
|
+
function isViteBuildStyleRequest(id, command) {
|
|
7052
|
+
return command === "build" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
7053
|
+
}
|
|
6748
7054
|
function isViteCssHmrModule(code, id, command) {
|
|
6749
7055
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && (/[?&](?:direct|vue)(?:&|$)/.test(id) || DEFERRED_CSS_HMR_QUERY_RE.test(id));
|
|
6750
7056
|
}
|
|
6751
|
-
function
|
|
7057
|
+
function hasViteCssGenerationDirective(code) {
|
|
6752
7058
|
return hasTailwindRootDirectives(code) || hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
6753
7059
|
}
|
|
6754
7060
|
function hasViteServeCssRootDirective(code) {
|
|
6755
7061
|
return hasTailwindRootDirectives(code);
|
|
6756
7062
|
}
|
|
6757
|
-
function
|
|
6758
|
-
return [
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
7063
|
+
function createViteCssGenerationPlugins(options) {
|
|
7064
|
+
return [
|
|
7065
|
+
{
|
|
7066
|
+
name: `${vitePluginName}:generate:serve`,
|
|
7067
|
+
apply: "serve",
|
|
7068
|
+
enforce: "pre",
|
|
7069
|
+
async transform(code, id) {
|
|
7070
|
+
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
7071
|
+
if (!hasTailwindRootDirectives(code)) return;
|
|
7072
|
+
if (DEFERRED_CSS_HMR_QUERY_RE.test(id)) return;
|
|
7073
|
+
await options.onTailwindRootCss?.(id, code);
|
|
7074
|
+
const generatedCss = await options.generateCss(id, code, this);
|
|
7075
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7076
|
+
return {
|
|
7077
|
+
code: generatedCss,
|
|
7078
|
+
map: null
|
|
7079
|
+
};
|
|
7080
|
+
}
|
|
7081
|
+
},
|
|
7082
|
+
{
|
|
7083
|
+
name: `${vitePluginName}:generate:build`,
|
|
7084
|
+
apply: "build",
|
|
7085
|
+
enforce: "pre",
|
|
7086
|
+
async transform(code, id) {
|
|
7087
|
+
if (!options.shouldGenerate() || options.shouldGenerateBuild?.() === false || !isViteBuildStyleRequest(id, options.getCommand())) return;
|
|
7088
|
+
if (!hasViteCssGenerationDirective(code)) return;
|
|
7089
|
+
if (hasViteServeCssRootDirective(code)) await options.onTailwindRootCss?.(id, code);
|
|
7090
|
+
const generatedCss = await options.generateCss(id, code, this);
|
|
7091
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7092
|
+
return {
|
|
7093
|
+
code: generatedCss,
|
|
7094
|
+
map: null
|
|
7095
|
+
};
|
|
7096
|
+
}
|
|
7097
|
+
},
|
|
7098
|
+
{
|
|
7099
|
+
name: `${vitePluginName}:generate:serve-hmr`,
|
|
7100
|
+
apply: "serve",
|
|
7101
|
+
enforce: "post",
|
|
7102
|
+
async transform(code, id) {
|
|
7103
|
+
if (!options.shouldGenerate() || !isViteCssHmrModule(code, id, options.getCommand())) return;
|
|
7104
|
+
const extracted = extractViteCssHmrModuleCss(code);
|
|
7105
|
+
if (!extracted) return;
|
|
7106
|
+
if (!hasViteCssGenerationDirective(extracted.css)) return;
|
|
7107
|
+
if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
|
|
7108
|
+
const generatedCss = await options.generateCss(id, extracted.css, this);
|
|
7109
|
+
if (generatedCss === void 0 || generatedCss === extracted.css) return;
|
|
7110
|
+
const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
|
|
7111
|
+
if (nextCode === void 0 || nextCode === code) return;
|
|
7112
|
+
return {
|
|
7113
|
+
code: nextCode,
|
|
7114
|
+
map: null
|
|
7115
|
+
};
|
|
7116
|
+
}
|
|
6792
7117
|
}
|
|
6793
|
-
|
|
7118
|
+
];
|
|
6794
7119
|
}
|
|
6795
7120
|
//#endregion
|
|
6796
7121
|
//#region src/bundlers/vite/serve-js-transform.ts
|
|
@@ -6819,6 +7144,22 @@ function createViteServeJsTransformPlugin(options) {
|
|
|
6819
7144
|
};
|
|
6820
7145
|
}
|
|
6821
7146
|
//#endregion
|
|
7147
|
+
//#region src/bundlers/vite/serve-root-import-shell.ts
|
|
7148
|
+
function resolveViteServeRootMiniProgramImportShell(options) {
|
|
7149
|
+
const { css, cssPipelineContext, cssPipelineStrategy, isWebGeneratorTarget, outputFile } = options;
|
|
7150
|
+
return shouldPreserveFrameworkRootMiniProgramImportShell({
|
|
7151
|
+
css,
|
|
7152
|
+
file: outputFile,
|
|
7153
|
+
isWebGeneratorTarget,
|
|
7154
|
+
matchesCss: cssPipelineContext.opts?.cssMatcher?.(outputFile) ?? true,
|
|
7155
|
+
shouldKeep: () => cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
7156
|
+
...cssPipelineContext,
|
|
7157
|
+
css,
|
|
7158
|
+
file: outputFile
|
|
7159
|
+
})
|
|
7160
|
+
}) ? normalizeMiniProgramImportShell(css) : void 0;
|
|
7161
|
+
}
|
|
7162
|
+
//#endregion
|
|
6822
7163
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
6823
7164
|
const PACKAGE_JSON_FILE = "package.json";
|
|
6824
7165
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -6839,6 +7180,40 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
6839
7180
|
return resolvedRoot;
|
|
6840
7181
|
}
|
|
6841
7182
|
//#endregion
|
|
7183
|
+
//#region src/bundlers/vite/watch-css-post.ts
|
|
7184
|
+
const wrappedCssPostPlugins = /* @__PURE__ */ new WeakSet();
|
|
7185
|
+
function isWebOrNativeAppPlatform$1(platform) {
|
|
7186
|
+
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
7187
|
+
}
|
|
7188
|
+
function shouldAdaptFrameworkWatchCssBeforeCache(options) {
|
|
7189
|
+
return options.enabled && options.ownsTailwindGeneration && options.isWatchBuild && (options.platform ? !isWebOrNativeAppPlatform$1(options.platform) : !options.isWebGeneratorBranch);
|
|
7190
|
+
}
|
|
7191
|
+
function resolveTransformHandler(plugin) {
|
|
7192
|
+
const hook = plugin.transform;
|
|
7193
|
+
if (typeof hook === "function") return hook;
|
|
7194
|
+
if (hook && typeof hook === "object" && typeof hook.handler === "function") return hook.handler;
|
|
7195
|
+
}
|
|
7196
|
+
/**
|
|
7197
|
+
* 在框架的 CSS post hook 持久化样式前完成转换,保证 watch 重放缓存时不会重新输出原始 CSS。
|
|
7198
|
+
*/
|
|
7199
|
+
function wrapViteCssPostTransform(config, transformCss) {
|
|
7200
|
+
const plugin = config.plugins?.find((candidate) => candidate.name === "vite:css-post");
|
|
7201
|
+
if (!plugin || wrappedCssPostPlugins.has(plugin)) return false;
|
|
7202
|
+
const originalHandler = resolveTransformHandler(plugin);
|
|
7203
|
+
if (!originalHandler) return false;
|
|
7204
|
+
const wrappedHandler = async function(code, id, ...args) {
|
|
7205
|
+
const transformedCss = await transformCss(code, id);
|
|
7206
|
+
return originalHandler.call(this, transformedCss, id, ...args);
|
|
7207
|
+
};
|
|
7208
|
+
const originalHook = plugin.transform;
|
|
7209
|
+
plugin.transform = originalHook && typeof originalHook === "object" ? {
|
|
7210
|
+
...originalHook,
|
|
7211
|
+
handler: wrappedHandler
|
|
7212
|
+
} : wrappedHandler;
|
|
7213
|
+
wrappedCssPostPlugins.add(plugin);
|
|
7214
|
+
return true;
|
|
7215
|
+
}
|
|
7216
|
+
//#endregion
|
|
6842
7217
|
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
6843
7218
|
const debug = createDebug();
|
|
6844
7219
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
@@ -6971,6 +7346,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6971
7346
|
cssEntries: opts.cssEntries ?? rawOptions.cssEntries
|
|
6972
7347
|
});
|
|
6973
7348
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
7349
|
+
const frameworkRootImportShellTargetByFile = /* @__PURE__ */ new Map();
|
|
6974
7350
|
const transientAutoCssSources = /* @__PURE__ */ new Map();
|
|
6975
7351
|
let refreshRuntimeStateForAutoCssSources;
|
|
6976
7352
|
let autoCssSourcesRefresh;
|
|
@@ -7047,7 +7423,21 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7047
7423
|
};
|
|
7048
7424
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
7049
7425
|
let recordedGeneratorCandidates;
|
|
7050
|
-
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
7426
|
+
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
7427
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
7428
|
+
customAttributesEntities,
|
|
7429
|
+
disabledDefaultTemplateHandler
|
|
7430
|
+
});
|
|
7431
|
+
const originalCssLayerSourceByFile = new LRUCache({ max: 128 });
|
|
7432
|
+
const rememberOriginalCssLayerSource = (id, code) => {
|
|
7433
|
+
const file = cleanUrl(id);
|
|
7434
|
+
if (!isCSSRequest(file)) return;
|
|
7435
|
+
if (!hasUserCssLayerBlocks(code)) {
|
|
7436
|
+
originalCssLayerSourceByFile.delete(file);
|
|
7437
|
+
return;
|
|
7438
|
+
}
|
|
7439
|
+
originalCssLayerSourceByFile.set(file, splitUserCssLayerBlocks(code).layer);
|
|
7440
|
+
};
|
|
7051
7441
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
7052
7442
|
let sourceScanEntries;
|
|
7053
7443
|
let sourceScanMatcher;
|
|
@@ -7433,12 +7823,23 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7433
7823
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
7434
7824
|
moduleGraph: void 0
|
|
7435
7825
|
});
|
|
7826
|
+
const shouldAdaptFrameworkWatchCss = () => {
|
|
7827
|
+
const platform = resolveViteStylePlatform();
|
|
7828
|
+
return shouldAdaptFrameworkWatchCssBeforeCache({
|
|
7829
|
+
enabled: frameworkBranch.adaptWatchCssBeforeFrameworkCache === true,
|
|
7830
|
+
ownsTailwindGeneration: shouldOwnTailwindGeneration,
|
|
7831
|
+
isWatchBuild: isWatchBuild(),
|
|
7832
|
+
isWebGeneratorBranch: resolveCurrentGeneratorBranch().isWeb,
|
|
7833
|
+
platform
|
|
7834
|
+
});
|
|
7835
|
+
};
|
|
7436
7836
|
const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
|
|
7437
7837
|
if (!shouldOwnTailwindGeneration) return;
|
|
7438
7838
|
await runtimeState.readyPromise;
|
|
7439
7839
|
await waitForSourceCandidateSyncs();
|
|
7440
7840
|
const file = cleanUrl(id);
|
|
7441
|
-
const
|
|
7841
|
+
const inferredSfcStyleRequest = isSfcStyleSourceFile(file) ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : file;
|
|
7842
|
+
const requestFile = isCSSRequest(id) ? inferredSfcStyleRequest === file ? id : inferredSfcStyleRequest : inferredSfcStyleRequest;
|
|
7442
7843
|
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
7443
7844
|
const generatorCode = normalizeEmptyTailwindCustomVariants(code);
|
|
7444
7845
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
@@ -7457,6 +7858,34 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7457
7858
|
const pendingHmrChange = resolvePendingHmrCandidateChange(generatorCode, file);
|
|
7458
7859
|
const forceFullHmrCssRegeneration = pendingFullHmrCssRegeneration || resolvedConfig?.command === "serve" && pendingHmrCandidateChange !== void 0 && pendingHmrChange === void 0;
|
|
7459
7860
|
const runtime = fullRuntime;
|
|
7861
|
+
const importShellCss = resolveViteServeRootMiniProgramImportShell({
|
|
7862
|
+
css: generatorTransformCode,
|
|
7863
|
+
cssPipelineContext,
|
|
7864
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
7865
|
+
isWebGeneratorTarget: currentGeneratorBranch.isWeb,
|
|
7866
|
+
outputFile
|
|
7867
|
+
});
|
|
7868
|
+
if (importShellCss !== void 0) {
|
|
7869
|
+
cleanGeneratedCssByFile.set(fileKey, importShellCss);
|
|
7870
|
+
tracedGeneratedCssByFile.set(fileKey, importShellCss);
|
|
7871
|
+
generatedClassSetByFile.set(fileKey, /* @__PURE__ */ new Set());
|
|
7872
|
+
recordViteProcessedCssAssetResult(file, importShellCss, {
|
|
7873
|
+
injectIntoMain: false,
|
|
7874
|
+
outputFile
|
|
7875
|
+
});
|
|
7876
|
+
markViteProcessedCssSource(file);
|
|
7877
|
+
rememberTailwindRootCssModule(id);
|
|
7878
|
+
recordGeneratorCandidates(fullRuntime);
|
|
7879
|
+
if (pendingHmrChange) finishPendingHmrCssTargetFile(file);
|
|
7880
|
+
else if (!pendingHmrCandidateChange) clearPendingHmrCandidateChange();
|
|
7881
|
+
cssMemory.rememberCssSource({
|
|
7882
|
+
outputFile,
|
|
7883
|
+
rawSource: code,
|
|
7884
|
+
sourceFile: requestFile
|
|
7885
|
+
});
|
|
7886
|
+
debug("css preserved root mini-program import shell for vite postcss pipeline: %s bytes=%d", requestFile, importShellCss.length);
|
|
7887
|
+
return importShellCss;
|
|
7888
|
+
}
|
|
7460
7889
|
if (pendingHmrChange && currentGeneratorOptions.target === "weapp" && filterUnsupportedMiniProgramTailwindV4Candidates(pendingHmrChange.addedCandidates).size === 0) {
|
|
7461
7890
|
const previousTracedCss = tracedGeneratedCssByFile.get(fileKey);
|
|
7462
7891
|
if (previousTracedCss !== void 0) {
|
|
@@ -7480,7 +7909,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7480
7909
|
cssHandlerOptions,
|
|
7481
7910
|
generatorCode: generatorTransformCode
|
|
7482
7911
|
}) ?? true);
|
|
7483
|
-
const
|
|
7912
|
+
const previousCss = pendingHmrChange && !forceFullHmrCssRegeneration ? cleanGeneratedCssByFile.get(fileKey) : void 0;
|
|
7913
|
+
const previousGeneratorCss = previousCss && !currentGeneratorBranch.isWeb ? normalizeMiniProgramGeneratorCssSource(previousCss, outputFile) : previousCss;
|
|
7914
|
+
const generated = await hmrTimingRecorder.measure(`generateCss.${resolvedConfig?.command ?? "unknown"}`, () => generateTailwindV4Css({
|
|
7484
7915
|
opts,
|
|
7485
7916
|
runtimeState,
|
|
7486
7917
|
runtime,
|
|
@@ -7494,7 +7925,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7494
7925
|
generatorPlatform: resolveGeneratorPlatform(),
|
|
7495
7926
|
styleHandler,
|
|
7496
7927
|
debug,
|
|
7928
|
+
previousCss: previousGeneratorCss,
|
|
7929
|
+
previousClassSet: pendingHmrChange && !forceFullHmrCssRegeneration ? generatedClassSetByFile.get(fileKey) : void 0,
|
|
7497
7930
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
7931
|
+
deferCssAdaptation: !currentGeneratorBranch.isWeb && !shouldAdaptFrameworkWatchCss(),
|
|
7498
7932
|
disableSourceScan: false,
|
|
7499
7933
|
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
7500
7934
|
}), {
|
|
@@ -7570,7 +8004,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7570
8004
|
weappTailwindcssDirPosix
|
|
7571
8005
|
});
|
|
7572
8006
|
if (disabledOptions.plugin) return rewritePlugins.length ? rewritePlugins : void 0;
|
|
7573
|
-
const
|
|
8007
|
+
const generateBundleContext = {
|
|
7574
8008
|
opts,
|
|
7575
8009
|
runtimeState,
|
|
7576
8010
|
ensureRuntimeClassSet,
|
|
@@ -7587,6 +8021,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7587
8021
|
getSourceCandidates,
|
|
7588
8022
|
getSourceCandidateSource: (file) => sourceCandidateCollector.source(file),
|
|
7589
8023
|
getSourceCandidateSources: () => sourceCandidateCollector.sources(),
|
|
8024
|
+
extractSourceCandidates: (file, source) => extractCandidatesFromSource(source, path.extname(cleanUrl(file)).slice(1) || "html", {
|
|
8025
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
8026
|
+
customAttributesEntities,
|
|
8027
|
+
disabledDefaultTemplateHandler
|
|
8028
|
+
}),
|
|
7590
8029
|
getSourceCandidatesForEntries,
|
|
7591
8030
|
getSourceCandidateSourcesForEntries,
|
|
7592
8031
|
waitForSourceCandidateSyncs,
|
|
@@ -7597,11 +8036,23 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7597
8036
|
setRememberedCssSignature: cssMemory.setRememberedCssSignature,
|
|
7598
8037
|
getKnownCssSource: cssMemory.getKnownCssSource,
|
|
7599
8038
|
getKnownSfcSource: cssMemory.getKnownSfcSource,
|
|
8039
|
+
getOriginalCssLayerSource: (file) => originalCssLayerSourceByFile.get(cleanUrl(file)),
|
|
7600
8040
|
recordGeneratorCandidates,
|
|
7601
8041
|
pruneViteCssCaches,
|
|
7602
8042
|
getViteCssCacheStats,
|
|
7603
8043
|
hmrTimingRecorder,
|
|
7604
|
-
cssPipelineStrategy: frameworkCssPipelineStrategy
|
|
8044
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
8045
|
+
frameworkRootImportShellTargetByFile
|
|
8046
|
+
};
|
|
8047
|
+
const shouldSplitGenerateBundlePhases = () => opts.appType === "weapp-vite" && getResolvedConfig()?.mode !== "production";
|
|
8048
|
+
const preGenerateBundleHook = createGenerateBundleHook({
|
|
8049
|
+
...generateBundleContext,
|
|
8050
|
+
processMarkupAndScripts: false,
|
|
8051
|
+
shouldProcessBundle: shouldSplitGenerateBundlePhases
|
|
8052
|
+
});
|
|
8053
|
+
const generateBundleHook = createGenerateBundleHook({
|
|
8054
|
+
...generateBundleContext,
|
|
8055
|
+
shouldProcessStyles: () => !shouldSplitGenerateBundlePhases()
|
|
7605
8056
|
});
|
|
7606
8057
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
7607
8058
|
opts,
|
|
@@ -7621,6 +8072,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7621
8072
|
getSourceCandidatesForEntries,
|
|
7622
8073
|
getSourceCandidateSourcesForEntries,
|
|
7623
8074
|
waitForSourceCandidateSyncs,
|
|
8075
|
+
frameworkRootImportShellTargetByFile,
|
|
7624
8076
|
rememberMainCssSource: (file, rawSource) => cssMemory.rememberCssSource({
|
|
7625
8077
|
outputFile: file,
|
|
7626
8078
|
rawSource,
|
|
@@ -7647,6 +8099,21 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7647
8099
|
styleHandler,
|
|
7648
8100
|
uniAppX
|
|
7649
8101
|
}) ?? [];
|
|
8102
|
+
const installFrameworkWatchCssCacheAdapter = async (config) => {
|
|
8103
|
+
if (!shouldAdaptFrameworkWatchCss()) return;
|
|
8104
|
+
if (wrapViteCssPostTransform(config, async (css, id) => {
|
|
8105
|
+
if (!isCSSRequest(id)) return css;
|
|
8106
|
+
if (hasBundlerGeneratedCssMarker(css)) {
|
|
8107
|
+
debug("preserve adapted generated css before uni-app watch cache: %s", id);
|
|
8108
|
+
return css;
|
|
8109
|
+
}
|
|
8110
|
+
const file = cleanUrl(id);
|
|
8111
|
+
const styleRequest = isSfcStyleSourceFile(file) ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), css, id) : id;
|
|
8112
|
+
const transformedCss = (await styleHandler(css, transformCssHandlerOptions.getCssHandlerOptions(styleRequest))).css;
|
|
8113
|
+
debug("adapt css before uni-app watch cache: %s inputRaw=%s outputRaw=%s", id, css.includes("\\[") || css.includes("\\:"), transformedCss.includes("\\[") || transformedCss.includes("\\:"));
|
|
8114
|
+
return transformedCss;
|
|
8115
|
+
})) debug("adapt uni-app watch css before vite:css-post cache");
|
|
8116
|
+
};
|
|
7650
8117
|
const plugins = [
|
|
7651
8118
|
...rewritePlugins,
|
|
7652
8119
|
{
|
|
@@ -7656,6 +8123,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7656
8123
|
if (!shouldOwnTailwindGeneration || isWebOrNativeAppPlatform(resolveViteStylePlatform()) || !isCSSRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
|
|
7657
8124
|
const rawCode = await readFile(cleanUrl(id), "utf8").catch(() => void 0);
|
|
7658
8125
|
if (typeof rawCode !== "string") return;
|
|
8126
|
+
rememberOriginalCssLayerSource(id, rawCode);
|
|
7659
8127
|
const transformedCode = transformEarlyMiniProgramCss(rawCode);
|
|
7660
8128
|
if (transformedCode === rawCode) return;
|
|
7661
8129
|
cssMemory.rememberKnownSfcSource(id, transformedCode);
|
|
@@ -7664,6 +8132,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7664
8132
|
transform: {
|
|
7665
8133
|
order: "pre",
|
|
7666
8134
|
async handler(code, id) {
|
|
8135
|
+
if (hasUserCssLayerBlocks(code)) rememberOriginalCssLayerSource(id, code);
|
|
7667
8136
|
let transformedCode = code;
|
|
7668
8137
|
if (shouldOwnTailwindGeneration && !resolveCurrentGeneratorBranch().isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
|
|
7669
8138
|
const shouldReturnTransformedCode = transformedCode !== code;
|
|
@@ -7719,6 +8188,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7719
8188
|
}
|
|
7720
8189
|
const canReadHotSource = typeof ctx.read === "function";
|
|
7721
8190
|
const hotSource = isSourceCandidateHotUpdate && canReadHotSource ? await ctx.read().catch(() => void 0) : void 0;
|
|
8191
|
+
if (typeof hotSource === "string" && isCSSRequest(ctx.file)) rememberOriginalCssLayerSource(ctx.file, hotSource);
|
|
7722
8192
|
const sourceCandidateChange = await syncChangedSourceCandidateFile(ctx.file, hotSource);
|
|
7723
8193
|
const isWebLikeHotUpdate = isCurrentWebLikeStylePlatform();
|
|
7724
8194
|
let canUseHmrCandidateAppend = false;
|
|
@@ -7762,13 +8232,15 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7762
8232
|
await hmrTimingRecorder.measure("sourceCandidates.buildStart", async () => {
|
|
7763
8233
|
await prepareTailwindGeneration();
|
|
7764
8234
|
}, { emit: false });
|
|
7765
|
-
}
|
|
8235
|
+
},
|
|
8236
|
+
generateBundle: preGenerateBundleHook
|
|
7766
8237
|
},
|
|
7767
|
-
...
|
|
8238
|
+
...createViteCssGenerationPlugins({
|
|
7768
8239
|
generateCss: generateTailwindCssForVitePipeline,
|
|
7769
8240
|
getCommand: () => resolvedConfig?.command,
|
|
7770
8241
|
onTailwindRootCss: registerTailwindRootCss,
|
|
7771
|
-
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
8242
|
+
shouldGenerate: () => shouldOwnTailwindGeneration,
|
|
8243
|
+
shouldGenerateBuild: () => resolveCurrentGeneratorBranch().isWeb
|
|
7772
8244
|
}),
|
|
7773
8245
|
createViteServeJsTransformPlugin({
|
|
7774
8246
|
createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
@@ -7780,6 +8252,13 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7780
8252
|
shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
|
|
7781
8253
|
transformRuntime: ensureRuntimeClassSet
|
|
7782
8254
|
}),
|
|
8255
|
+
{
|
|
8256
|
+
name: `${vitePluginName}:watch-css-cache`,
|
|
8257
|
+
configResolved: {
|
|
8258
|
+
order: "post",
|
|
8259
|
+
handler: installFrameworkWatchCssCacheAdapter
|
|
8260
|
+
}
|
|
8261
|
+
},
|
|
7783
8262
|
{
|
|
7784
8263
|
name: `${vitePluginName}:post`,
|
|
7785
8264
|
enforce: "post",
|
|
@@ -7787,7 +8266,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7787
8266
|
if (!shouldOwnTailwindGeneration) return;
|
|
7788
8267
|
if (Array.isArray(config.plugins)) {
|
|
7789
8268
|
const removed = disableAndRemoveTailwindVitePlugins(config.plugins);
|
|
7790
|
-
if (removed > 0)
|
|
8269
|
+
if (removed > 0) {
|
|
8270
|
+
logger.warn("检测到 @tailwindcss/vite,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
8271
|
+
debug("disable official tailwind vite plugins in generator mode: %d", removed);
|
|
8272
|
+
}
|
|
7791
8273
|
}
|
|
7792
8274
|
const root = config.root ? path.resolve(config.root) : process$1.cwd();
|
|
7793
8275
|
const baseConfig = { resolve: { alias: [{
|
|
@@ -7841,7 +8323,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7841
8323
|
const postcssPlugins = config.css.postcss.plugins;
|
|
7842
8324
|
if (shouldOwnTailwindGeneration) {
|
|
7843
8325
|
const removed = removeTailwindPostcssPlugins(postcssPlugins);
|
|
7844
|
-
if (removed > 0)
|
|
8326
|
+
if (removed > 0) {
|
|
8327
|
+
logger.warn("检测到 @tailwindcss/postcss,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
8328
|
+
debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
8329
|
+
}
|
|
7845
8330
|
}
|
|
7846
8331
|
}
|
|
7847
8332
|
}, { emit: false });
|
|
@@ -7966,6 +8451,7 @@ const uniAppCssPipelineStrategy = {
|
|
|
7966
8451
|
function createUniAppVitePlugins(options = {}) {
|
|
7967
8452
|
return createViteFrameworkPlugins(options, {
|
|
7968
8453
|
frameworkName: "uni-app",
|
|
8454
|
+
adaptWatchCssBeforeFrameworkCache: true,
|
|
7969
8455
|
cssPipelineStrategy: uniAppCssPipelineStrategy,
|
|
7970
8456
|
styleInjectorDelegate: viteStyleInjectorDelegates.uniApp
|
|
7971
8457
|
});
|
|
@@ -8091,6 +8577,7 @@ const uniAppXCssPipelineStrategy = {
|
|
|
8091
8577
|
function createUniAppXVitePlugins(options = {}) {
|
|
8092
8578
|
return createViteFrameworkPlugins(options, {
|
|
8093
8579
|
frameworkName: "uni-app-x",
|
|
8580
|
+
adaptWatchCssBeforeFrameworkCache: true,
|
|
8094
8581
|
cssPipelineStrategy: uniAppXCssPipelineStrategy,
|
|
8095
8582
|
getExtraPluginPlatform: () => ({ isIosPlatform: resolveUniUtsPlatform().isAppIos }),
|
|
8096
8583
|
styleInjectorDelegate: viteStyleInjectorDelegates.uniApp,
|