weapp-tailwindcss 5.1.7 → 5.1.9
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/bundlers/framework-selector.d.ts +26 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +6 -0
- package/dist/bundlers/gulp/index.d.ts +4 -4
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +6 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/generic/index.d.ts +2 -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/frameworks/weapp-vite/index.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +2 -2
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
- package/dist/bundlers/vite/index.d.ts +2 -4
- package/dist/bundlers/vite/processed-css-assets.d.ts +5 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +35 -0
- package/dist/bundlers/vite/shared/framework-strategy.d.ts +88 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -2
- package/dist/bundlers/webpack/frameworks/generic/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/index.d.ts +8 -0
- package/dist/bundlers/webpack/frameworks/mpx/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/taro/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/uni-app/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/weapp-vite/index.d.ts +5 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +21 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +4 -3
- package/dist/cli.js +8 -0
- package/dist/cli.mjs +8 -0
- package/dist/{context-C7KTDlrG.js → context-CRhUs_5e.js} +11 -3
- package/dist/{context-BqeDu1Ha.mjs → context-CfXr3hWz.mjs} +11 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-DASZwC6t.js → generator-DaaFxR5V.js} +1 -1
- package/dist/{generator-BOt2Tvx3.mjs → generator-DugIHBgl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-alDZryyB.mjs → gulp-CRjkPsbX.mjs} +22 -7
- package/dist/{gulp-D6hsaTLM.js → gulp-JUfnhOOo.js} +22 -7
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-CYwVMRol.mjs → hmr-timing-BecOXMd8.mjs} +5 -5
- package/dist/{hmr-timing-BIr_CiPW.js → hmr-timing-DcIEXnf8.js} +5 -5
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-Djr2Hw8y.js → source-candidate-scan-signature-10tvdJVC.js} +185 -98
- package/dist/{source-candidate-scan-signature-D97ZEXcj.mjs → source-candidate-scan-signature-DAg8QSgh.mjs} +162 -99
- package/dist/style-injector/internal.d.ts +18 -4
- package/dist/{tailwindcss-DPxJpRVP.js → tailwindcss-BZjZZi60.js} +1 -1
- package/dist/{tailwindcss-DDGD90w7.mjs → tailwindcss-PA2jHHpx.mjs} +1 -1
- package/dist/{transform-CvqqZBuq.js → transform-B0BxX3XB.js} +1 -1
- package/dist/{transform-DPPr79r2.mjs → transform-wNEbcZeQ.mjs} +1 -1
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v4-engine-3UmJkAY7.js → v4-engine-BZP2462H.js} +12 -0
- package/dist/{v4-engine-CYSrDVNp.mjs → v4-engine-CjjWONB0.mjs} +12 -0
- package/dist/{vite-BJRlG835.js → vite-CHk7V9EA.js} +1358 -848
- package/dist/{vite-XxJh7Xtu.mjs → vite-ClpyoD9e.mjs} +1357 -847
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +21 -1
- package/dist/{webpack-eN8WzIT-.mjs → webpack-2s-TFhgm.mjs} +321 -216
- package/dist/{webpack-BxBOMUtY.js → webpack-BhM4Hqla.js} +320 -215
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,47 +1,23 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import { $ as hasTailwindGeneratedCssMarkers, B as hasTailwindNonRootGenerationDirectives, Et as omitUndefined, G as normalizeTailwindSourceForGenerator, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, P as hasMiniProgramCssSpecificityPlaceholders, R as hasLocalCssImport, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, d as normalizeCssEntries, f as findNearestPackageRoot, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, s as upsertTailwindV4CssSource, u as isTailwindV4CssEntry, w as normalizeEmptyTailwindCustomVariants, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-
|
|
3
|
-
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-
|
|
2
|
+
import { $ as hasTailwindGeneratedCssMarkers, B as hasTailwindNonRootGenerationDirectives, Et as omitUndefined, G as normalizeTailwindSourceForGenerator, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, P as hasMiniProgramCssSpecificityPlaceholders, R as hasLocalCssImport, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, d as normalizeCssEntries, f as findNearestPackageRoot, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, rt as stripGeneratorPlaceholderMarkers, s as upsertTailwindV4CssSource, u as isTailwindV4CssEntry, w as normalizeEmptyTailwindCustomVariants, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-CjjWONB0.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-DugIHBgl.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
5
|
-
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-
|
|
6
|
-
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-
|
|
7
|
-
import { E as createCssTokenSourceMap, O as processCachedTask, T as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, b as scoreTailwindV4CssSourceFileMatch, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder, w as annotateCssSourceTrace } from "./hmr-timing-
|
|
8
|
-
import { A as
|
|
5
|
+
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-CfXr3hWz.mjs";
|
|
6
|
+
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-PA2jHHpx.mjs";
|
|
7
|
+
import { E as createCssTokenSourceMap, O as processCachedTask, T as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, b as scoreTailwindV4CssSourceFileMatch, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder, w as annotateCssSourceTrace } from "./hmr-timing-BecOXMd8.mjs";
|
|
8
|
+
import { A as hasBundlerGeneratedCssMarker, C as generateTailwindV4Css, E as normalizeOutputPathKey, F as createBuiltinViteStyleInjectorPlugins, L as viteStyleInjectorDelegates, M as stripBundlerGeneratedCssMarkers, N as resolvePackageDir, O as toAbsoluteOutputPath, P as resolvePluginDisabledState, S as createBundleModuleGraphOptions, T as stripRequestQuery, _ as isHTMLRequest, a as createJsHashSalt, b as createRuntimeAffectingSourceSignature, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as isCSSRequest, h as formatPostcssSourceMap, i as createCandidateSignature, j as parseBundlerGeneratedCssMarkerBlocks, k as createBundlerGeneratedCssMarker, l as summarizeStringDiff, m as cleanUrl, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as normalizePath, w as isSourceStyleRequest, x as applyLinkedResults, y as slash, z as resolveViteFrameworkProfile } from "./source-candidate-scan-signature-DAg8QSgh.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
10
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
13
13
|
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
|
-
import { compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
14
|
+
import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolveFilteredPostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
15
15
|
import { LRUCache } from "lru-cache";
|
|
16
16
|
import { readFile } from "node:fs/promises";
|
|
17
17
|
import micromatch from "micromatch";
|
|
18
18
|
import { Buffer } from "node:buffer";
|
|
19
19
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
20
20
|
import { parse } from "comment-json";
|
|
21
|
-
//#region src/uni-app-x/harmony.ts
|
|
22
|
-
function isUniAppXHarmonyOutDir(outDir) {
|
|
23
|
-
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/bundlers/vite/query.ts
|
|
27
|
-
function parseVueRequest(id) {
|
|
28
|
-
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
29
|
-
const searchParams = new URLSearchParams(rawQuery);
|
|
30
|
-
const query = Object.fromEntries(searchParams);
|
|
31
|
-
if (query.vue != null) query.vue = true;
|
|
32
|
-
if (query.index != null) query.index = Number(query.index);
|
|
33
|
-
if (query.raw != null) query.raw = true;
|
|
34
|
-
if (query.url != null) query.url = true;
|
|
35
|
-
if (query.scoped != null) query.scoped = true;
|
|
36
|
-
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
37
|
-
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
38
|
-
if (langType) query.lang = langType;
|
|
39
|
-
return {
|
|
40
|
-
filename,
|
|
41
|
-
query
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
21
|
//#region src/uni-app-x/style-asset/style-value.ts
|
|
46
22
|
const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/;
|
|
47
23
|
const STYLE_ENTRY_RE = /\[\s*("((?:\\.|[^"\\])+)")\s*,\s*(_pS\(_uM\(\[[\s\S]*?\]\)\))\s*\]/g;
|
|
@@ -488,488 +464,170 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
|
488
464
|
};
|
|
489
465
|
}
|
|
490
466
|
//#endregion
|
|
491
|
-
//#region src/
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
467
|
+
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
468
|
+
function collectConfiguredTailwindV4CssSources(opts) {
|
|
469
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
470
|
+
return filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
471
|
+
}
|
|
472
|
+
function collectExplicitTailwindV4CssEntries(opts) {
|
|
473
|
+
const entries = [
|
|
474
|
+
...opts.cssEntries ?? [],
|
|
475
|
+
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
476
|
+
...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
477
|
+
];
|
|
478
|
+
return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
|
|
479
|
+
}
|
|
480
|
+
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
481
|
+
const entries = [];
|
|
482
|
+
const seen = /* @__PURE__ */ new Set();
|
|
483
|
+
const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
|
|
484
|
+
for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
|
|
485
|
+
if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
|
|
486
|
+
const resolvedFile = path.isAbsolute(cssEntry) ? path.resolve(cssEntry) : path.resolve(fallbackBase, cssEntry);
|
|
487
|
+
if (!existsSync(resolvedFile)) continue;
|
|
488
|
+
const source = readFileSync(resolvedFile, "utf8");
|
|
489
|
+
const key = `${resolvedFile}\0${source}`;
|
|
490
|
+
if (seen.has(key)) continue;
|
|
491
|
+
seen.add(key);
|
|
492
|
+
entries.push({
|
|
493
|
+
file: resolvedFile,
|
|
494
|
+
source
|
|
495
|
+
});
|
|
504
496
|
}
|
|
505
|
-
|
|
506
|
-
|
|
497
|
+
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
498
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
499
|
+
const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
500
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : path.join(base, "tailwind.css");
|
|
501
|
+
const resolvedFile = path.isAbsolute(file) ? path.resolve(file) : path.resolve(base, file);
|
|
502
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
503
|
+
if (seen.has(key)) continue;
|
|
504
|
+
seen.add(key);
|
|
505
|
+
entries.push({
|
|
506
|
+
file: resolvedFile,
|
|
507
|
+
source: cssSource.css
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
return entries;
|
|
507
511
|
}
|
|
508
512
|
//#endregion
|
|
509
|
-
//#region src/
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
513
|
+
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
514
|
+
function createReplayCssAsset(fileName, source) {
|
|
515
|
+
return {
|
|
516
|
+
type: "asset",
|
|
517
|
+
fileName,
|
|
518
|
+
name: void 0,
|
|
519
|
+
source,
|
|
520
|
+
needsCodeReference: false,
|
|
521
|
+
names: [],
|
|
522
|
+
originalFileName: null,
|
|
523
|
+
originalFileNames: []
|
|
524
|
+
};
|
|
514
525
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
"
|
|
518
|
-
"less",
|
|
519
|
-
"styl",
|
|
520
|
-
"stylus"
|
|
521
|
-
]);
|
|
522
|
-
const INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
523
|
-
const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
524
|
-
const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
525
|
-
const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
526
|
-
const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
|
|
527
|
-
function isPreprocessorRequest(id, lang) {
|
|
528
|
-
const normalizedLang = lang?.toLowerCase();
|
|
529
|
-
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
530
|
-
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
531
|
-
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
532
|
-
return PREPROCESSOR_EXT_RE.test(id);
|
|
526
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
527
|
+
const candidate = error;
|
|
528
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
533
529
|
}
|
|
534
|
-
function
|
|
535
|
-
|
|
530
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
531
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
532
|
+
for (const dependency of dependencies ?? []) try {
|
|
533
|
+
ctx.addWatchFile(dependency);
|
|
534
|
+
} catch (error) {
|
|
535
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
536
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
536
541
|
}
|
|
537
|
-
|
|
538
|
-
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
544
|
+
function createCssAssetEmitter(context) {
|
|
545
|
+
return (fileName, source) => {
|
|
546
|
+
if (context.emitFile) {
|
|
547
|
+
context.emitFile({
|
|
548
|
+
type: "asset",
|
|
549
|
+
fileName,
|
|
550
|
+
source
|
|
551
|
+
});
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
return createReplayCssAsset(fileName, source);
|
|
555
|
+
};
|
|
539
556
|
}
|
|
540
|
-
function
|
|
541
|
-
return
|
|
557
|
+
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
558
|
+
return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
|
|
542
559
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
562
|
+
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
563
|
+
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
564
|
+
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
565
|
+
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
566
|
+
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
567
|
+
".wxss",
|
|
568
|
+
".acss",
|
|
569
|
+
".ttss",
|
|
570
|
+
".qss",
|
|
571
|
+
".jxss",
|
|
572
|
+
".tyss"
|
|
573
|
+
];
|
|
574
|
+
function resolveCssOutputRealPath(value) {
|
|
575
|
+
const resolved = path.resolve(value);
|
|
576
|
+
let current = resolved;
|
|
577
|
+
const pendingSegments = [];
|
|
578
|
+
while (!existsSync(current)) {
|
|
579
|
+
const parent = path.dirname(current);
|
|
580
|
+
if (parent === current) return resolved;
|
|
581
|
+
pendingSegments.unshift(path.basename(current));
|
|
582
|
+
current = parent;
|
|
560
583
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
567
|
-
componentLocalStyleEnabled = true;
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
|
|
571
|
-
const root = getResolvedConfig()?.root;
|
|
572
|
-
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
573
|
-
return componentLocalStyleEnabled;
|
|
584
|
+
try {
|
|
585
|
+
const realPath = realpathSync.native(current);
|
|
586
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
587
|
+
} catch {
|
|
588
|
+
return resolved;
|
|
574
589
|
}
|
|
575
|
-
|
|
576
|
-
|
|
590
|
+
}
|
|
591
|
+
function normalizeStyleOutputExtension(value) {
|
|
592
|
+
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
593
|
+
const normalized = value.trim().toLowerCase();
|
|
594
|
+
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
595
|
+
}
|
|
596
|
+
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
597
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
598
|
+
if (!cssMatcher?.(cleanFile)) return;
|
|
599
|
+
const ext = path.extname(cleanFile);
|
|
600
|
+
if (!ext || ext === ".css") return;
|
|
601
|
+
return ext;
|
|
602
|
+
}
|
|
603
|
+
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
604
|
+
let extension;
|
|
605
|
+
for (const file of files ?? []) {
|
|
606
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
607
|
+
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
608
|
+
if (!matchedExtension) continue;
|
|
609
|
+
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
610
|
+
if (extension && extension !== matchedExtension) return;
|
|
611
|
+
extension = matchedExtension;
|
|
577
612
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
597
|
-
postcssOptions: { options: {
|
|
598
|
-
from: id,
|
|
599
|
-
map: {
|
|
600
|
-
inline: false,
|
|
601
|
-
annotation: false,
|
|
602
|
-
sourcesContent: true
|
|
603
|
-
}
|
|
604
|
-
} }
|
|
605
|
-
});
|
|
606
|
-
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
607
|
-
}
|
|
608
|
-
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
609
|
-
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
610
|
-
for (const warning of warnings) logger$1.warn(warning.toString());
|
|
611
|
-
const postcssMap = await formatPostcssSourceMap(postcssResult.map.toJSON(), normalizePath(cleanUrl(id)));
|
|
612
|
-
return {
|
|
613
|
-
code: postcssResult.css,
|
|
614
|
-
map: postcssMap
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
const cssPlugins = [{
|
|
619
|
-
name: "weapp-tailwindcss:uni-app-x:css",
|
|
620
|
-
async transform(code, id) {
|
|
621
|
-
await runtimeState.readyPromise;
|
|
622
|
-
return transformStyle(code, id, void 0, this);
|
|
623
|
-
}
|
|
624
|
-
}, {
|
|
625
|
-
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
626
|
-
enforce: "pre",
|
|
627
|
-
async transform(code, id) {
|
|
628
|
-
await runtimeState.readyPromise;
|
|
629
|
-
const { query } = parseVueRequest(id);
|
|
630
|
-
const lang = query.lang;
|
|
631
|
-
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
632
|
-
return transformStyle(code, id, query, this);
|
|
633
|
-
}
|
|
634
|
-
}];
|
|
635
|
-
const nvuePlugin = {
|
|
636
|
-
name: "weapp-tailwindcss:uni-app-x:nvue",
|
|
637
|
-
enforce: "pre",
|
|
638
|
-
async buildStart() {
|
|
639
|
-
await ensureRuntimeClassSet(true);
|
|
640
|
-
},
|
|
641
|
-
async transform(code, id) {
|
|
642
|
-
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
643
|
-
rememberHarmonyApplySource(code);
|
|
644
|
-
const resolvedConfig = getResolvedConfig();
|
|
645
|
-
const isServeCommand = resolvedConfig?.command === "serve";
|
|
646
|
-
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
647
|
-
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
648
|
-
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
649
|
-
const transformUVue = await loadTransformUVue();
|
|
650
|
-
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
651
|
-
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
652
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, omitUndefined({
|
|
653
|
-
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
654
|
-
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
655
|
-
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
656
|
-
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
657
|
-
}));
|
|
658
|
-
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
659
|
-
},
|
|
660
|
-
async handleHotUpdate(ctx) {
|
|
661
|
-
if (getResolvedConfig()?.command !== "serve") return;
|
|
662
|
-
if (!UVUE_NVUE_RE.test(ctx.file)) return;
|
|
663
|
-
await ensureRuntimeClassSet(true);
|
|
664
|
-
},
|
|
665
|
-
async watchChange(id) {
|
|
666
|
-
const resolvedConfig = getResolvedConfig();
|
|
667
|
-
if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
|
|
668
|
-
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
669
|
-
await ensureRuntimeClassSet(true);
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
const stylePlaceholderPlugin = {
|
|
673
|
-
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
674
|
-
enforce: "post",
|
|
675
|
-
generateBundle: {
|
|
676
|
-
order: "post",
|
|
677
|
-
async handler(_options, bundle) {
|
|
678
|
-
const currentUtsPlatform = resolveUniUtsPlatform();
|
|
679
|
-
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
680
|
-
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
681
|
-
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
682
|
-
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
683
|
-
if (isHarmonyTarget) {
|
|
684
|
-
const cssSources = [];
|
|
685
|
-
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
686
|
-
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
687
|
-
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
688
|
-
const harmonyApplyCssFile = path.resolve(getResolvedConfig()?.root ?? process$1.cwd(), "uni-app-x-harmony-apply.css");
|
|
689
|
-
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
690
|
-
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
691
|
-
}
|
|
692
|
-
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
693
|
-
cssSources,
|
|
694
|
-
excludeComponents: shouldEnableComponentLocalStyle()
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
for (const [file, item] of Object.entries(bundle)) {
|
|
698
|
-
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
699
|
-
const currentSource = String(item.source);
|
|
700
|
-
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
701
|
-
if (nextSource !== currentSource) item.source = nextSource;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
return [
|
|
707
|
-
...cssPlugins,
|
|
708
|
-
nvuePlugin,
|
|
709
|
-
stylePlaceholderPlugin
|
|
710
|
-
];
|
|
711
|
-
}
|
|
712
|
-
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
713
|
-
return async () => {
|
|
714
|
-
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
715
|
-
const absoluteFile = toAbsoluteOutputPath(file, outDir);
|
|
716
|
-
const rawSource = originalSource.source.toString();
|
|
717
|
-
await processCachedTask({
|
|
718
|
-
cache,
|
|
719
|
-
cacheKey: file,
|
|
720
|
-
hashKey,
|
|
721
|
-
rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
|
|
722
|
-
applyResult(source) {
|
|
723
|
-
originalSource.source = source;
|
|
724
|
-
},
|
|
725
|
-
onCacheHit() {
|
|
726
|
-
debug("js cache hit: %s", file);
|
|
727
|
-
},
|
|
728
|
-
async transform() {
|
|
729
|
-
const currentSource = originalSource.source.toString();
|
|
730
|
-
const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
|
|
731
|
-
uniAppX: resolveUniAppXJsTransformEnabled$1(options.uniAppX),
|
|
732
|
-
babelParserOptions: {
|
|
733
|
-
plugins: ["typescript"],
|
|
734
|
-
sourceType: "unambiguous"
|
|
735
|
-
}
|
|
736
|
-
}));
|
|
737
|
-
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
738
|
-
onUpdate(file, currentSource, nextCode);
|
|
739
|
-
debug("js handle: %s", file);
|
|
740
|
-
applyLinkedResults(linked);
|
|
741
|
-
return { result: nextCode };
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
747
|
-
"uni-ad-draw",
|
|
748
|
-
"uni-ad-fullscreen-video",
|
|
749
|
-
"uni-ad-interactive",
|
|
750
|
-
"uni-ad-interstitial",
|
|
751
|
-
"uni-ad-rewarded-video",
|
|
752
|
-
"uni-ad",
|
|
753
|
-
"uni-animation-view",
|
|
754
|
-
"uni-audio",
|
|
755
|
-
"uni-block",
|
|
756
|
-
"uni-button",
|
|
757
|
-
"uni-camera",
|
|
758
|
-
"uni-canvas",
|
|
759
|
-
"uni-checkbox-group",
|
|
760
|
-
"uni-checkbox",
|
|
761
|
-
"uni-cover-image",
|
|
762
|
-
"uni-cover-view",
|
|
763
|
-
"uni-custom-tab-bar",
|
|
764
|
-
"uni-editor",
|
|
765
|
-
"uni-form",
|
|
766
|
-
"uni-icon",
|
|
767
|
-
"uni-image",
|
|
768
|
-
"uni-input",
|
|
769
|
-
"uni-label",
|
|
770
|
-
"uni-list-item",
|
|
771
|
-
"uni-list-view",
|
|
772
|
-
"uni-live-player",
|
|
773
|
-
"uni-live-pusher",
|
|
774
|
-
"uni-map",
|
|
775
|
-
"uni-match-media",
|
|
776
|
-
"uni-movable-area",
|
|
777
|
-
"uni-movable-view",
|
|
778
|
-
"uni-navigation-bar",
|
|
779
|
-
"uni-navigator",
|
|
780
|
-
"uni-open-data",
|
|
781
|
-
"uni-page-meta",
|
|
782
|
-
"uni-picker-view",
|
|
783
|
-
"uni-picker",
|
|
784
|
-
"uni-progress",
|
|
785
|
-
"uni-radio-group",
|
|
786
|
-
"uni-radio",
|
|
787
|
-
"uni-rich-text",
|
|
788
|
-
"uni-scroll-view",
|
|
789
|
-
"uni-slider",
|
|
790
|
-
"uni-sticky-header",
|
|
791
|
-
"uni-sticky-section",
|
|
792
|
-
"uni-swiper-item",
|
|
793
|
-
"uni-swiper",
|
|
794
|
-
"uni-switch",
|
|
795
|
-
"uni-template",
|
|
796
|
-
"uni-text",
|
|
797
|
-
"uni-textarea",
|
|
798
|
-
"uni-unicloud-db",
|
|
799
|
-
"uni-video",
|
|
800
|
-
"uni-view",
|
|
801
|
-
"uni-web-view"
|
|
802
|
-
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
803
|
-
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
804
|
-
function withUniAppXWebPreflightReset(css, enabled) {
|
|
805
|
-
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
806
|
-
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
807
|
-
}
|
|
808
|
-
//#endregion
|
|
809
|
-
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
810
|
-
function collectConfiguredTailwindV4CssSources(opts) {
|
|
811
|
-
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
812
|
-
return filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
813
|
-
}
|
|
814
|
-
function collectExplicitTailwindV4CssEntries(opts) {
|
|
815
|
-
const entries = [
|
|
816
|
-
...opts.cssEntries ?? [],
|
|
817
|
-
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
818
|
-
...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
819
|
-
];
|
|
820
|
-
return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
|
|
821
|
-
}
|
|
822
|
-
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
823
|
-
const entries = [];
|
|
824
|
-
const seen = /* @__PURE__ */ new Set();
|
|
825
|
-
const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
|
|
826
|
-
for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
|
|
827
|
-
if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
|
|
828
|
-
const resolvedFile = path.isAbsolute(cssEntry) ? path.resolve(cssEntry) : path.resolve(fallbackBase, cssEntry);
|
|
829
|
-
if (!existsSync(resolvedFile)) continue;
|
|
830
|
-
const source = readFileSync(resolvedFile, "utf8");
|
|
831
|
-
const key = `${resolvedFile}\0${source}`;
|
|
832
|
-
if (seen.has(key)) continue;
|
|
833
|
-
seen.add(key);
|
|
834
|
-
entries.push({
|
|
835
|
-
file: resolvedFile,
|
|
836
|
-
source
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
840
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
841
|
-
const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
842
|
-
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : path.join(base, "tailwind.css");
|
|
843
|
-
const resolvedFile = path.isAbsolute(file) ? path.resolve(file) : path.resolve(base, file);
|
|
844
|
-
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
845
|
-
if (seen.has(key)) continue;
|
|
846
|
-
seen.add(key);
|
|
847
|
-
entries.push({
|
|
848
|
-
file: resolvedFile,
|
|
849
|
-
source: cssSource.css
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
return entries;
|
|
853
|
-
}
|
|
854
|
-
//#endregion
|
|
855
|
-
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
856
|
-
function createReplayCssAsset(fileName, source) {
|
|
857
|
-
return {
|
|
858
|
-
type: "asset",
|
|
859
|
-
fileName,
|
|
860
|
-
name: void 0,
|
|
861
|
-
source,
|
|
862
|
-
needsCodeReference: false,
|
|
863
|
-
names: [],
|
|
864
|
-
originalFileName: null,
|
|
865
|
-
originalFileNames: []
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
869
|
-
const candidate = error;
|
|
870
|
-
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
871
|
-
}
|
|
872
|
-
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
873
|
-
if (typeof ctx.addWatchFile !== "function") return;
|
|
874
|
-
for (const dependency of dependencies ?? []) try {
|
|
875
|
-
ctx.addWatchFile(dependency);
|
|
876
|
-
} catch (error) {
|
|
877
|
-
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
878
|
-
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
879
|
-
continue;
|
|
880
|
-
}
|
|
881
|
-
throw error;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
//#endregion
|
|
885
|
-
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
886
|
-
function createCssAssetEmitter(context) {
|
|
887
|
-
return (fileName, source) => {
|
|
888
|
-
if (context.emitFile) {
|
|
889
|
-
context.emitFile({
|
|
890
|
-
type: "asset",
|
|
891
|
-
fileName,
|
|
892
|
-
source
|
|
893
|
-
});
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
return createReplayCssAsset(fileName, source);
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
900
|
-
return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
|
|
901
|
-
}
|
|
902
|
-
//#endregion
|
|
903
|
-
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
904
|
-
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
905
|
-
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
906
|
-
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
907
|
-
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
908
|
-
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
909
|
-
".wxss",
|
|
910
|
-
".acss",
|
|
911
|
-
".ttss",
|
|
912
|
-
".qss",
|
|
913
|
-
".jxss",
|
|
914
|
-
".tyss"
|
|
915
|
-
];
|
|
916
|
-
function resolveCssOutputRealPath(value) {
|
|
917
|
-
const resolved = path.resolve(value);
|
|
918
|
-
let current = resolved;
|
|
919
|
-
const pendingSegments = [];
|
|
920
|
-
while (!existsSync(current)) {
|
|
921
|
-
const parent = path.dirname(current);
|
|
922
|
-
if (parent === current) return resolved;
|
|
923
|
-
pendingSegments.unshift(path.basename(current));
|
|
924
|
-
current = parent;
|
|
925
|
-
}
|
|
926
|
-
try {
|
|
927
|
-
const realPath = realpathSync.native(current);
|
|
928
|
-
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
929
|
-
} catch {
|
|
930
|
-
return resolved;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
function normalizeStyleOutputExtension(value) {
|
|
934
|
-
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
935
|
-
const normalized = value.trim().toLowerCase();
|
|
936
|
-
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
937
|
-
}
|
|
938
|
-
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
939
|
-
const cleanFile = file.replace(/[?#].*$/, "");
|
|
940
|
-
if (!cssMatcher?.(cleanFile)) return;
|
|
941
|
-
const ext = path.extname(cleanFile);
|
|
942
|
-
if (!ext || ext === ".css") return;
|
|
943
|
-
return ext;
|
|
944
|
-
}
|
|
945
|
-
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
946
|
-
let extension;
|
|
947
|
-
for (const file of files ?? []) {
|
|
948
|
-
const cleanFile = file.replace(/[?#].*$/, "");
|
|
949
|
-
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
950
|
-
if (!matchedExtension) continue;
|
|
951
|
-
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
952
|
-
if (extension && extension !== matchedExtension) return;
|
|
953
|
-
extension = matchedExtension;
|
|
954
|
-
}
|
|
955
|
-
return extension;
|
|
956
|
-
}
|
|
957
|
-
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
958
|
-
if (!cssMatcher || !stem) return;
|
|
959
|
-
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
960
|
-
}
|
|
961
|
-
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
962
|
-
const cleanStem = normalizeOutputPathKey(stem);
|
|
963
|
-
const stemSuffix = `/${cleanStem}`;
|
|
964
|
-
const matchedFiles = /* @__PURE__ */ new Set();
|
|
965
|
-
for (const file of files ?? []) {
|
|
966
|
-
const cleanFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
967
|
-
if (!cssMatcher?.(cleanFile)) continue;
|
|
968
|
-
const extension = path.extname(cleanFile);
|
|
969
|
-
if (!extension || extension === ".css") continue;
|
|
970
|
-
const outputStem = cleanFile.slice(0, -extension.length);
|
|
971
|
-
const outputStemSuffix = `/${outputStem}`;
|
|
972
|
-
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
613
|
+
return extension;
|
|
614
|
+
}
|
|
615
|
+
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
616
|
+
if (!cssMatcher || !stem) return;
|
|
617
|
+
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
618
|
+
}
|
|
619
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
620
|
+
const cleanStem = normalizeOutputPathKey(stem);
|
|
621
|
+
const stemSuffix = `/${cleanStem}`;
|
|
622
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
623
|
+
for (const file of files ?? []) {
|
|
624
|
+
const cleanFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
625
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
626
|
+
const extension = path.extname(cleanFile);
|
|
627
|
+
if (!extension || extension === ".css") continue;
|
|
628
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
629
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
630
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
973
631
|
}
|
|
974
632
|
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
975
633
|
}
|
|
@@ -1236,18 +894,21 @@ function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
|
1236
894
|
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
1237
895
|
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
1238
896
|
}
|
|
1239
|
-
function shouldKeepRootMiniProgramStyleAsImportShell(
|
|
1240
|
-
return
|
|
897
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(enabled) {
|
|
898
|
+
return enabled === true;
|
|
1241
899
|
}
|
|
1242
|
-
function shouldMoveRootMiniProgramStyleToImportShellOrigin(
|
|
1243
|
-
return
|
|
900
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(enabled) {
|
|
901
|
+
return enabled === true;
|
|
1244
902
|
}
|
|
1245
903
|
//#endregion
|
|
1246
904
|
//#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
|
|
1247
905
|
function resolveCssBundleOutputFile(options) {
|
|
1248
|
-
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
|
|
906
|
+
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, pipelineContext, cssPipelineStrategy, shouldPreserveAppCssExtension } = options;
|
|
1249
907
|
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
1250
|
-
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(
|
|
908
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
909
|
+
...pipelineContext,
|
|
910
|
+
file
|
|
911
|
+
}))) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
1251
912
|
return outputFile;
|
|
1252
913
|
}
|
|
1253
914
|
function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile = file, cssMatcher) {
|
|
@@ -1285,12 +946,16 @@ function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAsset
|
|
|
1285
946
|
return false;
|
|
1286
947
|
}
|
|
1287
948
|
function applyCssResultToBundle(options) {
|
|
1288
|
-
const {
|
|
949
|
+
const { assetSourceFile, bundle, cssPipelineStrategy, emitOrReplayCssAsset, file, originalSource, outputFile, pipelineContext, source, viteProcessedCssAsset } = options;
|
|
1289
950
|
if (outputFile === file) {
|
|
1290
951
|
originalSource.source = source;
|
|
1291
952
|
return;
|
|
1292
953
|
}
|
|
1293
|
-
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(
|
|
954
|
+
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
955
|
+
...pipelineContext,
|
|
956
|
+
css: source,
|
|
957
|
+
file
|
|
958
|
+
})) ? createCssImportShell$1(file, outputFile) : void 0;
|
|
1294
959
|
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
1295
960
|
const existingOutput = bundle[outputFile];
|
|
1296
961
|
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
@@ -1815,20 +1480,66 @@ const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
|
1815
1480
|
".svelte",
|
|
1816
1481
|
".mpx"
|
|
1817
1482
|
];
|
|
1818
|
-
const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]
|
|
1819
|
-
|
|
1483
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1484
|
+
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1485
|
+
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1486
|
+
function extractSfcStyleBlocks(source) {
|
|
1820
1487
|
const styleSources = [];
|
|
1821
1488
|
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1489
|
+
let index = 0;
|
|
1822
1490
|
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1823
1491
|
while (match !== null) {
|
|
1824
|
-
|
|
1492
|
+
const attrs = match[1] ?? "";
|
|
1493
|
+
styleSources.push({
|
|
1494
|
+
attrs,
|
|
1495
|
+
index,
|
|
1496
|
+
scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
|
|
1497
|
+
source: match[2] ?? ""
|
|
1498
|
+
});
|
|
1499
|
+
index += 1;
|
|
1825
1500
|
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1826
1501
|
}
|
|
1827
1502
|
return styleSources;
|
|
1828
1503
|
}
|
|
1504
|
+
function extractSfcStyleSources(source) {
|
|
1505
|
+
return extractSfcStyleBlocks(source).map((style) => style.source);
|
|
1506
|
+
}
|
|
1829
1507
|
function hasSfcStyleSources(source) {
|
|
1830
1508
|
return extractSfcStyleSources(source).length > 0;
|
|
1831
1509
|
}
|
|
1510
|
+
function resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks) {
|
|
1511
|
+
const scopedStyleBlock = styleBlocks.find((style) => style.scoped);
|
|
1512
|
+
return scopedStyleBlock ? `${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true` : sourceFile;
|
|
1513
|
+
}
|
|
1514
|
+
function normalizeSfcStyleSourceForCompare(source) {
|
|
1515
|
+
return source.replace(/\r\n?/g, "\n").trim();
|
|
1516
|
+
}
|
|
1517
|
+
function resolveSfcStyleBlockLang(attrs) {
|
|
1518
|
+
const match = SFC_LANG_STYLE_ATTR_RE.exec(attrs);
|
|
1519
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
1520
|
+
}
|
|
1521
|
+
function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
1522
|
+
const params = new URLSearchParams();
|
|
1523
|
+
params.set("vue", "");
|
|
1524
|
+
params.set("type", "style");
|
|
1525
|
+
params.set("index", String(styleBlock.index));
|
|
1526
|
+
if (styleBlock.scoped) params.set("scoped", "true");
|
|
1527
|
+
const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
|
|
1528
|
+
if (lang) params.set("lang", lang);
|
|
1529
|
+
return `${sourceFile}?${params.toString()}`;
|
|
1530
|
+
}
|
|
1531
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource) {
|
|
1532
|
+
if (!sfcSource) return sourceFile;
|
|
1533
|
+
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
1534
|
+
if (styleBlocks.length === 0) return sourceFile;
|
|
1535
|
+
const normalizedStyleSource = normalizeSfcStyleSourceForCompare(styleSource);
|
|
1536
|
+
const matchedBlocks = styleBlocks.filter((styleBlock) => {
|
|
1537
|
+
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
1538
|
+
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
1539
|
+
});
|
|
1540
|
+
const styleBlock = matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0;
|
|
1541
|
+
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1542
|
+
}
|
|
1832
1543
|
function hasTailwindGenerationSource(source, options = {}) {
|
|
1833
1544
|
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1834
1545
|
return hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
@@ -1848,7 +1559,8 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1848
1559
|
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1849
1560
|
return;
|
|
1850
1561
|
}
|
|
1851
|
-
const
|
|
1562
|
+
const styleBlocks = extractSfcStyleBlocks(source);
|
|
1563
|
+
const rawSource = styleBlocks.map((style) => style.source).join("\n");
|
|
1852
1564
|
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1853
1565
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1854
1566
|
return;
|
|
@@ -1857,7 +1569,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1857
1569
|
return {
|
|
1858
1570
|
outputFile,
|
|
1859
1571
|
rawSource,
|
|
1860
|
-
sourceFile
|
|
1572
|
+
sourceFile: resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks)
|
|
1861
1573
|
};
|
|
1862
1574
|
}
|
|
1863
1575
|
function normalizeSfcSourceFileForCompare(file) {
|
|
@@ -2059,6 +1771,13 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
2059
1771
|
//#endregion
|
|
2060
1772
|
//#region src/bundlers/vite/processed-css-assets.ts
|
|
2061
1773
|
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
1774
|
+
function createCssAssetPipelineContext(options, file, bundle) {
|
|
1775
|
+
const context = options.createCssPipelineContext?.(file);
|
|
1776
|
+
return context ? {
|
|
1777
|
+
...context,
|
|
1778
|
+
bundle
|
|
1779
|
+
} : void 0;
|
|
1780
|
+
}
|
|
2062
1781
|
function isCssOutputFile(file) {
|
|
2063
1782
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
2064
1783
|
}
|
|
@@ -2091,31 +1810,64 @@ function dedupeViteCssResults(records) {
|
|
|
2091
1810
|
return true;
|
|
2092
1811
|
});
|
|
2093
1812
|
}
|
|
2094
|
-
function
|
|
2095
|
-
|
|
1813
|
+
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
1814
|
+
let changed = false;
|
|
1815
|
+
root.walkAtRules("media", (atRule) => {
|
|
1816
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
1817
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
1818
|
+
else atRule.remove();
|
|
1819
|
+
changed = true;
|
|
1820
|
+
});
|
|
1821
|
+
if (changed) root.walkAtRules((atRule) => {
|
|
1822
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
1823
|
+
});
|
|
1824
|
+
return changed;
|
|
1825
|
+
}
|
|
1826
|
+
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
1827
|
+
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
1828
|
+
}
|
|
1829
|
+
function removeTailwindEntryDirectivesFromCss(css) {
|
|
2096
1830
|
try {
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
1831
|
+
const source = stripGeneratorPlaceholderMarkers(css);
|
|
1832
|
+
const root = postcss.parse(source);
|
|
1833
|
+
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
1834
|
+
const removedTailwindDirectives = removeTailwindSourceDirectivesRoot(root);
|
|
1835
|
+
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
1836
|
+
} catch {
|
|
1837
|
+
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
1841
|
+
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
1842
|
+
return css.split(/\r?\n/).filter((line) => {
|
|
1843
|
+
const trimmed = line.trim();
|
|
1844
|
+
if (!trimmed.startsWith("@import")) return true;
|
|
1845
|
+
const request = parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
1846
|
+
return request === void 0 || isMiniProgramLocalCssImportRequest(request);
|
|
1847
|
+
}).join("\n");
|
|
1848
|
+
}
|
|
1849
|
+
function normalizeInjectableCssForTarget(css, file) {
|
|
1850
|
+
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
1851
|
+
}
|
|
1852
|
+
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
1853
|
+
if (!css.includes("@import")) return {
|
|
1854
|
+
css,
|
|
1855
|
+
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
1856
|
+
};
|
|
1857
|
+
try {
|
|
1858
|
+
const root = postcss.parse(css);
|
|
1859
|
+
return {
|
|
1860
|
+
css: (isMiniProgramStyleOutputFile(file) ? removeUnsupportedMiniProgramCssImportsRoot(root) : false) ? root.toString() : css,
|
|
1861
|
+
importedStyleFiles: collectImportedStyleFilesRoot(root, file)
|
|
1862
|
+
};
|
|
2112
1863
|
} catch {
|
|
2113
|
-
|
|
1864
|
+
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
1865
|
+
return {
|
|
1866
|
+
css: fallbackCss,
|
|
1867
|
+
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
1868
|
+
};
|
|
2114
1869
|
}
|
|
2115
1870
|
}
|
|
2116
|
-
function removeTailwindEntryDirectivesFromCss(css) {
|
|
2117
|
-
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappers(css));
|
|
2118
|
-
}
|
|
2119
1871
|
function stripStyleExtension(file) {
|
|
2120
1872
|
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
2121
1873
|
}
|
|
@@ -2129,15 +1881,23 @@ function resolveImportedStyleFile(targetFile, request) {
|
|
|
2129
1881
|
const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
2130
1882
|
return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2131
1883
|
}
|
|
2132
|
-
function
|
|
1884
|
+
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
2133
1885
|
const imports = /* @__PURE__ */ new Set();
|
|
1886
|
+
for (const request of requests) {
|
|
1887
|
+
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
1888
|
+
if (importedFile) imports.add(importedFile);
|
|
1889
|
+
}
|
|
1890
|
+
return imports;
|
|
1891
|
+
}
|
|
1892
|
+
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
1893
|
+
return collectImportedStyleFilesFromRequests(collectCssImportRequestsRoot(root), targetFile);
|
|
1894
|
+
}
|
|
1895
|
+
function collectImportedStyleFiles(css, targetFile) {
|
|
1896
|
+
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
2134
1897
|
try {
|
|
2135
|
-
postcss.parse(css)
|
|
2136
|
-
const importedFile = resolveImportedStyleFile(targetFile, parseImportRequest(atRule.params));
|
|
2137
|
-
if (importedFile) imports.add(importedFile);
|
|
2138
|
-
});
|
|
1898
|
+
return collectImportedStyleFilesRoot(postcss.parse(css), targetFile);
|
|
2139
1899
|
} catch {}
|
|
2140
|
-
return
|
|
1900
|
+
return /* @__PURE__ */ new Set();
|
|
2141
1901
|
}
|
|
2142
1902
|
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
2143
1903
|
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
@@ -2233,14 +1993,17 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
|
|
|
2233
1993
|
return removed;
|
|
2234
1994
|
}
|
|
2235
1995
|
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
1996
|
+
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
2236
1997
|
function hasVueScopedAttr(value) {
|
|
2237
1998
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2238
|
-
|
|
1999
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
2000
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
|
|
2239
2001
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2002
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
2240
2003
|
return matched;
|
|
2241
2004
|
}
|
|
2242
2005
|
function normalizeCssSignatureValue(value) {
|
|
2243
|
-
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
2006
|
+
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(VUE_SCOPED_CLASS_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
2244
2007
|
}
|
|
2245
2008
|
function createDeclarationSignature(rule) {
|
|
2246
2009
|
return createDeclarationKeys(rule).sort().join(";");
|
|
@@ -2267,6 +2030,33 @@ function isLikelyTailwindGlobalRule(rule) {
|
|
|
2267
2030
|
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
2268
2031
|
return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
2269
2032
|
}
|
|
2033
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
2034
|
+
"view",
|
|
2035
|
+
"text",
|
|
2036
|
+
"::after",
|
|
2037
|
+
"::before"
|
|
2038
|
+
]);
|
|
2039
|
+
const MINI_PROGRAM_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
2040
|
+
"box-sizing",
|
|
2041
|
+
"margin",
|
|
2042
|
+
"padding",
|
|
2043
|
+
"border"
|
|
2044
|
+
]);
|
|
2045
|
+
function isMiniProgramTailwindPreflightDeclaration(decl) {
|
|
2046
|
+
return decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop);
|
|
2047
|
+
}
|
|
2048
|
+
function isUnscopedMiniProgramTailwindPreflightRule(rule) {
|
|
2049
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2050
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
2051
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2052
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
2053
|
+
})) return false;
|
|
2054
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2055
|
+
return declarations.length > 0 && declarations.every(isMiniProgramTailwindPreflightDeclaration);
|
|
2056
|
+
}
|
|
2057
|
+
function hasUnscopedMiniProgramTailwindPreflightRule(css) {
|
|
2058
|
+
return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
|
|
2059
|
+
}
|
|
2270
2060
|
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2271
2061
|
const rules = /* @__PURE__ */ new Set();
|
|
2272
2062
|
const atRules = /* @__PURE__ */ new Set();
|
|
@@ -2308,8 +2098,9 @@ function isRuleCoveredByRootCss(rule, coverage) {
|
|
|
2308
2098
|
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2309
2099
|
if (!hasVueScopedAttr(css)) return css;
|
|
2310
2100
|
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2101
|
+
const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
|
|
2311
2102
|
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2312
|
-
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
|
|
2103
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight) return css;
|
|
2313
2104
|
try {
|
|
2314
2105
|
const root = postcss.parse(css);
|
|
2315
2106
|
let changed = false;
|
|
@@ -2320,7 +2111,7 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
|
2320
2111
|
}
|
|
2321
2112
|
});
|
|
2322
2113
|
root.walkRules((rule) => {
|
|
2323
|
-
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
|
|
2114
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule)) {
|
|
2324
2115
|
rule.remove();
|
|
2325
2116
|
changed = true;
|
|
2326
2117
|
}
|
|
@@ -2419,11 +2210,17 @@ function isRootStyleOutputFile(file) {
|
|
|
2419
2210
|
function isMiniProgramStyleOutputFile(file) {
|
|
2420
2211
|
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2421
2212
|
}
|
|
2422
|
-
function shouldPreserveMiniProgramImportShell(
|
|
2423
|
-
|
|
2213
|
+
function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
|
|
2214
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2215
|
+
return context !== void 0 && options.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
2216
|
+
...context,
|
|
2217
|
+
css,
|
|
2218
|
+
file
|
|
2219
|
+
}) === true && isMiniProgramStyleOutputFile(file) && options.opts.cssMatcher(file) && isPureLocalCssImportWrapper(css);
|
|
2424
2220
|
}
|
|
2425
|
-
function resolvePreservedImportShellInjectionTarget(
|
|
2426
|
-
|
|
2221
|
+
function resolvePreservedImportShellInjectionTarget(options, bundle, file, css) {
|
|
2222
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2223
|
+
if (context === void 0 || options.cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(context) !== true) return;
|
|
2427
2224
|
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2428
2225
|
if (importedStyleFiles.size !== 1) return;
|
|
2429
2226
|
const [importedFile] = importedStyleFiles;
|
|
@@ -2435,15 +2232,25 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
|
2435
2232
|
if (normalizeOutputPathKey(outputFile) === normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2436
2233
|
}
|
|
2437
2234
|
}
|
|
2438
|
-
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
2235
|
+
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bundle) {
|
|
2236
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2439
2237
|
const fileKey = normalizeOutputPathKey(file);
|
|
2440
2238
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2441
2239
|
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
2442
2240
|
const matchedRootWebOutputTargets = records.map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile)).filter((outputFile) => opts.mainCssChunkMatcher(outputFile, opts.appType));
|
|
2443
|
-
if (
|
|
2241
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferMatchedRootWebOutputTarget?.({
|
|
2242
|
+
...context,
|
|
2243
|
+
file,
|
|
2244
|
+
matchedRootWebOutputTargets
|
|
2245
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2444
2246
|
const explicitRootTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2445
2247
|
const explicitWebCssTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isCssOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2446
|
-
if (
|
|
2248
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferExplicitWebCssTargets?.({
|
|
2249
|
+
...context,
|
|
2250
|
+
explicitRootTargets,
|
|
2251
|
+
explicitWebCssTargets,
|
|
2252
|
+
file
|
|
2253
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2447
2254
|
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2448
2255
|
if (records.some((record) => {
|
|
2449
2256
|
if (record.injectIntoMain !== true) return false;
|
|
@@ -2483,7 +2290,7 @@ function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, record
|
|
|
2483
2290
|
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
|
|
2484
2291
|
if (!isRecordFile && !isProcessedSource) continue;
|
|
2485
2292
|
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2486
|
-
if (candidateIsRootWebStyle && !isRecordFile) continue;
|
|
2293
|
+
if (candidateIsRootWebStyle && !isRecordFile && !isProcessedSource) continue;
|
|
2487
2294
|
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2488
2295
|
else clearAssetSource(candidateOutput);
|
|
2489
2296
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
@@ -2535,8 +2342,22 @@ function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
|
2535
2342
|
const fileKey = normalizeComparableStyleFile(file);
|
|
2536
2343
|
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2537
2344
|
}
|
|
2538
|
-
function
|
|
2539
|
-
|
|
2345
|
+
function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
|
|
2346
|
+
const opts = options.opts;
|
|
2347
|
+
if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2348
|
+
const context = createCssAssetPipelineContext(options, outputFile, bundle);
|
|
2349
|
+
if (context === void 0) return;
|
|
2350
|
+
const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
2351
|
+
...context,
|
|
2352
|
+
bundle,
|
|
2353
|
+
isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
|
|
2354
|
+
isMiniProgramStyleOutputFile,
|
|
2355
|
+
isRootStyleOutputFile,
|
|
2356
|
+
outputFile,
|
|
2357
|
+
sourceFile
|
|
2358
|
+
});
|
|
2359
|
+
if (resolvedByStrategy !== void 0) return resolvedByStrategy;
|
|
2360
|
+
if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
|
|
2540
2361
|
const rootCssFiles = [];
|
|
2541
2362
|
const matchedRootCssFiles = [];
|
|
2542
2363
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -2603,7 +2424,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2603
2424
|
options.markCssAssetProcessed?.(output, file);
|
|
2604
2425
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2605
2426
|
const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
|
|
2606
|
-
const webviewRootCssInjectionTarget = options.opts ?
|
|
2427
|
+
const webviewRootCssInjectionTarget = options.opts ? resolveConfiguredCssEntryRootInjectionTarget(bundle, options, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
|
|
2607
2428
|
const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
|
|
2608
2429
|
if (singleMarkerFile && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(normalizeOutputPathKey(resolvedOutputFile))) {
|
|
2609
2430
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
@@ -2678,10 +2499,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2678
2499
|
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2679
2500
|
if (output.type !== "asset") continue;
|
|
2680
2501
|
let file = getAssetFile$1(bundleFile, output);
|
|
2681
|
-
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2502
|
+
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults, options, bundle)) continue;
|
|
2682
2503
|
let originalSource = readAssetSource$2(output);
|
|
2683
|
-
if (shouldPreserveMiniProgramImportShell(options
|
|
2684
|
-
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options
|
|
2504
|
+
if (shouldPreserveMiniProgramImportShell(options, bundle, file, originalSource)) {
|
|
2505
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options, bundle, file, originalSource);
|
|
2685
2506
|
if (typeof importedTargetFile === "string") {
|
|
2686
2507
|
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2687
2508
|
const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === normalizeOutputPathKey(importedTargetFile))?.[1];
|
|
@@ -2697,8 +2518,9 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2697
2518
|
}
|
|
2698
2519
|
const fileKey = normalizeOutputPathKey(file);
|
|
2699
2520
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2700
|
-
|
|
2701
|
-
|
|
2521
|
+
const normalizedOriginalCss = normalizeInjectableCssForTargetWithImports(transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file), file);
|
|
2522
|
+
let nextCss = normalizedOriginalCss.css;
|
|
2523
|
+
const importedStyleFiles = normalizedOriginalCss.importedStyleFiles;
|
|
2702
2524
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2703
2525
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2704
2526
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
@@ -2714,7 +2536,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2714
2536
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2715
2537
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2716
2538
|
targetViteCssResults.push(record);
|
|
2717
|
-
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2539
|
+
let css = normalizeInjectableCssForTarget(stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim();
|
|
2718
2540
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2719
2541
|
if (css.length === 0) continue;
|
|
2720
2542
|
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
@@ -3028,17 +2850,10 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
3028
2850
|
function readAssetSource(asset) {
|
|
3029
2851
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
3030
2852
|
}
|
|
3031
|
-
function isUniAppViteWebviewAppBundle(bundleFiles) {
|
|
3032
|
-
return bundleFiles.some((file) => path.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
3033
|
-
}
|
|
3034
|
-
function isUniAppViteWebviewOutDir$2(outDir) {
|
|
3035
|
-
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
3036
|
-
return normalized === "app" || normalized === "app-plus";
|
|
3037
|
-
}
|
|
3038
2853
|
function getAssetFile(bundleFile, asset) {
|
|
3039
2854
|
return asset.fileName || bundleFile;
|
|
3040
2855
|
}
|
|
3041
|
-
function
|
|
2856
|
+
function finalizeWebviewCssCompat(bundle, options) {
|
|
3042
2857
|
if (options.opts.generator?.webCompat === false) return 0;
|
|
3043
2858
|
let transformed = 0;
|
|
3044
2859
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -3051,7 +2866,7 @@ function finalizeUniAppViteWebviewCssCompat(bundle, options) {
|
|
|
3051
2866
|
output.source = nextCss;
|
|
3052
2867
|
options.recordCssAssetResult?.(file, nextCss);
|
|
3053
2868
|
options.onUpdate(file, rawSource, nextCss);
|
|
3054
|
-
options.debug("finalize
|
|
2869
|
+
options.debug("finalize webview css compat: %s bytes=%d", file, nextCss.length);
|
|
3055
2870
|
transformed++;
|
|
3056
2871
|
}
|
|
3057
2872
|
return transformed;
|
|
@@ -3092,8 +2907,8 @@ function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
|
3092
2907
|
} catch {}
|
|
3093
2908
|
return importedFile;
|
|
3094
2909
|
}
|
|
3095
|
-
function
|
|
3096
|
-
if (options.
|
|
2910
|
+
function normalizeRootMiniProgramImportShellAssets(bundle, options) {
|
|
2911
|
+
if (!options.enabled) return 0;
|
|
3097
2912
|
let updated = 0;
|
|
3098
2913
|
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
3099
2914
|
if (rootOutput.type !== "asset") continue;
|
|
@@ -3104,6 +2919,17 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3104
2919
|
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && normalizeOutputPathKey(getAssetFile(bundleFile, output)) === normalizeOutputPathKey(originFile))?.[1];
|
|
3105
2920
|
if (originOutput?.type !== "asset") continue;
|
|
3106
2921
|
const rootSource = readAssetSource(rootOutput);
|
|
2922
|
+
const importedRootFile = resolveSingleCssImportOutputFile(rootFile, rootSource);
|
|
2923
|
+
if (importedRootFile && normalizeOutputPathKey(importedRootFile) === normalizeOutputPathKey(originFile)) {
|
|
2924
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2925
|
+
if (rootSource === nextRootSource) continue;
|
|
2926
|
+
rootOutput.source = nextRootSource;
|
|
2927
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2928
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2929
|
+
options.debug("normalize root css import shell request: %s -> %s", rootFile, originFile);
|
|
2930
|
+
updated++;
|
|
2931
|
+
continue;
|
|
2932
|
+
}
|
|
3107
2933
|
if (isPureLocalCssImportWrapper(rootSource)) continue;
|
|
3108
2934
|
const originSource = readAssetSource(originOutput);
|
|
3109
2935
|
if (isPureLocalCssImportWrapper(originSource)) {
|
|
@@ -3118,13 +2944,13 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3118
2944
|
options.recordCssAssetResult?.(originFile, rootSource);
|
|
3119
2945
|
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
3120
2946
|
options.onUpdate?.(originFile, originSource, rootSource);
|
|
3121
|
-
options.debug("normalize
|
|
2947
|
+
options.debug("normalize root css import shell: %s -> %s", rootFile, originFile);
|
|
3122
2948
|
updated++;
|
|
3123
2949
|
}
|
|
3124
2950
|
return updated;
|
|
3125
2951
|
}
|
|
3126
2952
|
async function finalizeGenerateBundle(options) {
|
|
3127
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
|
|
2953
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, cssPipelineStrategy, createCssPipelineContext, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
|
|
3128
2954
|
const tasksStart = performance.now();
|
|
3129
2955
|
if (cssTaskFactories.length > 0) {
|
|
3130
2956
|
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -3153,6 +2979,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3153
2979
|
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
3154
2980
|
collectViteProcessedCssAssetResults(bundle, {
|
|
3155
2981
|
opts,
|
|
2982
|
+
cssPipelineStrategy,
|
|
2983
|
+
createCssPipelineContext,
|
|
3156
2984
|
isViteProcessedCssAsset,
|
|
3157
2985
|
markCssAssetProcessed,
|
|
3158
2986
|
recordCssAssetResult,
|
|
@@ -3164,6 +2992,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3164
2992
|
});
|
|
3165
2993
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3166
2994
|
opts,
|
|
2995
|
+
cssPipelineStrategy,
|
|
2996
|
+
createCssPipelineContext,
|
|
3167
2997
|
getViteProcessedCssAssetResults,
|
|
3168
2998
|
markCssAssetProcessed,
|
|
3169
2999
|
recordCssAssetResult,
|
|
@@ -3182,10 +3012,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3182
3012
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
3183
3013
|
syncViteProcessedCssIntoMainCssAssets();
|
|
3184
3014
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3015
|
+
const createFinalizeCssPipelineContext = (file = "") => createCssPipelineContext?.(file);
|
|
3016
|
+
const finalizeCssPipelineContext = createFinalizeCssPipelineContext();
|
|
3017
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
3187
3018
|
cssMatcher: opts.cssMatcher,
|
|
3188
3019
|
debug,
|
|
3020
|
+
enabled: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(finalizeCssPipelineContext) === true,
|
|
3189
3021
|
onUpdate,
|
|
3190
3022
|
recordCssAssetResult
|
|
3191
3023
|
});
|
|
@@ -3193,13 +3025,23 @@ async function finalizeGenerateBundle(options) {
|
|
|
3193
3025
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
3194
3026
|
cssMatcher: opts.cssMatcher,
|
|
3195
3027
|
debug,
|
|
3196
|
-
includeTailwindGeneratedCssAssets:
|
|
3028
|
+
includeTailwindGeneratedCssAssets: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.includeTailwindGeneratedCssAssetsInRootCoverage?.({
|
|
3029
|
+
...finalizeCssPipelineContext,
|
|
3030
|
+
bundleFiles,
|
|
3031
|
+
isWebGeneratorTarget,
|
|
3032
|
+
outDir
|
|
3033
|
+
}) === true,
|
|
3197
3034
|
isViteProcessedCssAsset,
|
|
3198
3035
|
onUpdate,
|
|
3199
3036
|
recordCssAssetResult,
|
|
3200
3037
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
3201
3038
|
});
|
|
3202
|
-
if (
|
|
3039
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml?.({
|
|
3040
|
+
...finalizeCssPipelineContext,
|
|
3041
|
+
bundleFiles: Object.keys(bundle),
|
|
3042
|
+
isWebGeneratorTarget,
|
|
3043
|
+
outDir
|
|
3044
|
+
}) === true) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
3203
3045
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
3204
3046
|
cssMatcher: opts.cssMatcher,
|
|
3205
3047
|
debug,
|
|
@@ -3210,7 +3052,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3210
3052
|
recordCssAssetResult,
|
|
3211
3053
|
styleHandler
|
|
3212
3054
|
});
|
|
3213
|
-
if (
|
|
3055
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldApplyFinalWebviewCssCompat?.({
|
|
3056
|
+
...finalizeCssPipelineContext,
|
|
3057
|
+
bundleFiles: Object.keys(bundle),
|
|
3058
|
+
isWebGeneratorTarget,
|
|
3059
|
+
outDir
|
|
3060
|
+
}) === true) finalizeWebviewCssCompat(bundle, {
|
|
3214
3061
|
debug,
|
|
3215
3062
|
onUpdate,
|
|
3216
3063
|
opts,
|
|
@@ -3302,131 +3149,418 @@ function collectClassAttributeValues(source) {
|
|
|
3302
3149
|
break;
|
|
3303
3150
|
}
|
|
3304
3151
|
}
|
|
3305
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3152
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3153
|
+
}
|
|
3154
|
+
return values;
|
|
3155
|
+
}
|
|
3156
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
3157
|
+
const matches = /* @__PURE__ */ new Set();
|
|
3158
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
3159
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
3160
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
3161
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3162
|
+
while (quoted !== null) {
|
|
3163
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
3164
|
+
for (const candidate of splitCandidateTokens(literal)) {
|
|
3165
|
+
const normalized = candidate.trim();
|
|
3166
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
3167
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
3168
|
+
matches.add(normalized);
|
|
3169
|
+
}
|
|
3170
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
return [...matches];
|
|
3174
|
+
}
|
|
3175
|
+
//#endregion
|
|
3176
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
3177
|
+
function processHtmlBundleEntry(options) {
|
|
3178
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
3179
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
3180
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3181
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3182
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
3183
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3184
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3185
|
+
const hashKey = cacheKey;
|
|
3186
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3187
|
+
tasks.push(timeTask("html", () => processCachedTask({
|
|
3188
|
+
cache,
|
|
3189
|
+
cacheKey,
|
|
3190
|
+
hashKey,
|
|
3191
|
+
hash: htmlProcessHash,
|
|
3192
|
+
applyResult(source) {
|
|
3193
|
+
originalSource.source = source;
|
|
3194
|
+
},
|
|
3195
|
+
onCacheHit() {
|
|
3196
|
+
metrics.html.cacheHits++;
|
|
3197
|
+
debug("html cache hit: %s", file);
|
|
3198
|
+
},
|
|
3199
|
+
async transform() {
|
|
3200
|
+
const start = performance.now();
|
|
3201
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
3202
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3203
|
+
let retryRuntimeSet;
|
|
3204
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
3205
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
3206
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
3207
|
+
retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
3208
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
3209
|
+
}
|
|
3210
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
3211
|
+
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3212
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3213
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3214
|
+
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3215
|
+
}
|
|
3216
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
3217
|
+
metrics.html.transformed++;
|
|
3218
|
+
onUpdate(file, rawSource, transformed);
|
|
3219
|
+
debug("html handle: %s", file);
|
|
3220
|
+
return { result: transformed };
|
|
3221
|
+
}
|
|
3222
|
+
})));
|
|
3223
|
+
}
|
|
3224
|
+
//#endregion
|
|
3225
|
+
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
3226
|
+
function createJsEntryResolver(jsEntries) {
|
|
3227
|
+
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
3228
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(normalizeOutputPathKey(id), entry);
|
|
3229
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(normalizeOutputPathKey(id));
|
|
3230
|
+
}
|
|
3231
|
+
//#endregion
|
|
3232
|
+
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
3233
|
+
function resolveUniAppXJsTransformEnabled$1(uniAppX) {
|
|
3234
|
+
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
3235
|
+
}
|
|
3236
|
+
function createJsHandlerOptionsFactory(options) {
|
|
3237
|
+
return (absoluteFilename, extra) => ({
|
|
3238
|
+
...extra,
|
|
3239
|
+
generateMap: false,
|
|
3240
|
+
filename: absoluteFilename,
|
|
3241
|
+
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
3242
|
+
moduleGraph: options.moduleGraph,
|
|
3243
|
+
babelParserOptions: {
|
|
3244
|
+
...extra?.babelParserOptions ?? {},
|
|
3245
|
+
sourceFilename: absoluteFilename
|
|
3246
|
+
}
|
|
3247
|
+
});
|
|
3248
|
+
}
|
|
3249
|
+
//#endregion
|
|
3250
|
+
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
3251
|
+
function createLinkedUpdateHelpers(options) {
|
|
3252
|
+
const pendingLinkedUpdates = [];
|
|
3253
|
+
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
3254
|
+
options.onUpdate(fileName, previous, next);
|
|
3255
|
+
options.debug("js linked handle: %s", fileName);
|
|
3256
|
+
};
|
|
3257
|
+
const scheduleLinkedApply = (entry, code) => {
|
|
3258
|
+
pendingLinkedUpdates.push(() => {
|
|
3259
|
+
if (entry.output.type === "chunk") entry.output.code = code;
|
|
3260
|
+
else entry.output.source = code;
|
|
3261
|
+
});
|
|
3262
|
+
};
|
|
3263
|
+
const applyLinkedUpdates = (linked) => {
|
|
3264
|
+
applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
3265
|
+
};
|
|
3266
|
+
return {
|
|
3267
|
+
applyLinkedUpdates,
|
|
3268
|
+
pendingLinkedUpdates
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
3272
|
+
if (!linked || !linkedSet) return;
|
|
3273
|
+
for (const id of Object.keys(linked)) {
|
|
3274
|
+
const linkedEntry = getJsEntry(id);
|
|
3275
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
//#endregion
|
|
3279
|
+
//#region src/bundlers/vite/query.ts
|
|
3280
|
+
function parseVueRequest(id) {
|
|
3281
|
+
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
3282
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
3283
|
+
const query = Object.fromEntries(searchParams);
|
|
3284
|
+
if (query.vue != null) query.vue = true;
|
|
3285
|
+
if (query.index != null) query.index = Number(query.index);
|
|
3286
|
+
if (query.raw != null) query.raw = true;
|
|
3287
|
+
if (query.url != null) query.url = true;
|
|
3288
|
+
if (query.scoped != null) query.scoped = true;
|
|
3289
|
+
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
3290
|
+
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
3291
|
+
if (langType) query.lang = langType;
|
|
3292
|
+
return {
|
|
3293
|
+
filename,
|
|
3294
|
+
query
|
|
3295
|
+
};
|
|
3296
|
+
}
|
|
3297
|
+
//#endregion
|
|
3298
|
+
//#region src/uni-app-x/harmony.ts
|
|
3299
|
+
function isUniAppXHarmonyOutDir(outDir) {
|
|
3300
|
+
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
3301
|
+
}
|
|
3302
|
+
//#endregion
|
|
3303
|
+
//#region src/uni-app-x/style-isolation.ts
|
|
3304
|
+
const manifestCache = /* @__PURE__ */ new Map();
|
|
3305
|
+
function resolveUniAppXStyleIsolationEnabled(root) {
|
|
3306
|
+
if (!root) return false;
|
|
3307
|
+
const normalizedRoot = path.resolve(root);
|
|
3308
|
+
const cached = manifestCache.get(normalizedRoot);
|
|
3309
|
+
if (cached !== void 0) return cached;
|
|
3310
|
+
const manifestPath = path.join(normalizedRoot, "manifest.json");
|
|
3311
|
+
let enabled = false;
|
|
3312
|
+
try {
|
|
3313
|
+
enabled = `${parse(fs.readFileSync(manifestPath, "utf8"))["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
|
|
3314
|
+
} catch {
|
|
3315
|
+
enabled = false;
|
|
3316
|
+
}
|
|
3317
|
+
manifestCache.set(normalizedRoot, enabled);
|
|
3318
|
+
return enabled;
|
|
3319
|
+
}
|
|
3320
|
+
//#endregion
|
|
3321
|
+
//#region src/uni-app-x/vite.ts
|
|
3322
|
+
let transformUVuePromise;
|
|
3323
|
+
function loadTransformUVue() {
|
|
3324
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-wNEbcZeQ.mjs").then((mod) => mod.transformUVue));
|
|
3325
|
+
return transformUVuePromise;
|
|
3326
|
+
}
|
|
3327
|
+
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
3328
|
+
"scss",
|
|
3329
|
+
"sass",
|
|
3330
|
+
"less",
|
|
3331
|
+
"styl",
|
|
3332
|
+
"stylus"
|
|
3333
|
+
]);
|
|
3334
|
+
const INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
3335
|
+
const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
3336
|
+
const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
3337
|
+
const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
3338
|
+
const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
|
|
3339
|
+
function isPreprocessorRequest(id, lang) {
|
|
3340
|
+
const normalizedLang = lang?.toLowerCase();
|
|
3341
|
+
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
3342
|
+
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
3343
|
+
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
3344
|
+
return PREPROCESSOR_EXT_RE.test(id);
|
|
3345
|
+
}
|
|
3346
|
+
function resolveUniAppXCssTarget(id) {
|
|
3347
|
+
return UVUE_NVUE_RE.test(cleanUrl(id)) ? "uvue" : void 0;
|
|
3348
|
+
}
|
|
3349
|
+
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
3350
|
+
return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
|
|
3351
|
+
}
|
|
3352
|
+
function isCssModuleExport(code) {
|
|
3353
|
+
return CSS_MODULE_EXPORT_RE.test(code);
|
|
3354
|
+
}
|
|
3355
|
+
function createUniAppXPlugins(options) {
|
|
3356
|
+
const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX } = options;
|
|
3357
|
+
const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
|
|
3358
|
+
const utsPlatform = resolveUniUtsPlatform();
|
|
3359
|
+
const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
|
|
3360
|
+
const isHarmonyPlatform = utsPlatform.isAppHarmony;
|
|
3361
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
3362
|
+
let componentLocalStyleEnabled;
|
|
3363
|
+
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
3364
|
+
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
3365
|
+
function rememberHarmonyApplySource(code) {
|
|
3366
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
3367
|
+
if (styleSources.length === 0) return;
|
|
3368
|
+
for (const styleSource of styleSources) {
|
|
3369
|
+
harmonyApplyStyleSources.add(styleSource);
|
|
3370
|
+
for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
|
|
3371
|
+
}
|
|
3306
3372
|
}
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3373
|
+
function shouldEnableComponentLocalStyle() {
|
|
3374
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
|
|
3375
|
+
componentLocalStyleEnabled = false;
|
|
3376
|
+
return false;
|
|
3377
|
+
}
|
|
3378
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
3379
|
+
componentLocalStyleEnabled = true;
|
|
3380
|
+
return true;
|
|
3381
|
+
}
|
|
3382
|
+
if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
|
|
3383
|
+
const root = getResolvedConfig()?.root;
|
|
3384
|
+
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
3385
|
+
return componentLocalStyleEnabled;
|
|
3386
|
+
}
|
|
3387
|
+
function shouldEnableHarmonyPageLocalStyle() {
|
|
3388
|
+
return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
|
|
3389
|
+
}
|
|
3390
|
+
function isHarmonyBuildTarget() {
|
|
3391
|
+
if (resolveUniUtsPlatform().isAppHarmony) return true;
|
|
3392
|
+
return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
|
|
3393
|
+
}
|
|
3394
|
+
async function transformStyle(code, id, query, hookContext) {
|
|
3395
|
+
const parsed = query ?? parseVueRequest(id).query;
|
|
3396
|
+
if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
3397
|
+
if (isCssModuleExport(code)) return;
|
|
3398
|
+
const shouldGenerateCss = hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
3399
|
+
rememberHarmonyApplySource(code);
|
|
3400
|
+
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
3401
|
+
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
3402
|
+
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
3403
|
+
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
3404
|
+
if (!styleHandlerOptions) {
|
|
3405
|
+
styleHandlerOptions = omitUndefined({
|
|
3406
|
+
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
3407
|
+
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
3408
|
+
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
3409
|
+
postcssOptions: { options: {
|
|
3410
|
+
from: id,
|
|
3411
|
+
map: {
|
|
3412
|
+
inline: false,
|
|
3413
|
+
annotation: false,
|
|
3414
|
+
sourcesContent: true
|
|
3415
|
+
}
|
|
3416
|
+
} }
|
|
3417
|
+
});
|
|
3418
|
+
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
3322
3419
|
}
|
|
3323
|
-
|
|
3420
|
+
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
3421
|
+
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
3422
|
+
for (const warning of warnings) logger$1.warn(warning.toString());
|
|
3423
|
+
const postcssMap = await formatPostcssSourceMap(postcssResult.map.toJSON(), normalizePath(cleanUrl(id)));
|
|
3424
|
+
return {
|
|
3425
|
+
code: postcssResult.css,
|
|
3426
|
+
map: postcssMap
|
|
3427
|
+
};
|
|
3324
3428
|
}
|
|
3325
3429
|
}
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3430
|
+
const cssPlugins = [{
|
|
3431
|
+
name: "weapp-tailwindcss:uni-app-x:css",
|
|
3432
|
+
async transform(code, id) {
|
|
3433
|
+
if (!isEnabled()) return;
|
|
3434
|
+
await runtimeState.readyPromise;
|
|
3435
|
+
return transformStyle(code, id, void 0, this);
|
|
3436
|
+
}
|
|
3437
|
+
}, {
|
|
3438
|
+
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
3439
|
+
enforce: "pre",
|
|
3440
|
+
async transform(code, id) {
|
|
3441
|
+
if (!isEnabled()) return;
|
|
3442
|
+
await runtimeState.readyPromise;
|
|
3443
|
+
const { query } = parseVueRequest(id);
|
|
3444
|
+
const lang = query.lang;
|
|
3445
|
+
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
3446
|
+
return transformStyle(code, id, query, this);
|
|
3447
|
+
}
|
|
3448
|
+
}];
|
|
3449
|
+
const nvuePlugin = {
|
|
3450
|
+
name: "weapp-tailwindcss:uni-app-x:nvue",
|
|
3451
|
+
enforce: "pre",
|
|
3452
|
+
async buildStart() {
|
|
3453
|
+
if (!isEnabled()) return;
|
|
3454
|
+
await ensureRuntimeClassSet(true);
|
|
3347
3455
|
},
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3456
|
+
async transform(code, id) {
|
|
3457
|
+
if (!isEnabled()) return;
|
|
3458
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3459
|
+
rememberHarmonyApplySource(code);
|
|
3460
|
+
const resolvedConfig = getResolvedConfig();
|
|
3461
|
+
const isServeCommand = resolvedConfig?.command === "serve";
|
|
3462
|
+
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
3463
|
+
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
3464
|
+
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
3465
|
+
const transformUVue = await loadTransformUVue();
|
|
3466
|
+
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
3467
|
+
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
3468
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, omitUndefined({
|
|
3469
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
3470
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
3471
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
3472
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
3473
|
+
}));
|
|
3474
|
+
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
3351
3475
|
},
|
|
3352
|
-
async
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3365
|
-
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3366
|
-
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3367
|
-
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3368
|
-
}
|
|
3369
|
-
metrics.html.elapsed += measureElapsed(start);
|
|
3370
|
-
metrics.html.transformed++;
|
|
3371
|
-
onUpdate(file, rawSource, transformed);
|
|
3372
|
-
debug("html handle: %s", file);
|
|
3373
|
-
return { result: transformed };
|
|
3476
|
+
async handleHotUpdate(ctx) {
|
|
3477
|
+
if (!isEnabled()) return;
|
|
3478
|
+
if (getResolvedConfig()?.command !== "serve") return;
|
|
3479
|
+
if (!UVUE_NVUE_RE.test(ctx.file)) return;
|
|
3480
|
+
await ensureRuntimeClassSet(true);
|
|
3481
|
+
},
|
|
3482
|
+
async watchChange(id) {
|
|
3483
|
+
if (!isEnabled()) return;
|
|
3484
|
+
const resolvedConfig = getResolvedConfig();
|
|
3485
|
+
if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
|
|
3486
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3487
|
+
await ensureRuntimeClassSet(true);
|
|
3374
3488
|
}
|
|
3375
|
-
}
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3489
|
+
};
|
|
3490
|
+
const stylePlaceholderPlugin = {
|
|
3491
|
+
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
3492
|
+
enforce: "post",
|
|
3493
|
+
generateBundle: {
|
|
3494
|
+
order: "post",
|
|
3495
|
+
async handler(_options, bundle) {
|
|
3496
|
+
if (!isEnabled()) return;
|
|
3497
|
+
const currentUtsPlatform = resolveUniUtsPlatform();
|
|
3498
|
+
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
3499
|
+
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
3500
|
+
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
3501
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3502
|
+
if (isHarmonyTarget) {
|
|
3503
|
+
const cssSources = [];
|
|
3504
|
+
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
3505
|
+
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
3506
|
+
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
3507
|
+
const harmonyApplyCssFile = path.resolve(getResolvedConfig()?.root ?? process$1.cwd(), "uni-app-x-harmony-apply.css");
|
|
3508
|
+
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
3509
|
+
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
3510
|
+
}
|
|
3511
|
+
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
3512
|
+
cssSources,
|
|
3513
|
+
excludeComponents: shouldEnableComponentLocalStyle()
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
3517
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
3518
|
+
const currentSource = String(item.source);
|
|
3519
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
3520
|
+
if (nextSource !== currentSource) item.source = nextSource;
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3399
3523
|
}
|
|
3400
|
-
});
|
|
3401
|
-
}
|
|
3402
|
-
//#endregion
|
|
3403
|
-
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
3404
|
-
function createLinkedUpdateHelpers(options) {
|
|
3405
|
-
const pendingLinkedUpdates = [];
|
|
3406
|
-
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
3407
|
-
options.onUpdate(fileName, previous, next);
|
|
3408
|
-
options.debug("js linked handle: %s", fileName);
|
|
3409
3524
|
};
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3525
|
+
return [
|
|
3526
|
+
...cssPlugins,
|
|
3527
|
+
nvuePlugin,
|
|
3528
|
+
stylePlaceholderPlugin
|
|
3529
|
+
];
|
|
3530
|
+
}
|
|
3531
|
+
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
3532
|
+
return async () => {
|
|
3533
|
+
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
3534
|
+
const absoluteFile = toAbsoluteOutputPath(file, outDir);
|
|
3535
|
+
const rawSource = originalSource.source.toString();
|
|
3536
|
+
await processCachedTask({
|
|
3537
|
+
cache,
|
|
3538
|
+
cacheKey: file,
|
|
3539
|
+
hashKey,
|
|
3540
|
+
rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
|
|
3541
|
+
applyResult(source) {
|
|
3542
|
+
originalSource.source = source;
|
|
3543
|
+
},
|
|
3544
|
+
onCacheHit() {
|
|
3545
|
+
debug("js cache hit: %s", file);
|
|
3546
|
+
},
|
|
3547
|
+
async transform() {
|
|
3548
|
+
const currentSource = originalSource.source.toString();
|
|
3549
|
+
const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
|
|
3550
|
+
uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
|
|
3551
|
+
babelParserOptions: {
|
|
3552
|
+
plugins: ["typescript"],
|
|
3553
|
+
sourceType: "unambiguous"
|
|
3554
|
+
}
|
|
3555
|
+
}));
|
|
3556
|
+
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
3557
|
+
onUpdate(file, currentSource, nextCode);
|
|
3558
|
+
debug("js handle: %s", file);
|
|
3559
|
+
applyLinkedResults(linked);
|
|
3560
|
+
return { result: nextCode };
|
|
3561
|
+
}
|
|
3414
3562
|
});
|
|
3415
3563
|
};
|
|
3416
|
-
const applyLinkedUpdates = (linked) => {
|
|
3417
|
-
applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
3418
|
-
};
|
|
3419
|
-
return {
|
|
3420
|
-
applyLinkedUpdates,
|
|
3421
|
-
pendingLinkedUpdates
|
|
3422
|
-
};
|
|
3423
|
-
}
|
|
3424
|
-
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
3425
|
-
if (!linked || !linkedSet) return;
|
|
3426
|
-
for (const id of Object.keys(linked)) {
|
|
3427
|
-
const linkedEntry = getJsEntry(id);
|
|
3428
|
-
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
3429
|
-
}
|
|
3430
3564
|
}
|
|
3431
3565
|
//#endregion
|
|
3432
3566
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
@@ -3534,7 +3668,7 @@ function processJsBundleEntry(options) {
|
|
|
3534
3668
|
}
|
|
3535
3669
|
const currentSource = originalEntrySource;
|
|
3536
3670
|
const precheckOptions = createHandlerOptions(path.resolve(outDir, file), {
|
|
3537
|
-
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
3671
|
+
uniAppX: resolveUniAppXJsTransformEnabled$1(uniAppX),
|
|
3538
3672
|
babelParserOptions: {
|
|
3539
3673
|
plugins: ["typescript"],
|
|
3540
3674
|
sourceType: "unambiguous"
|
|
@@ -4202,27 +4336,6 @@ function createTransformFilterSignature(options) {
|
|
|
4202
4336
|
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
4203
4337
|
}
|
|
4204
4338
|
//#endregion
|
|
4205
|
-
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
4206
|
-
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
4207
|
-
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
4208
|
-
if (!shouldUseNativeAppCssBranch(resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4209
|
-
appType: opts.appType,
|
|
4210
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4211
|
-
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
4212
|
-
uniUtsPlatform
|
|
4213
|
-
}), {
|
|
4214
|
-
appType: opts.appType,
|
|
4215
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4216
|
-
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
4217
|
-
uniUtsPlatform
|
|
4218
|
-
})) || !isUniAppXEnabled(opts.uniAppX)) return {};
|
|
4219
|
-
return {
|
|
4220
|
-
uniAppX: true,
|
|
4221
|
-
uniAppXCssTarget: "uvue",
|
|
4222
|
-
uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
4223
|
-
};
|
|
4224
|
-
}
|
|
4225
|
-
//#endregion
|
|
4226
4339
|
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
4227
4340
|
function resolveSourceRootCandidate(root, value) {
|
|
4228
4341
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
@@ -4284,16 +4397,35 @@ function inferPlatformFromViteOutDir$1(outDir) {
|
|
|
4284
4397
|
const normalized = segment.trim().toLowerCase();
|
|
4285
4398
|
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
4286
4399
|
}
|
|
4287
|
-
function isUniAppViteWebviewOutDir$1(outDir) {
|
|
4288
|
-
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
4289
|
-
return normalized === "app" || normalized === "app-plus";
|
|
4290
|
-
}
|
|
4291
4400
|
function createGenerateBundleHook(context) {
|
|
4292
4401
|
const state = createBundleBuildState();
|
|
4293
4402
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4294
4403
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4295
4404
|
let currentOutDir;
|
|
4296
4405
|
let currentSubpackageRoots;
|
|
4406
|
+
const createInitialCssPipelineContext = (file) => {
|
|
4407
|
+
const resolvedConfig = context.getResolvedConfig();
|
|
4408
|
+
const platform = context.opts.cssOptions?.platform ?? context.opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4409
|
+
const currentGeneratorOptions = normalizeWeappTailwindcssGeneratorOptions(context.opts.generator, {
|
|
4410
|
+
appType: context.opts.appType,
|
|
4411
|
+
platform,
|
|
4412
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4413
|
+
uniAppX: context.opts.uniAppX
|
|
4414
|
+
});
|
|
4415
|
+
return {
|
|
4416
|
+
currentGeneratorBranch: resolveGeneratorRuntimeBranch(currentGeneratorOptions, {
|
|
4417
|
+
appType: context.opts.appType,
|
|
4418
|
+
platform,
|
|
4419
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4420
|
+
uniAppX: context.opts.uniAppX
|
|
4421
|
+
}),
|
|
4422
|
+
currentGeneratorOptions,
|
|
4423
|
+
file,
|
|
4424
|
+
opts: context.opts,
|
|
4425
|
+
resolvedConfig,
|
|
4426
|
+
resolveStylePlatform: () => platform
|
|
4427
|
+
};
|
|
4428
|
+
};
|
|
4297
4429
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
4298
4430
|
getAppType: () => context.opts.appType,
|
|
4299
4431
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
@@ -4301,7 +4433,7 @@ function createGenerateBundleHook(context) {
|
|
|
4301
4433
|
getOutputRoot: () => currentOutDir,
|
|
4302
4434
|
getExtraOptions: (file) => ({
|
|
4303
4435
|
...resolveViteCssHandlerExtraOptions(file),
|
|
4304
|
-
...
|
|
4436
|
+
...context.cssPipelineStrategy?.getCssHandlerExtraOptions?.(createInitialCssPipelineContext(file)) ?? {},
|
|
4305
4437
|
...currentSubpackageRoots && isSubpackageOutputFile(file, currentSubpackageRoots) ? { isMainChunk: false } : {}
|
|
4306
4438
|
})
|
|
4307
4439
|
});
|
|
@@ -4332,18 +4464,27 @@ function createGenerateBundleHook(context) {
|
|
|
4332
4464
|
uniAppX,
|
|
4333
4465
|
uniUtsPlatform
|
|
4334
4466
|
});
|
|
4467
|
+
const cssPipelineContext = {
|
|
4468
|
+
bundle,
|
|
4469
|
+
currentGeneratorBranch: generatorBranch,
|
|
4470
|
+
currentGeneratorOptions: generatorOptions,
|
|
4471
|
+
opts,
|
|
4472
|
+
resolvedConfig,
|
|
4473
|
+
resolveStylePlatform: () => generatorPlatform
|
|
4474
|
+
};
|
|
4335
4475
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4336
|
-
const
|
|
4337
|
-
const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
|
|
4476
|
+
const shouldApplyWebCssCompat = context.cssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
4338
4477
|
const transformWebTargetCss = (css) => {
|
|
4339
|
-
|
|
4340
|
-
|
|
4478
|
+
return context.cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
4479
|
+
...cssPipelineContext,
|
|
4480
|
+
defaultWebCssCompat: (value) => transformWebCssCompat(value, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true),
|
|
4481
|
+
removeScopedPreflight: (value) => value,
|
|
4482
|
+
shouldApplyWebCssCompat
|
|
4483
|
+
}) ?? (shouldApplyWebCssCompat ? transformWebCssCompat(css, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true) : css);
|
|
4341
4484
|
};
|
|
4342
|
-
const
|
|
4343
|
-
const
|
|
4344
|
-
const
|
|
4345
|
-
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
4346
|
-
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
4485
|
+
const isNativeAppStyleTarget = context.cssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
4486
|
+
const isHarmonyAppStyleTarget = context.cssPipelineStrategy?.isHarmonyAppStyleTarget?.(cssPipelineContext) === true;
|
|
4487
|
+
const shouldPreserveAppCssExtension = context.cssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? (isNativeAppStyleTarget || isHarmonyAppStyleTarget);
|
|
4347
4488
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
4348
4489
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
4349
4490
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
@@ -4358,6 +4499,8 @@ function createGenerateBundleHook(context) {
|
|
|
4358
4499
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
4359
4500
|
collectViteProcessedCssAssetResults(bundle, {
|
|
4360
4501
|
opts,
|
|
4502
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4503
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
4361
4504
|
isViteProcessedCssAsset,
|
|
4362
4505
|
markCssAssetProcessed,
|
|
4363
4506
|
recordCssAssetResult,
|
|
@@ -4422,20 +4565,32 @@ function createGenerateBundleHook(context) {
|
|
|
4422
4565
|
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4423
4566
|
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4424
4567
|
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4425
|
-
const
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4568
|
+
const isRootStyleOutputFile = (file) => {
|
|
4569
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4570
|
+
return normalized.endsWith(".css") && !normalized.includes("/");
|
|
4571
|
+
};
|
|
4572
|
+
const isMiniProgramStyleOutputFile = (file) => /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
4573
|
+
const resolveConfiguredCssEntryRootInjectionTarget = (sourceFile, outputFile) => {
|
|
4574
|
+
if (!outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
|
|
4575
|
+
return context.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
4576
|
+
...cssPipelineContext,
|
|
4577
|
+
bundle,
|
|
4578
|
+
isConfiguredCssEntryFile: (file) => typeof file === "string" && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(file)),
|
|
4579
|
+
isMiniProgramStyleOutputFile,
|
|
4580
|
+
isRootStyleOutputFile,
|
|
4581
|
+
outputFile,
|
|
4582
|
+
sourceFile
|
|
4430
4583
|
});
|
|
4431
|
-
const matchedRootCssFiles = rootCssFiles.filter((file) => getCssHandlerOptions(file).isMainChunk);
|
|
4432
|
-
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
4433
|
-
if (matchedRootCssFiles.length > 1) return;
|
|
4434
|
-
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
4435
4584
|
};
|
|
4436
4585
|
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4437
|
-
const
|
|
4438
|
-
|
|
4586
|
+
const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
|
|
4587
|
+
const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
|
|
4588
|
+
if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
|
|
4589
|
+
if (!(context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
|
|
4590
|
+
...cssPipelineContext,
|
|
4591
|
+
isRootStyleOutputFile,
|
|
4592
|
+
outputFile
|
|
4593
|
+
}) === true || cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile))) return;
|
|
4439
4594
|
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4440
4595
|
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4441
4596
|
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
@@ -4608,10 +4763,18 @@ function createGenerateBundleHook(context) {
|
|
|
4608
4763
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4609
4764
|
moduleGraph: moduleGraphOptions
|
|
4610
4765
|
});
|
|
4611
|
-
const
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
}
|
|
4766
|
+
const resolveFrameworkJsHandlerOptions = (absoluteFilename) => context.cssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
4767
|
+
...cssPipelineContext,
|
|
4768
|
+
file: absoluteFilename
|
|
4769
|
+
});
|
|
4770
|
+
const createHandlerOptions = (absoluteFilename, extra) => {
|
|
4771
|
+
const frameworkExtra = resolveFrameworkJsHandlerOptions(absoluteFilename);
|
|
4772
|
+
return createBaseHandlerOptions(absoluteFilename, frameworkExtra || extra ? {
|
|
4773
|
+
...frameworkExtra,
|
|
4774
|
+
...extra
|
|
4775
|
+
} : void 0);
|
|
4776
|
+
};
|
|
4777
|
+
const shouldTransformJsBundle = !isWebGeneratorTarget || context.cssPipelineStrategy?.shouldTransformServeJs?.(cssPipelineContext) === true;
|
|
4615
4778
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4616
4779
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4617
4780
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4668,12 +4831,18 @@ function createGenerateBundleHook(context) {
|
|
|
4668
4831
|
metrics.css.total++;
|
|
4669
4832
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
4670
4833
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
4834
|
+
const cssPipelineContext = {
|
|
4835
|
+
...createInitialCssPipelineContext(file),
|
|
4836
|
+
bundle
|
|
4837
|
+
};
|
|
4671
4838
|
let outputFile = resolveCssBundleOutputFile({
|
|
4672
4839
|
bundleFiles,
|
|
4840
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4673
4841
|
defaultStyleOutputExtension,
|
|
4674
4842
|
file,
|
|
4675
4843
|
isWebGeneratorTarget,
|
|
4676
4844
|
opts,
|
|
4845
|
+
pipelineContext: cssPipelineContext,
|
|
4677
4846
|
shouldPreserveAppCssExtension
|
|
4678
4847
|
});
|
|
4679
4848
|
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
@@ -4682,6 +4851,13 @@ function createGenerateBundleHook(context) {
|
|
|
4682
4851
|
originalFileNames: originalSource.originalFileNames,
|
|
4683
4852
|
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4684
4853
|
});
|
|
4854
|
+
const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((entry) => originalSource.originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true) : void 0;
|
|
4855
|
+
const configuredOriginalOutputFile = configuredOriginalSourceEntry ? resolveMatchedOutputFileForCurrentAsset(configuredOriginalSourceEntry.file) : void 0;
|
|
4856
|
+
let resolvedFromConfiguredOriginalCssEntry = false;
|
|
4857
|
+
if (configuredOriginalOutputFile && normalizeOutputPathKey(configuredOriginalOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
4858
|
+
outputFile = configuredOriginalOutputFile;
|
|
4859
|
+
resolvedFromConfiguredOriginalCssEntry = true;
|
|
4860
|
+
}
|
|
4685
4861
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4686
4862
|
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile, opts.cssMatcher)) {
|
|
4687
4863
|
delete bundle[file];
|
|
@@ -4693,13 +4869,14 @@ function createGenerateBundleHook(context) {
|
|
|
4693
4869
|
let resolvedFromTemporaryCssAsset = false;
|
|
4694
4870
|
const applyCssResult = (source) => {
|
|
4695
4871
|
applyCssResultToBundle({
|
|
4696
|
-
appType: opts.appType,
|
|
4697
4872
|
assetSourceFile,
|
|
4698
4873
|
bundle,
|
|
4874
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4699
4875
|
emitOrReplayCssAsset,
|
|
4700
4876
|
file,
|
|
4701
4877
|
originalSource,
|
|
4702
4878
|
outputFile,
|
|
4879
|
+
pipelineContext: cssPipelineContext,
|
|
4703
4880
|
source,
|
|
4704
4881
|
viteProcessedCssAsset
|
|
4705
4882
|
});
|
|
@@ -4766,7 +4943,7 @@ function createGenerateBundleHook(context) {
|
|
|
4766
4943
|
if (!hasUsableRememberedTailwindSource) {
|
|
4767
4944
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4768
4945
|
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
4769
|
-
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 :
|
|
4946
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
|
|
4770
4947
|
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
4771
4948
|
outputFile,
|
|
4772
4949
|
rawSource: inferredWebviewRootSourceEntry.source,
|
|
@@ -4854,7 +5031,7 @@ function createGenerateBundleHook(context) {
|
|
|
4854
5031
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
4855
5032
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4856
5033
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4857
|
-
const webviewRootCssInjectionTarget = vitePipelineCssAsset ?
|
|
5034
|
+
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveConfiguredCssEntryRootInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
4858
5035
|
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4859
5036
|
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
4860
5037
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
@@ -4895,7 +5072,7 @@ function createGenerateBundleHook(context) {
|
|
|
4895
5072
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4896
5073
|
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
4897
5074
|
const shouldRecordVitePipelineCssByOutput = normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4898
|
-
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
5075
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
4899
5076
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
4900
5077
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
4901
5078
|
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
@@ -5041,7 +5218,7 @@ function createGenerateBundleHook(context) {
|
|
|
5041
5218
|
continue;
|
|
5042
5219
|
}
|
|
5043
5220
|
if (type !== "js") continue;
|
|
5044
|
-
if (
|
|
5221
|
+
if (!shouldTransformJsBundle) {
|
|
5045
5222
|
debug("js skip web target: %s", file);
|
|
5046
5223
|
continue;
|
|
5047
5224
|
}
|
|
@@ -5123,6 +5300,8 @@ function createGenerateBundleHook(context) {
|
|
|
5123
5300
|
bundleFiles,
|
|
5124
5301
|
cache,
|
|
5125
5302
|
cssTaskFactories,
|
|
5303
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
5304
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
5126
5305
|
debug,
|
|
5127
5306
|
defaultStyleOutputExtension,
|
|
5128
5307
|
formatIteration: useIncrementalMode ? state.iteration : 0,
|
|
@@ -5196,9 +5375,9 @@ function registerGeneratorDependencies(ctx, dependencies) {
|
|
|
5196
5375
|
throw error;
|
|
5197
5376
|
}
|
|
5198
5377
|
}
|
|
5199
|
-
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
5378
|
+
function createCssHandlerOptions(opts, majorVersion, file, extraOptions = {}) {
|
|
5200
5379
|
return {
|
|
5201
|
-
...
|
|
5380
|
+
...extraOptions,
|
|
5202
5381
|
cssPreflight: opts.cssPreflight,
|
|
5203
5382
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
5204
5383
|
postcssOptions: { options: { from: file } },
|
|
@@ -5223,13 +5402,15 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
5223
5402
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
5224
5403
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
5225
5404
|
}
|
|
5226
|
-
function
|
|
5227
|
-
const
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5405
|
+
function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
5406
|
+
const shouldApplyWebCssCompat = cssPipelineStrategy?.shouldApplyWebCssCompat?.(context) === true;
|
|
5407
|
+
const defaultWebCssCompat = (value) => transformWebCssCompat(value, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true);
|
|
5408
|
+
return cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
5409
|
+
...context,
|
|
5410
|
+
defaultWebCssCompat,
|
|
5411
|
+
removeScopedPreflight: (value) => value,
|
|
5412
|
+
shouldApplyWebCssCompat
|
|
5413
|
+
}) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
|
|
5233
5414
|
}
|
|
5234
5415
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
5235
5416
|
return {
|
|
@@ -5238,7 +5419,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5238
5419
|
generateBundle: {
|
|
5239
5420
|
order: "post",
|
|
5240
5421
|
async handler(_options, bundle) {
|
|
5241
|
-
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
5422
|
+
const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
5242
5423
|
const resolvedConfig = getResolvedConfig();
|
|
5243
5424
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
5244
5425
|
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
@@ -5257,11 +5438,16 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5257
5438
|
uniUtsPlatform
|
|
5258
5439
|
});
|
|
5259
5440
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
5260
|
-
const
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5441
|
+
const createCssPipelineContext = (_file) => ({
|
|
5442
|
+
bundle,
|
|
5443
|
+
currentGeneratorBranch: generatorBranch,
|
|
5444
|
+
currentGeneratorOptions: generatorOptions,
|
|
5445
|
+
opts,
|
|
5446
|
+
resolvedConfig,
|
|
5447
|
+
resolveStylePlatform: () => generatorPlatform
|
|
5448
|
+
});
|
|
5449
|
+
const isHarmonyAppStyleTarget = cssPipelineStrategy?.isHarmonyAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5450
|
+
const isNativeAppStyleTarget = cssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5265
5451
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
5266
5452
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
5267
5453
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -5273,30 +5459,32 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5273
5459
|
const collectViteProcessedCssAssets = () => {
|
|
5274
5460
|
collectViteProcessedCssAssetResults(bundle, {
|
|
5275
5461
|
opts,
|
|
5462
|
+
cssPipelineStrategy,
|
|
5463
|
+
createCssPipelineContext,
|
|
5276
5464
|
isViteProcessedCssAsset,
|
|
5277
5465
|
markCssAssetProcessed,
|
|
5278
5466
|
recordCssAssetResult,
|
|
5279
5467
|
recordViteProcessedCssAssetResult,
|
|
5280
5468
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
5281
|
-
transformCss: (css) => finalizeWebCss(css,
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
}),
|
|
5469
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5470
|
+
...createCssPipelineContext(file),
|
|
5471
|
+
file
|
|
5472
|
+
}, cssPipelineStrategy),
|
|
5286
5473
|
debug
|
|
5287
5474
|
});
|
|
5288
5475
|
};
|
|
5289
5476
|
const injectViteProcessedCssIntoMainCss = () => {
|
|
5290
5477
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
5291
5478
|
opts,
|
|
5479
|
+
cssPipelineStrategy,
|
|
5480
|
+
createCssPipelineContext,
|
|
5292
5481
|
getViteProcessedCssAssetResults,
|
|
5293
5482
|
markCssAssetProcessed,
|
|
5294
5483
|
recordCssAssetResult,
|
|
5295
|
-
transformCss: (css) => finalizeWebCss(css,
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
}),
|
|
5484
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5485
|
+
...createCssPipelineContext(file),
|
|
5486
|
+
file
|
|
5487
|
+
}, cssPipelineStrategy),
|
|
5300
5488
|
debug,
|
|
5301
5489
|
onUpdate: opts.onUpdate
|
|
5302
5490
|
});
|
|
@@ -5308,7 +5496,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5308
5496
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
5309
5497
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
5310
5498
|
const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
|
|
5311
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css"
|
|
5499
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5500
|
+
...createCssPipelineContext("uni-app-x-harmony-apply.css"),
|
|
5501
|
+
file: "uni-app-x-harmony-apply.css"
|
|
5502
|
+
}) ?? {});
|
|
5312
5503
|
const generated = await generateTailwindV4Css({
|
|
5313
5504
|
opts,
|
|
5314
5505
|
runtimeState,
|
|
@@ -5343,10 +5534,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5343
5534
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
5344
5535
|
collectViteProcessedCssAssets();
|
|
5345
5536
|
injectViteProcessedCssIntoMainCss();
|
|
5346
|
-
|
|
5347
|
-
appType: opts.appType,
|
|
5537
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5348
5538
|
cssMatcher: opts.cssMatcher,
|
|
5349
5539
|
debug,
|
|
5540
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5350
5541
|
onUpdate: opts.onUpdate,
|
|
5351
5542
|
recordCssAssetResult
|
|
5352
5543
|
});
|
|
@@ -5361,18 +5552,20 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5361
5552
|
const file = output.fileName || bundleFile;
|
|
5362
5553
|
const rawSource = output.source.toString();
|
|
5363
5554
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
5364
|
-
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource),
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
}));
|
|
5555
|
+
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), {
|
|
5556
|
+
...createCssPipelineContext(file),
|
|
5557
|
+
file
|
|
5558
|
+
}, cssPipelineStrategy));
|
|
5369
5559
|
output.source = nextCss;
|
|
5370
5560
|
markCssAssetProcessed(output, file);
|
|
5371
5561
|
recordCssAssetResult?.(file, nextCss);
|
|
5372
5562
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
5373
5563
|
return;
|
|
5374
5564
|
}
|
|
5375
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file
|
|
5565
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5566
|
+
...createCssPipelineContext(file),
|
|
5567
|
+
file
|
|
5568
|
+
}) ?? {});
|
|
5376
5569
|
const cssUserHandlerOptions = {
|
|
5377
5570
|
...cssHandlerOptions,
|
|
5378
5571
|
isMainChunk: false
|
|
@@ -5381,7 +5574,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5381
5574
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
5382
5575
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
5383
5576
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
5384
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile
|
|
5577
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5578
|
+
...createCssPipelineContext(generatorSourceFile),
|
|
5579
|
+
file: generatorSourceFile
|
|
5580
|
+
}) ?? {}) : cssHandlerOptions;
|
|
5385
5581
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
5386
5582
|
...generatorCssHandlerOptions,
|
|
5387
5583
|
isMainChunk: false
|
|
@@ -5400,11 +5596,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5400
5596
|
styleHandler: opts.styleHandler,
|
|
5401
5597
|
debug
|
|
5402
5598
|
}) : void 0;
|
|
5403
|
-
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource,
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
}) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5599
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, {
|
|
5600
|
+
...createCssPipelineContext(file),
|
|
5601
|
+
file
|
|
5602
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5408
5603
|
if (generated) {
|
|
5409
5604
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
5410
5605
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5419,10 +5614,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5419
5614
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
5420
5615
|
collectViteProcessedCssAssets();
|
|
5421
5616
|
injectViteProcessedCssIntoMainCss();
|
|
5422
|
-
|
|
5423
|
-
appType: opts.appType,
|
|
5617
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5424
5618
|
cssMatcher: opts.cssMatcher,
|
|
5425
5619
|
debug,
|
|
5620
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5426
5621
|
onUpdate: opts.onUpdate,
|
|
5427
5622
|
recordCssAssetResult
|
|
5428
5623
|
});
|
|
@@ -6193,7 +6388,7 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
6193
6388
|
return resolvedRoot;
|
|
6194
6389
|
}
|
|
6195
6390
|
//#endregion
|
|
6196
|
-
//#region src/bundlers/vite/
|
|
6391
|
+
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
6197
6392
|
const debug = createDebug();
|
|
6198
6393
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
6199
6394
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
@@ -6232,23 +6427,22 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
6232
6427
|
function isWebOrNativeAppPlatform(platform) {
|
|
6233
6428
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
6234
6429
|
}
|
|
6235
|
-
function
|
|
6236
|
-
return
|
|
6430
|
+
function applyViteWebCssCompat(css, options) {
|
|
6431
|
+
return transformWebCssCompat(css, options.compat);
|
|
6237
6432
|
}
|
|
6238
|
-
function
|
|
6239
|
-
|
|
6240
|
-
return options.safeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
6433
|
+
function isInternalUserDefinedOptions(options) {
|
|
6434
|
+
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
6241
6435
|
}
|
|
6242
6436
|
/**
|
|
6243
|
-
*
|
|
6244
|
-
* @description uni-app vite / uni-app-x 版本插件
|
|
6245
|
-
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
6437
|
+
* Vite 各框架分支共享的组合工厂。框架分支只负责选择和拥有各自入口,公共稳定能力放在这里复用。
|
|
6246
6438
|
*/
|
|
6247
|
-
function
|
|
6248
|
-
|
|
6249
|
-
const
|
|
6250
|
-
const
|
|
6251
|
-
const
|
|
6439
|
+
function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
6440
|
+
debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
|
|
6441
|
+
const rawOptions = options.__internalViteRawOptions ?? options;
|
|
6442
|
+
const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
6443
|
+
const hasExplicitTailwindcssBasedir = typeof options.__internalViteRawExplicitTailwindcssBasedir === "boolean" ? options.__internalViteRawExplicitTailwindcssBasedir : typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
6444
|
+
const rawCssEntries = collectConfiguredCssEntries(rawOptions);
|
|
6445
|
+
const opts = isInternalUserDefinedOptions(options) ? options : getCompilerContext({
|
|
6252
6446
|
...options,
|
|
6253
6447
|
__internalDeferMissingCssEntriesWarning: true
|
|
6254
6448
|
});
|
|
@@ -6269,8 +6463,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6269
6463
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler, styleInjector } = opts;
|
|
6270
6464
|
const initialTailwindRuntime = tailwindRuntime;
|
|
6271
6465
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
6272
|
-
const
|
|
6273
|
-
const
|
|
6466
|
+
const frameworkCssPipelineStrategy = frameworkBranch.cssPipelineStrategy;
|
|
6467
|
+
const uniAppXEnabled = frameworkBranch.isRuntimeClassSetFeatureEnabled?.({ uniAppX }) === true;
|
|
6468
|
+
const shouldEnableFrameworkExtraPlugins = () => frameworkBranch.createExtraPlugins !== void 0;
|
|
6274
6469
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
6275
6470
|
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
6276
6471
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
@@ -6299,6 +6494,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6299
6494
|
tailwindcssMajorVersion,
|
|
6300
6495
|
uniAppX
|
|
6301
6496
|
});
|
|
6497
|
+
const createCssPipelineContext = (overrides = {}) => ({
|
|
6498
|
+
currentGeneratorBranch: resolveCurrentGeneratorBranch(),
|
|
6499
|
+
currentGeneratorOptions: resolveCurrentGeneratorOptions(),
|
|
6500
|
+
opts,
|
|
6501
|
+
resolvedConfig,
|
|
6502
|
+
resolveStylePlatform: resolveViteStylePlatform,
|
|
6503
|
+
...overrides
|
|
6504
|
+
});
|
|
6302
6505
|
const initialGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6303
6506
|
const transformEarlyMiniProgramCss = (code) => {
|
|
6304
6507
|
const platform = resolveViteStylePlatform();
|
|
@@ -6315,8 +6518,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
6315
6518
|
};
|
|
6316
6519
|
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
6317
6520
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
6318
|
-
...
|
|
6319
|
-
cssEntries: opts.cssEntries ??
|
|
6521
|
+
...rawOptions,
|
|
6522
|
+
cssEntries: opts.cssEntries ?? rawOptions.cssEntries
|
|
6320
6523
|
});
|
|
6321
6524
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
6322
6525
|
const transientAutoCssSources = /* @__PURE__ */ new Map();
|
|
@@ -6632,10 +6835,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
6632
6835
|
const isUniViteProject = () => {
|
|
6633
6836
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
6634
6837
|
};
|
|
6635
|
-
const isHarmonyAppBuildTarget = () => {
|
|
6636
|
-
if (resolveUniUtsPlatform().isAppHarmony) return true;
|
|
6637
|
-
return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
|
|
6638
|
-
};
|
|
6639
6838
|
const matchesViteProcessedCssSource = (candidate) => {
|
|
6640
6839
|
const normalized = normalizeViteProcessedCssFile(candidate);
|
|
6641
6840
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
@@ -6655,7 +6854,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6655
6854
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
6656
6855
|
getExtraOptions: (file) => ({
|
|
6657
6856
|
...resolveViteCssHandlerExtraOptions(file),
|
|
6658
|
-
...
|
|
6857
|
+
...frameworkCssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
6858
|
+
...createCssPipelineContext(),
|
|
6859
|
+
file
|
|
6860
|
+
}) ?? {}
|
|
6659
6861
|
}),
|
|
6660
6862
|
getDynamicCssOptions: () => ({ cssPreflight: opts.cssPreflight })
|
|
6661
6863
|
});
|
|
@@ -6668,20 +6870,24 @@ function WeappTailwindcss(options = {}) {
|
|
|
6668
6870
|
await runtimeState.readyPromise;
|
|
6669
6871
|
await waitForSourceCandidateSyncs();
|
|
6670
6872
|
const file = cleanUrl(id);
|
|
6671
|
-
const requestFile = isCSSRequest(id) ? id : file;
|
|
6873
|
+
const requestFile = isCSSRequest(id) ? id === file ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : id : file;
|
|
6672
6874
|
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
6673
6875
|
const generatorCode = normalizeEmptyTailwindCustomVariants(code);
|
|
6674
6876
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
6675
|
-
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
6676
|
-
const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
|
|
6677
|
-
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6678
6877
|
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6679
6878
|
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6680
|
-
const
|
|
6879
|
+
const cssPipelineContext = createCssPipelineContext({
|
|
6880
|
+
currentGeneratorBranch,
|
|
6881
|
+
currentGeneratorOptions
|
|
6882
|
+
});
|
|
6883
|
+
const shouldPreserveStyleOutputExtension = frameworkCssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
6884
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6885
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, shouldPreserveStyleOutputExtension, sourceRoot);
|
|
6681
6886
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6887
|
+
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
6682
6888
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6683
6889
|
const cssHandlerOptions = {
|
|
6684
|
-
...
|
|
6890
|
+
...sourceCssHandlerOptions,
|
|
6685
6891
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6686
6892
|
};
|
|
6687
6893
|
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindApplyDirective(generatorCode) ? {
|
|
@@ -6689,7 +6895,11 @@ function WeappTailwindcss(options = {}) {
|
|
|
6689
6895
|
css: generatorCode,
|
|
6690
6896
|
file: path.resolve(file)
|
|
6691
6897
|
} : void 0);
|
|
6692
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null &&
|
|
6898
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && (frameworkCssPipelineStrategy?.shouldDeferEmptyScopedCssSource?.({
|
|
6899
|
+
...cssPipelineContext,
|
|
6900
|
+
cssHandlerOptions,
|
|
6901
|
+
generatorCode
|
|
6902
|
+
}) ?? true);
|
|
6693
6903
|
const generated = await generateTailwindV4Css({
|
|
6694
6904
|
opts,
|
|
6695
6905
|
runtimeState,
|
|
@@ -6698,7 +6908,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6698
6908
|
file,
|
|
6699
6909
|
outputFile,
|
|
6700
6910
|
cssHandlerOptions,
|
|
6701
|
-
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(
|
|
6911
|
+
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(requestFile),
|
|
6702
6912
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6703
6913
|
getSourceCandidatesForEntries,
|
|
6704
6914
|
generatorPlatform: resolveGeneratorPlatform(),
|
|
@@ -6710,12 +6920,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6710
6920
|
});
|
|
6711
6921
|
if (!generated) return;
|
|
6712
6922
|
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6713
|
-
const
|
|
6714
|
-
const tracedCss = annotateCssSourceTrace(
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6923
|
+
const shouldApplyWebCssCompat = currentGeneratorBranch.isWeb || frameworkCssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
6924
|
+
const tracedCss = annotateCssSourceTrace(frameworkCssPipelineStrategy?.transformGeneratedCss?.(finalizedCss, {
|
|
6925
|
+
...cssPipelineContext,
|
|
6926
|
+
defaultWebCssCompat: (css) => applyViteWebCssCompat(css, { compat: currentGeneratorOptions.webCompat ?? true }),
|
|
6927
|
+
removeScopedPreflight: removeScopedTailwindPreflightCss,
|
|
6928
|
+
shouldApplyWebCssCompat
|
|
6929
|
+
}) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ? applyViteWebCssCompat(finalizedCss, { compat: currentGeneratorOptions.webCompat ?? true }) : finalizedCss), {
|
|
6719
6930
|
opts,
|
|
6720
6931
|
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6721
6932
|
});
|
|
@@ -6730,7 +6941,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6730
6941
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6731
6942
|
outputFile
|
|
6732
6943
|
});
|
|
6733
|
-
if (
|
|
6944
|
+
if (shouldPreserveStyleOutputExtension && outputFile.endsWith(".css")) hookContext?.emitFile?.({
|
|
6734
6945
|
type: "asset",
|
|
6735
6946
|
fileName: outputFile,
|
|
6736
6947
|
source: tracedCss
|
|
@@ -6741,9 +6952,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6741
6952
|
cssMemory.rememberCssSource({
|
|
6742
6953
|
outputFile,
|
|
6743
6954
|
rawSource: code,
|
|
6744
|
-
sourceFile:
|
|
6955
|
+
sourceFile: requestFile
|
|
6745
6956
|
});
|
|
6746
|
-
debug("css generated for vite postcss pipeline: %s bytes=%d",
|
|
6957
|
+
debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
|
|
6747
6958
|
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
6748
6959
|
};
|
|
6749
6960
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
@@ -6789,12 +7000,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6789
7000
|
recordGeneratorCandidates,
|
|
6790
7001
|
pruneViteCssCaches,
|
|
6791
7002
|
getViteCssCacheStats,
|
|
6792
|
-
hmrTimingRecorder
|
|
7003
|
+
hmrTimingRecorder,
|
|
7004
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy
|
|
6793
7005
|
});
|
|
6794
7006
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
6795
7007
|
opts,
|
|
6796
7008
|
runtimeState,
|
|
6797
7009
|
ensureRuntimeClassSet,
|
|
7010
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
6798
7011
|
debug,
|
|
6799
7012
|
getResolvedConfig,
|
|
6800
7013
|
markCssAssetProcessed,
|
|
@@ -6815,25 +7028,25 @@ function WeappTailwindcss(options = {}) {
|
|
|
6815
7028
|
}),
|
|
6816
7029
|
getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
|
|
6817
7030
|
});
|
|
6818
|
-
const
|
|
7031
|
+
const extraPluginPlatform = frameworkBranch.getExtraPluginPlatform?.() ?? {};
|
|
6819
7032
|
const prepareTailwindGeneration = async () => {
|
|
6820
7033
|
if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
|
|
6821
7034
|
await syncSourceCandidateScan();
|
|
6822
7035
|
};
|
|
6823
|
-
const
|
|
6824
|
-
appType: opts.appType ?? "uni-app-x",
|
|
7036
|
+
const extraPlugins = frameworkBranch.createExtraPlugins?.({
|
|
6825
7037
|
customAttributesEntities,
|
|
6826
7038
|
disabledDefaultTemplateHandler,
|
|
6827
|
-
|
|
7039
|
+
ensureRuntimeClassSet,
|
|
7040
|
+
generateCss: generateTailwindCssForVitePipeline,
|
|
7041
|
+
getResolvedConfig,
|
|
7042
|
+
isEnabled: shouldEnableFrameworkExtraPlugins,
|
|
7043
|
+
isIosPlatform: extraPluginPlatform.isIosPlatform === true,
|
|
7044
|
+
jsHandler,
|
|
6828
7045
|
mainCssChunkMatcher,
|
|
6829
7046
|
runtimeState,
|
|
6830
7047
|
styleHandler,
|
|
6831
|
-
generateCss: generateTailwindCssForVitePipeline,
|
|
6832
|
-
jsHandler,
|
|
6833
|
-
ensureRuntimeClassSet,
|
|
6834
|
-
getResolvedConfig,
|
|
6835
7048
|
uniAppX
|
|
6836
|
-
})
|
|
7049
|
+
}) ?? [];
|
|
6837
7050
|
const plugins = [
|
|
6838
7051
|
...rewritePlugins,
|
|
6839
7052
|
{
|
|
@@ -6932,10 +7145,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6932
7145
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6933
7146
|
}),
|
|
6934
7147
|
createViteServeJsTransformPlugin({
|
|
6935
|
-
createHandlerOptions: (file) => serveJsHandlerOptions(file,
|
|
7148
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
7149
|
+
...createCssPipelineContext(),
|
|
7150
|
+
file
|
|
7151
|
+
})),
|
|
6936
7152
|
getCommand: () => resolvedConfig?.command,
|
|
6937
7153
|
jsHandler,
|
|
6938
|
-
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb
|
|
7154
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
|
|
6939
7155
|
transformRuntime: ensureRuntimeClassSet
|
|
6940
7156
|
}),
|
|
6941
7157
|
{
|
|
@@ -7010,10 +7226,304 @@ function WeappTailwindcss(options = {}) {
|
|
|
7010
7226
|
}
|
|
7011
7227
|
}
|
|
7012
7228
|
];
|
|
7013
|
-
|
|
7229
|
+
plugins.push(...extraPlugins);
|
|
7014
7230
|
plugins.push(cssFinalizerOutputPlugin);
|
|
7015
|
-
plugins.push(...createBuiltinViteStyleInjectorPlugins(styleInjector, () =>
|
|
7231
|
+
plugins.push(...createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
|
|
7016
7232
|
return plugins;
|
|
7017
7233
|
}
|
|
7018
7234
|
//#endregion
|
|
7235
|
+
//#region src/bundlers/vite/frameworks/generic/index.ts
|
|
7236
|
+
function createGenericVitePlugins(options = {}) {
|
|
7237
|
+
return createViteFrameworkPlugins(options, {
|
|
7238
|
+
frameworkName: "generic",
|
|
7239
|
+
styleInjectorDelegate: viteStyleInjectorDelegates.generic
|
|
7240
|
+
});
|
|
7241
|
+
}
|
|
7242
|
+
//#endregion
|
|
7243
|
+
//#region src/bundlers/vite/frameworks/taro/index.ts
|
|
7244
|
+
const taroCssPipelineStrategy = {
|
|
7245
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7246
|
+
return true;
|
|
7247
|
+
},
|
|
7248
|
+
shouldMoveRootMiniProgramStyleToImportShellOrigin() {
|
|
7249
|
+
return true;
|
|
7250
|
+
},
|
|
7251
|
+
shouldNormalizeRootMiniProgramImportShell() {
|
|
7252
|
+
return true;
|
|
7253
|
+
}
|
|
7254
|
+
};
|
|
7255
|
+
function createTaroAlipayBrowserslistAssetPlugin() {
|
|
7256
|
+
return {
|
|
7257
|
+
name: "weapp-tailwindcss:taro-alipay-browserslist-asset",
|
|
7258
|
+
enforce: "pre",
|
|
7259
|
+
generateBundle(_options, bundle) {
|
|
7260
|
+
if (process$1.env.TARO_ENV !== "alipay") return;
|
|
7261
|
+
bundle[".browserslistrc"] = {
|
|
7262
|
+
type: "asset",
|
|
7263
|
+
fileName: ".browserslistrc",
|
|
7264
|
+
source: "defaults and fully supports es6-module"
|
|
7265
|
+
};
|
|
7266
|
+
}
|
|
7267
|
+
};
|
|
7268
|
+
}
|
|
7269
|
+
function createTaroVitePlugins(options = {}) {
|
|
7270
|
+
return [createTaroAlipayBrowserslistAssetPlugin(), ...createViteFrameworkPlugins(options, {
|
|
7271
|
+
frameworkName: "taro",
|
|
7272
|
+
cssPipelineStrategy: taroCssPipelineStrategy,
|
|
7273
|
+
styleInjectorDelegate: viteStyleInjectorDelegates.taro
|
|
7274
|
+
})];
|
|
7275
|
+
}
|
|
7276
|
+
//#endregion
|
|
7277
|
+
//#region src/bundlers/vite/frameworks/uni-app/index.ts
|
|
7278
|
+
function isUniAppWebviewStylePlatform(platform) {
|
|
7279
|
+
return platform === "app" || platform === "app-plus";
|
|
7280
|
+
}
|
|
7281
|
+
function isUniAppWebviewAppBundle(bundleFiles) {
|
|
7282
|
+
return bundleFiles.some((file) => path.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
7283
|
+
}
|
|
7284
|
+
function isUniAppWebviewOutDir(outDir) {
|
|
7285
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
7286
|
+
return normalized === "app" || normalized === "app-plus";
|
|
7287
|
+
}
|
|
7288
|
+
const uniAppCssPipelineStrategy = {
|
|
7289
|
+
getServeJsHandlerOptions(context) {
|
|
7290
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? { needEscaped: true } : void 0;
|
|
7291
|
+
},
|
|
7292
|
+
shouldApplyWebCssCompat(context) {
|
|
7293
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7294
|
+
},
|
|
7295
|
+
includeTailwindGeneratedCssAssetsInRootCoverage(context) {
|
|
7296
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7297
|
+
},
|
|
7298
|
+
resolveConfiguredCssEntryRootInjectionTarget(context) {
|
|
7299
|
+
if (context.isMiniProgramStyleOutputFile(context.outputFile) || !context.isConfiguredCssEntryFile(context.sourceFile)) return;
|
|
7300
|
+
const rootCssFiles = [];
|
|
7301
|
+
const matchedRootCssFiles = [];
|
|
7302
|
+
for (const [bundleFile, output] of Object.entries(context.bundle)) {
|
|
7303
|
+
if (output.type !== "asset") continue;
|
|
7304
|
+
const file = output.fileName || bundleFile;
|
|
7305
|
+
if (!context.opts.cssMatcher(file) || !context.isRootStyleOutputFile(file) || context.isMiniProgramStyleOutputFile(file)) continue;
|
|
7306
|
+
rootCssFiles.push(file);
|
|
7307
|
+
if (context.opts.mainCssChunkMatcher(file, context.opts.appType)) matchedRootCssFiles.push(file);
|
|
7308
|
+
}
|
|
7309
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
7310
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
7311
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
7312
|
+
},
|
|
7313
|
+
shouldApplyFinalWebviewCssCompat(context) {
|
|
7314
|
+
return isUniAppWebviewAppBundle(context.bundleFiles) || isUniAppWebviewOutDir(context.outDir);
|
|
7315
|
+
},
|
|
7316
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7317
|
+
return true;
|
|
7318
|
+
},
|
|
7319
|
+
shouldPreferExplicitWebCssTargets() {
|
|
7320
|
+
return true;
|
|
7321
|
+
},
|
|
7322
|
+
shouldPreferMatchedRootWebOutputTarget() {
|
|
7323
|
+
return true;
|
|
7324
|
+
},
|
|
7325
|
+
shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml(context) {
|
|
7326
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7327
|
+
},
|
|
7328
|
+
shouldSelectConfiguredCssEntryRootSource(context) {
|
|
7329
|
+
return context.currentGeneratorBranch.isWeb && context.opts.cssMatcher(context.outputFile) && context.isRootStyleOutputFile(context.outputFile);
|
|
7330
|
+
},
|
|
7331
|
+
shouldTransformServeJs(context) {
|
|
7332
|
+
return !context.currentGeneratorBranch.isWeb || isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7333
|
+
},
|
|
7334
|
+
transformGeneratedCss(css, context) {
|
|
7335
|
+
const webCss = context.shouldApplyWebCssCompat ? transformWebCssCompat(css, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true) : css;
|
|
7336
|
+
const safeCss = isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? transformWebCssSafeSelectors(webCss, { escapeMap: context.opts.escapeMap }) : webCss;
|
|
7337
|
+
return context.removeScopedPreflight(safeCss);
|
|
7338
|
+
}
|
|
7339
|
+
};
|
|
7340
|
+
function createUniAppVitePlugins(options = {}) {
|
|
7341
|
+
return createViteFrameworkPlugins(options, {
|
|
7342
|
+
frameworkName: "uni-app",
|
|
7343
|
+
cssPipelineStrategy: uniAppCssPipelineStrategy,
|
|
7344
|
+
styleInjectorDelegate: viteStyleInjectorDelegates.uniApp
|
|
7345
|
+
});
|
|
7346
|
+
}
|
|
7347
|
+
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
7348
|
+
"uni-ad-draw",
|
|
7349
|
+
"uni-ad-fullscreen-video",
|
|
7350
|
+
"uni-ad-interactive",
|
|
7351
|
+
"uni-ad-interstitial",
|
|
7352
|
+
"uni-ad-rewarded-video",
|
|
7353
|
+
"uni-ad",
|
|
7354
|
+
"uni-animation-view",
|
|
7355
|
+
"uni-audio",
|
|
7356
|
+
"uni-block",
|
|
7357
|
+
"uni-button",
|
|
7358
|
+
"uni-camera",
|
|
7359
|
+
"uni-canvas",
|
|
7360
|
+
"uni-checkbox-group",
|
|
7361
|
+
"uni-checkbox",
|
|
7362
|
+
"uni-cover-image",
|
|
7363
|
+
"uni-cover-view",
|
|
7364
|
+
"uni-custom-tab-bar",
|
|
7365
|
+
"uni-editor",
|
|
7366
|
+
"uni-form",
|
|
7367
|
+
"uni-icon",
|
|
7368
|
+
"uni-image",
|
|
7369
|
+
"uni-input",
|
|
7370
|
+
"uni-label",
|
|
7371
|
+
"uni-list-item",
|
|
7372
|
+
"uni-list-view",
|
|
7373
|
+
"uni-live-player",
|
|
7374
|
+
"uni-live-pusher",
|
|
7375
|
+
"uni-map",
|
|
7376
|
+
"uni-match-media",
|
|
7377
|
+
"uni-movable-area",
|
|
7378
|
+
"uni-movable-view",
|
|
7379
|
+
"uni-navigation-bar",
|
|
7380
|
+
"uni-navigator",
|
|
7381
|
+
"uni-open-data",
|
|
7382
|
+
"uni-page-meta",
|
|
7383
|
+
"uni-picker-view",
|
|
7384
|
+
"uni-picker",
|
|
7385
|
+
"uni-progress",
|
|
7386
|
+
"uni-radio-group",
|
|
7387
|
+
"uni-radio",
|
|
7388
|
+
"uni-rich-text",
|
|
7389
|
+
"uni-scroll-view",
|
|
7390
|
+
"uni-slider",
|
|
7391
|
+
"uni-sticky-header",
|
|
7392
|
+
"uni-sticky-section",
|
|
7393
|
+
"uni-swiper-item",
|
|
7394
|
+
"uni-swiper",
|
|
7395
|
+
"uni-switch",
|
|
7396
|
+
"uni-template",
|
|
7397
|
+
"uni-text",
|
|
7398
|
+
"uni-textarea",
|
|
7399
|
+
"uni-unicloud-db",
|
|
7400
|
+
"uni-video",
|
|
7401
|
+
"uni-view",
|
|
7402
|
+
"uni-web-view"
|
|
7403
|
+
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
7404
|
+
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
7405
|
+
function withUniAppXWebPreflightReset(css, enabled) {
|
|
7406
|
+
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
7407
|
+
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
7408
|
+
}
|
|
7409
|
+
//#endregion
|
|
7410
|
+
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
7411
|
+
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
7412
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
7413
|
+
if (!shouldUseNativeAppCssBranch(resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
7414
|
+
appType: opts.appType,
|
|
7415
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7416
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
7417
|
+
uniUtsPlatform
|
|
7418
|
+
}), {
|
|
7419
|
+
appType: opts.appType,
|
|
7420
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7421
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
7422
|
+
uniUtsPlatform
|
|
7423
|
+
})) || !isUniAppXEnabled(opts.uniAppX)) return {};
|
|
7424
|
+
return {
|
|
7425
|
+
uniAppX: true,
|
|
7426
|
+
uniAppXCssTarget: "uvue",
|
|
7427
|
+
uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
7428
|
+
};
|
|
7429
|
+
}
|
|
7430
|
+
//#endregion
|
|
7431
|
+
//#region src/bundlers/vite/frameworks/uni-app-x/index.ts
|
|
7432
|
+
function isUniAppXNativeAppStyleTarget() {
|
|
7433
|
+
return resolveUniUtsPlatform().isApp;
|
|
7434
|
+
}
|
|
7435
|
+
function isUniAppXHarmonyAppStyleTarget(context) {
|
|
7436
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
7437
|
+
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
7438
|
+
return uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (context.bundle != null && isUniAppXHarmonyBundle(context.bundle) || isUniAppXHarmonyOutDir(context.resolvedConfig?.build?.outDir));
|
|
7439
|
+
}
|
|
7440
|
+
const uniAppXCssPipelineStrategy = {
|
|
7441
|
+
getCssHandlerExtraOptions(context) {
|
|
7442
|
+
return resolveUniAppXNativeCssHandlerOptions(context.opts);
|
|
7443
|
+
},
|
|
7444
|
+
isNativeAppStyleTarget() {
|
|
7445
|
+
return isUniAppXNativeAppStyleTarget();
|
|
7446
|
+
},
|
|
7447
|
+
isHarmonyAppStyleTarget(context) {
|
|
7448
|
+
return isUniAppXHarmonyAppStyleTarget(context);
|
|
7449
|
+
},
|
|
7450
|
+
shouldPreserveStyleOutputExtension(context) {
|
|
7451
|
+
return isUniAppXNativeAppStyleTarget() || isUniAppXHarmonyAppStyleTarget(context);
|
|
7452
|
+
},
|
|
7453
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7454
|
+
return true;
|
|
7455
|
+
},
|
|
7456
|
+
shouldDeferEmptyScopedCssSource(context) {
|
|
7457
|
+
if (!context.cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(context.generatorCode)) return false;
|
|
7458
|
+
return true;
|
|
7459
|
+
},
|
|
7460
|
+
transformGeneratedCss(css, context) {
|
|
7461
|
+
const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
|
|
7462
|
+
return withUniAppXWebPreflightReset(context.removeScopedPreflight(webCss), context.currentGeneratorBranch.isWeb);
|
|
7463
|
+
}
|
|
7464
|
+
};
|
|
7465
|
+
function createUniAppXVitePlugins(options = {}) {
|
|
7466
|
+
return createViteFrameworkPlugins(options, {
|
|
7467
|
+
frameworkName: "uni-app-x",
|
|
7468
|
+
cssPipelineStrategy: uniAppXCssPipelineStrategy,
|
|
7469
|
+
getExtraPluginPlatform: () => ({ isIosPlatform: resolveUniUtsPlatform().isAppIos }),
|
|
7470
|
+
styleInjectorDelegate: viteStyleInjectorDelegates.uniApp,
|
|
7471
|
+
isRuntimeClassSetFeatureEnabled: () => true,
|
|
7472
|
+
createExtraPlugins: (context) => createUniAppXPlugins({
|
|
7473
|
+
appType: "uni-app-x",
|
|
7474
|
+
customAttributesEntities: context.customAttributesEntities,
|
|
7475
|
+
disabledDefaultTemplateHandler: context.disabledDefaultTemplateHandler,
|
|
7476
|
+
ensureRuntimeClassSet: context.ensureRuntimeClassSet,
|
|
7477
|
+
generateCss: context.generateCss,
|
|
7478
|
+
getResolvedConfig: context.getResolvedConfig,
|
|
7479
|
+
isEnabled: context.isEnabled,
|
|
7480
|
+
isIosPlatform: context.isIosPlatform,
|
|
7481
|
+
jsHandler: context.jsHandler,
|
|
7482
|
+
mainCssChunkMatcher: context.mainCssChunkMatcher,
|
|
7483
|
+
runtimeState: context.runtimeState,
|
|
7484
|
+
styleHandler: context.styleHandler,
|
|
7485
|
+
uniAppX: context.uniAppX
|
|
7486
|
+
})
|
|
7487
|
+
});
|
|
7488
|
+
}
|
|
7489
|
+
//#endregion
|
|
7490
|
+
//#region src/bundlers/vite/frameworks/weapp-vite/index.ts
|
|
7491
|
+
function createWeappVitePlugins(options = {}) {
|
|
7492
|
+
return createViteFrameworkPlugins(options, {
|
|
7493
|
+
frameworkName: "weapp-vite",
|
|
7494
|
+
styleInjectorDelegate: viteStyleInjectorDelegates.generic
|
|
7495
|
+
});
|
|
7496
|
+
}
|
|
7497
|
+
//#endregion
|
|
7498
|
+
//#region src/bundlers/vite/index.ts
|
|
7499
|
+
/**
|
|
7500
|
+
* @name WeappTailwindcss
|
|
7501
|
+
* @description Vite 入口只负责早期识别框架分支,具体插件组合由各 framework 目录拥有。
|
|
7502
|
+
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
7503
|
+
*/
|
|
7504
|
+
function WeappTailwindcss(options = {}) {
|
|
7505
|
+
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
7506
|
+
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
7507
|
+
const opts = getCompilerContext({
|
|
7508
|
+
...options,
|
|
7509
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
7510
|
+
});
|
|
7511
|
+
opts.__internalViteRawOptions = options;
|
|
7512
|
+
opts.__internalViteRawExplicitAppType = hasExplicitAppType;
|
|
7513
|
+
opts.__internalViteRawExplicitTailwindcssBasedir = hasExplicitTailwindcssBasedir;
|
|
7514
|
+
switch (resolveViteFrameworkProfile({
|
|
7515
|
+
appType: opts.appType,
|
|
7516
|
+
detectEnv: true,
|
|
7517
|
+
env: process$1.env,
|
|
7518
|
+
root: opts.tailwindcssBasedir ?? process$1.cwd(),
|
|
7519
|
+
uniAppX: opts.uniAppX
|
|
7520
|
+
}).frameworkName) {
|
|
7521
|
+
case "taro": return createTaroVitePlugins(opts);
|
|
7522
|
+
case "uni-app": return createUniAppVitePlugins(opts);
|
|
7523
|
+
case "uni-app-x": return createUniAppXVitePlugins(opts);
|
|
7524
|
+
case "weapp-vite": return createWeappVitePlugins(opts);
|
|
7525
|
+
default: return createGenericVitePlugins(opts);
|
|
7526
|
+
}
|
|
7527
|
+
}
|
|
7528
|
+
//#endregion
|
|
7019
7529
|
export { WeappTailwindcss as t };
|