weapp-tailwindcss 5.1.7 → 5.1.8
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-GdzlG_lx.js} +1286 -818
- package/dist/{vite-XxJh7Xtu.mjs → vite-vf2-cDdk.mjs} +1284 -816
- 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 +3 -3
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.js");
|
|
2
2
|
const require_framework = require("./framework.js");
|
|
3
|
-
const require_v4_engine = require("./v4-engine-
|
|
4
|
-
const require_generator = require("./generator-
|
|
3
|
+
const require_v4_engine = require("./v4-engine-BZP2462H.js");
|
|
4
|
+
const require_generator = require("./generator-DaaFxR5V.js");
|
|
5
5
|
const require_utils = require("./utils-D3h8j7Mk.js");
|
|
6
|
-
const require_context = require("./context-
|
|
7
|
-
const require_tailwindcss = require("./tailwindcss-
|
|
8
|
-
const require_hmr_timing = require("./hmr-timing-
|
|
9
|
-
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-
|
|
6
|
+
const require_context = require("./context-CRhUs_5e.js");
|
|
7
|
+
const require_tailwindcss = require("./tailwindcss-BZjZZi60.js");
|
|
8
|
+
const require_hmr_timing = require("./hmr-timing-DcIEXnf8.js");
|
|
9
|
+
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-10tvdJVC.js");
|
|
10
10
|
require("./logger-TlKT3xmR.js");
|
|
11
11
|
let node_fs = require("node:fs");
|
|
12
12
|
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
@@ -24,30 +24,6 @@ let node_buffer = require("node:buffer");
|
|
|
24
24
|
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
25
25
|
let comment_json = require("comment-json");
|
|
26
26
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
27
|
-
//#region src/uni-app-x/harmony.ts
|
|
28
|
-
function isUniAppXHarmonyOutDir(outDir) {
|
|
29
|
-
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/bundlers/vite/query.ts
|
|
33
|
-
function parseVueRequest(id) {
|
|
34
|
-
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
35
|
-
const searchParams = new URLSearchParams(rawQuery);
|
|
36
|
-
const query = Object.fromEntries(searchParams);
|
|
37
|
-
if (query.vue != null) query.vue = true;
|
|
38
|
-
if (query.index != null) query.index = Number(query.index);
|
|
39
|
-
if (query.raw != null) query.raw = true;
|
|
40
|
-
if (query.url != null) query.url = true;
|
|
41
|
-
if (query.scoped != null) query.scoped = true;
|
|
42
|
-
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
43
|
-
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
44
|
-
if (langType) query.lang = langType;
|
|
45
|
-
return {
|
|
46
|
-
filename,
|
|
47
|
-
query
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
//#endregion
|
|
51
27
|
//#region src/uni-app-x/style-asset/style-value.ts
|
|
52
28
|
const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/;
|
|
53
29
|
const STYLE_ENTRY_RE = /\[\s*("((?:\\.|[^"\\])+)")\s*,\s*(_pS\(_uM\(\[[\s\S]*?\]\)\))\s*\]/g;
|
|
@@ -494,488 +470,170 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
|
494
470
|
};
|
|
495
471
|
}
|
|
496
472
|
//#endregion
|
|
497
|
-
//#region src/
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
473
|
+
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
474
|
+
function collectConfiguredTailwindV4CssSources(opts) {
|
|
475
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
476
|
+
return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
477
|
+
}
|
|
478
|
+
function collectExplicitTailwindV4CssEntries(opts) {
|
|
479
|
+
const entries = [
|
|
480
|
+
...opts.cssEntries ?? [],
|
|
481
|
+
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
482
|
+
...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
483
|
+
];
|
|
484
|
+
return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
|
|
485
|
+
}
|
|
486
|
+
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
487
|
+
const entries = [];
|
|
488
|
+
const seen = /* @__PURE__ */ new Set();
|
|
489
|
+
const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
|
|
490
|
+
for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
|
|
491
|
+
if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
|
|
492
|
+
const resolvedFile = node_path.default.isAbsolute(cssEntry) ? node_path.default.resolve(cssEntry) : node_path.default.resolve(fallbackBase, cssEntry);
|
|
493
|
+
if (!(0, node_fs.existsSync)(resolvedFile)) continue;
|
|
494
|
+
const source = (0, node_fs.readFileSync)(resolvedFile, "utf8");
|
|
495
|
+
const key = `${resolvedFile}\0${source}`;
|
|
496
|
+
if (seen.has(key)) continue;
|
|
497
|
+
seen.add(key);
|
|
498
|
+
entries.push({
|
|
499
|
+
file: resolvedFile,
|
|
500
|
+
source
|
|
501
|
+
});
|
|
510
502
|
}
|
|
511
|
-
|
|
512
|
-
|
|
503
|
+
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
504
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
505
|
+
const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
506
|
+
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
|
|
507
|
+
const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
|
|
508
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
509
|
+
if (seen.has(key)) continue;
|
|
510
|
+
seen.add(key);
|
|
511
|
+
entries.push({
|
|
512
|
+
file: resolvedFile,
|
|
513
|
+
source: cssSource.css
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return entries;
|
|
513
517
|
}
|
|
514
518
|
//#endregion
|
|
515
|
-
//#region src/
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
519
|
+
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
520
|
+
function createReplayCssAsset(fileName, source) {
|
|
521
|
+
return {
|
|
522
|
+
type: "asset",
|
|
523
|
+
fileName,
|
|
524
|
+
name: void 0,
|
|
525
|
+
source,
|
|
526
|
+
needsCodeReference: false,
|
|
527
|
+
names: [],
|
|
528
|
+
originalFileName: null,
|
|
529
|
+
originalFileNames: []
|
|
530
|
+
};
|
|
520
531
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
"
|
|
524
|
-
"less",
|
|
525
|
-
"styl",
|
|
526
|
-
"stylus"
|
|
527
|
-
]);
|
|
528
|
-
const INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
529
|
-
const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
530
|
-
const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
531
|
-
const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
532
|
-
const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
|
|
533
|
-
function isPreprocessorRequest(id, lang) {
|
|
534
|
-
const normalizedLang = lang?.toLowerCase();
|
|
535
|
-
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
536
|
-
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
537
|
-
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
538
|
-
return PREPROCESSOR_EXT_RE.test(id);
|
|
532
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
533
|
+
const candidate = error;
|
|
534
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
539
535
|
}
|
|
540
|
-
function
|
|
541
|
-
|
|
536
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
537
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
538
|
+
for (const dependency of dependencies ?? []) try {
|
|
539
|
+
ctx.addWatchFile(dependency);
|
|
540
|
+
} catch (error) {
|
|
541
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
542
|
+
_weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
throw error;
|
|
546
|
+
}
|
|
542
547
|
}
|
|
543
|
-
|
|
544
|
-
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
550
|
+
function createCssAssetEmitter(context) {
|
|
551
|
+
return (fileName, source) => {
|
|
552
|
+
if (context.emitFile) {
|
|
553
|
+
context.emitFile({
|
|
554
|
+
type: "asset",
|
|
555
|
+
fileName,
|
|
556
|
+
source
|
|
557
|
+
});
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
return createReplayCssAsset(fileName, source);
|
|
561
|
+
};
|
|
545
562
|
}
|
|
546
|
-
function
|
|
547
|
-
return
|
|
563
|
+
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
564
|
+
return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
|
|
548
565
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
568
|
+
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
569
|
+
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
570
|
+
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
571
|
+
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
572
|
+
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
573
|
+
".wxss",
|
|
574
|
+
".acss",
|
|
575
|
+
".ttss",
|
|
576
|
+
".qss",
|
|
577
|
+
".jxss",
|
|
578
|
+
".tyss"
|
|
579
|
+
];
|
|
580
|
+
function resolveCssOutputRealPath(value) {
|
|
581
|
+
const resolved = node_path.default.resolve(value);
|
|
582
|
+
let current = resolved;
|
|
583
|
+
const pendingSegments = [];
|
|
584
|
+
while (!(0, node_fs.existsSync)(current)) {
|
|
585
|
+
const parent = node_path.default.dirname(current);
|
|
586
|
+
if (parent === current) return resolved;
|
|
587
|
+
pendingSegments.unshift(node_path.default.basename(current));
|
|
588
|
+
current = parent;
|
|
566
589
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
573
|
-
componentLocalStyleEnabled = true;
|
|
574
|
-
return true;
|
|
575
|
-
}
|
|
576
|
-
if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
|
|
577
|
-
const root = getResolvedConfig()?.root;
|
|
578
|
-
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
579
|
-
return componentLocalStyleEnabled;
|
|
590
|
+
try {
|
|
591
|
+
const realPath = node_fs.realpathSync.native(current);
|
|
592
|
+
return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
|
|
593
|
+
} catch {
|
|
594
|
+
return resolved;
|
|
580
595
|
}
|
|
581
|
-
|
|
582
|
-
|
|
596
|
+
}
|
|
597
|
+
function normalizeStyleOutputExtension(value) {
|
|
598
|
+
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
599
|
+
const normalized = value.trim().toLowerCase();
|
|
600
|
+
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
601
|
+
}
|
|
602
|
+
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
603
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
604
|
+
if (!cssMatcher?.(cleanFile)) return;
|
|
605
|
+
const ext = node_path.default.extname(cleanFile);
|
|
606
|
+
if (!ext || ext === ".css") return;
|
|
607
|
+
return ext;
|
|
608
|
+
}
|
|
609
|
+
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
610
|
+
let extension;
|
|
611
|
+
for (const file of files ?? []) {
|
|
612
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
613
|
+
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
614
|
+
if (!matchedExtension) continue;
|
|
615
|
+
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
616
|
+
if (extension && extension !== matchedExtension) return;
|
|
617
|
+
extension = matchedExtension;
|
|
583
618
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
603
|
-
postcssOptions: { options: {
|
|
604
|
-
from: id,
|
|
605
|
-
map: {
|
|
606
|
-
inline: false,
|
|
607
|
-
annotation: false,
|
|
608
|
-
sourcesContent: true
|
|
609
|
-
}
|
|
610
|
-
} }
|
|
611
|
-
});
|
|
612
|
-
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
613
|
-
}
|
|
614
|
-
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
615
|
-
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
616
|
-
for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
|
|
617
|
-
const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
|
|
618
|
-
return {
|
|
619
|
-
code: postcssResult.css,
|
|
620
|
-
map: postcssMap
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
const cssPlugins = [{
|
|
625
|
-
name: "weapp-tailwindcss:uni-app-x:css",
|
|
626
|
-
async transform(code, id) {
|
|
627
|
-
await runtimeState.readyPromise;
|
|
628
|
-
return transformStyle(code, id, void 0, this);
|
|
629
|
-
}
|
|
630
|
-
}, {
|
|
631
|
-
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
632
|
-
enforce: "pre",
|
|
633
|
-
async transform(code, id) {
|
|
634
|
-
await runtimeState.readyPromise;
|
|
635
|
-
const { query } = parseVueRequest(id);
|
|
636
|
-
const lang = query.lang;
|
|
637
|
-
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
638
|
-
return transformStyle(code, id, query, this);
|
|
639
|
-
}
|
|
640
|
-
}];
|
|
641
|
-
const nvuePlugin = {
|
|
642
|
-
name: "weapp-tailwindcss:uni-app-x:nvue",
|
|
643
|
-
enforce: "pre",
|
|
644
|
-
async buildStart() {
|
|
645
|
-
await ensureRuntimeClassSet(true);
|
|
646
|
-
},
|
|
647
|
-
async transform(code, id) {
|
|
648
|
-
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
649
|
-
rememberHarmonyApplySource(code);
|
|
650
|
-
const resolvedConfig = getResolvedConfig();
|
|
651
|
-
const isServeCommand = resolvedConfig?.command === "serve";
|
|
652
|
-
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
653
|
-
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
654
|
-
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
655
|
-
const transformUVue = await loadTransformUVue();
|
|
656
|
-
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
657
|
-
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
658
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
|
|
659
|
-
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
660
|
-
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
661
|
-
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
662
|
-
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
663
|
-
}));
|
|
664
|
-
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
665
|
-
},
|
|
666
|
-
async handleHotUpdate(ctx) {
|
|
667
|
-
if (getResolvedConfig()?.command !== "serve") return;
|
|
668
|
-
if (!UVUE_NVUE_RE.test(ctx.file)) return;
|
|
669
|
-
await ensureRuntimeClassSet(true);
|
|
670
|
-
},
|
|
671
|
-
async watchChange(id) {
|
|
672
|
-
const resolvedConfig = getResolvedConfig();
|
|
673
|
-
if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
|
|
674
|
-
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
675
|
-
await ensureRuntimeClassSet(true);
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
const stylePlaceholderPlugin = {
|
|
679
|
-
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
680
|
-
enforce: "post",
|
|
681
|
-
generateBundle: {
|
|
682
|
-
order: "post",
|
|
683
|
-
async handler(_options, bundle) {
|
|
684
|
-
const currentUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
685
|
-
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
686
|
-
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
687
|
-
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
688
|
-
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
689
|
-
if (isHarmonyTarget) {
|
|
690
|
-
const cssSources = [];
|
|
691
|
-
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
692
|
-
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
693
|
-
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
694
|
-
const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
|
|
695
|
-
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
696
|
-
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
697
|
-
}
|
|
698
|
-
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
699
|
-
cssSources,
|
|
700
|
-
excludeComponents: shouldEnableComponentLocalStyle()
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
for (const [file, item] of Object.entries(bundle)) {
|
|
704
|
-
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
705
|
-
const currentSource = String(item.source);
|
|
706
|
-
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
707
|
-
if (nextSource !== currentSource) item.source = nextSource;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
return [
|
|
713
|
-
...cssPlugins,
|
|
714
|
-
nvuePlugin,
|
|
715
|
-
stylePlaceholderPlugin
|
|
716
|
-
];
|
|
717
|
-
}
|
|
718
|
-
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
719
|
-
return async () => {
|
|
720
|
-
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
721
|
-
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
|
|
722
|
-
const rawSource = originalSource.source.toString();
|
|
723
|
-
await require_hmr_timing.processCachedTask({
|
|
724
|
-
cache,
|
|
725
|
-
cacheKey: file,
|
|
726
|
-
hashKey,
|
|
727
|
-
rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
|
|
728
|
-
applyResult(source) {
|
|
729
|
-
originalSource.source = source;
|
|
730
|
-
},
|
|
731
|
-
onCacheHit() {
|
|
732
|
-
debug("js cache hit: %s", file);
|
|
733
|
-
},
|
|
734
|
-
async transform() {
|
|
735
|
-
const currentSource = originalSource.source.toString();
|
|
736
|
-
const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
|
|
737
|
-
uniAppX: resolveUniAppXJsTransformEnabled$1(options.uniAppX),
|
|
738
|
-
babelParserOptions: {
|
|
739
|
-
plugins: ["typescript"],
|
|
740
|
-
sourceType: "unambiguous"
|
|
741
|
-
}
|
|
742
|
-
}));
|
|
743
|
-
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
744
|
-
onUpdate(file, currentSource, nextCode);
|
|
745
|
-
debug("js handle: %s", file);
|
|
746
|
-
applyLinkedResults(linked);
|
|
747
|
-
return { result: nextCode };
|
|
748
|
-
}
|
|
749
|
-
});
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
753
|
-
"uni-ad-draw",
|
|
754
|
-
"uni-ad-fullscreen-video",
|
|
755
|
-
"uni-ad-interactive",
|
|
756
|
-
"uni-ad-interstitial",
|
|
757
|
-
"uni-ad-rewarded-video",
|
|
758
|
-
"uni-ad",
|
|
759
|
-
"uni-animation-view",
|
|
760
|
-
"uni-audio",
|
|
761
|
-
"uni-block",
|
|
762
|
-
"uni-button",
|
|
763
|
-
"uni-camera",
|
|
764
|
-
"uni-canvas",
|
|
765
|
-
"uni-checkbox-group",
|
|
766
|
-
"uni-checkbox",
|
|
767
|
-
"uni-cover-image",
|
|
768
|
-
"uni-cover-view",
|
|
769
|
-
"uni-custom-tab-bar",
|
|
770
|
-
"uni-editor",
|
|
771
|
-
"uni-form",
|
|
772
|
-
"uni-icon",
|
|
773
|
-
"uni-image",
|
|
774
|
-
"uni-input",
|
|
775
|
-
"uni-label",
|
|
776
|
-
"uni-list-item",
|
|
777
|
-
"uni-list-view",
|
|
778
|
-
"uni-live-player",
|
|
779
|
-
"uni-live-pusher",
|
|
780
|
-
"uni-map",
|
|
781
|
-
"uni-match-media",
|
|
782
|
-
"uni-movable-area",
|
|
783
|
-
"uni-movable-view",
|
|
784
|
-
"uni-navigation-bar",
|
|
785
|
-
"uni-navigator",
|
|
786
|
-
"uni-open-data",
|
|
787
|
-
"uni-page-meta",
|
|
788
|
-
"uni-picker-view",
|
|
789
|
-
"uni-picker",
|
|
790
|
-
"uni-progress",
|
|
791
|
-
"uni-radio-group",
|
|
792
|
-
"uni-radio",
|
|
793
|
-
"uni-rich-text",
|
|
794
|
-
"uni-scroll-view",
|
|
795
|
-
"uni-slider",
|
|
796
|
-
"uni-sticky-header",
|
|
797
|
-
"uni-sticky-section",
|
|
798
|
-
"uni-swiper-item",
|
|
799
|
-
"uni-swiper",
|
|
800
|
-
"uni-switch",
|
|
801
|
-
"uni-template",
|
|
802
|
-
"uni-text",
|
|
803
|
-
"uni-textarea",
|
|
804
|
-
"uni-unicloud-db",
|
|
805
|
-
"uni-video",
|
|
806
|
-
"uni-view",
|
|
807
|
-
"uni-web-view"
|
|
808
|
-
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
809
|
-
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
810
|
-
function withUniAppXWebPreflightReset(css, enabled) {
|
|
811
|
-
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
812
|
-
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
813
|
-
}
|
|
814
|
-
//#endregion
|
|
815
|
-
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
816
|
-
function collectConfiguredTailwindV4CssSources(opts) {
|
|
817
|
-
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
818
|
-
return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
819
|
-
}
|
|
820
|
-
function collectExplicitTailwindV4CssEntries(opts) {
|
|
821
|
-
const entries = [
|
|
822
|
-
...opts.cssEntries ?? [],
|
|
823
|
-
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
824
|
-
...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
825
|
-
];
|
|
826
|
-
return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
|
|
827
|
-
}
|
|
828
|
-
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
829
|
-
const entries = [];
|
|
830
|
-
const seen = /* @__PURE__ */ new Set();
|
|
831
|
-
const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
|
|
832
|
-
for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
|
|
833
|
-
if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
|
|
834
|
-
const resolvedFile = node_path.default.isAbsolute(cssEntry) ? node_path.default.resolve(cssEntry) : node_path.default.resolve(fallbackBase, cssEntry);
|
|
835
|
-
if (!(0, node_fs.existsSync)(resolvedFile)) continue;
|
|
836
|
-
const source = (0, node_fs.readFileSync)(resolvedFile, "utf8");
|
|
837
|
-
const key = `${resolvedFile}\0${source}`;
|
|
838
|
-
if (seen.has(key)) continue;
|
|
839
|
-
seen.add(key);
|
|
840
|
-
entries.push({
|
|
841
|
-
file: resolvedFile,
|
|
842
|
-
source
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
846
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
847
|
-
const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
848
|
-
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
|
|
849
|
-
const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
|
|
850
|
-
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
851
|
-
if (seen.has(key)) continue;
|
|
852
|
-
seen.add(key);
|
|
853
|
-
entries.push({
|
|
854
|
-
file: resolvedFile,
|
|
855
|
-
source: cssSource.css
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
return entries;
|
|
859
|
-
}
|
|
860
|
-
//#endregion
|
|
861
|
-
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
862
|
-
function createReplayCssAsset(fileName, source) {
|
|
863
|
-
return {
|
|
864
|
-
type: "asset",
|
|
865
|
-
fileName,
|
|
866
|
-
name: void 0,
|
|
867
|
-
source,
|
|
868
|
-
needsCodeReference: false,
|
|
869
|
-
names: [],
|
|
870
|
-
originalFileName: null,
|
|
871
|
-
originalFileNames: []
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
875
|
-
const candidate = error;
|
|
876
|
-
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
877
|
-
}
|
|
878
|
-
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
879
|
-
if (typeof ctx.addWatchFile !== "function") return;
|
|
880
|
-
for (const dependency of dependencies ?? []) try {
|
|
881
|
-
ctx.addWatchFile(dependency);
|
|
882
|
-
} catch (error) {
|
|
883
|
-
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
884
|
-
_weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
885
|
-
continue;
|
|
886
|
-
}
|
|
887
|
-
throw error;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
//#endregion
|
|
891
|
-
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
892
|
-
function createCssAssetEmitter(context) {
|
|
893
|
-
return (fileName, source) => {
|
|
894
|
-
if (context.emitFile) {
|
|
895
|
-
context.emitFile({
|
|
896
|
-
type: "asset",
|
|
897
|
-
fileName,
|
|
898
|
-
source
|
|
899
|
-
});
|
|
900
|
-
return;
|
|
901
|
-
}
|
|
902
|
-
return createReplayCssAsset(fileName, source);
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
906
|
-
return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
|
|
907
|
-
}
|
|
908
|
-
//#endregion
|
|
909
|
-
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
910
|
-
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
911
|
-
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
912
|
-
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
913
|
-
const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
|
|
914
|
-
const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
915
|
-
".wxss",
|
|
916
|
-
".acss",
|
|
917
|
-
".ttss",
|
|
918
|
-
".qss",
|
|
919
|
-
".jxss",
|
|
920
|
-
".tyss"
|
|
921
|
-
];
|
|
922
|
-
function resolveCssOutputRealPath(value) {
|
|
923
|
-
const resolved = node_path.default.resolve(value);
|
|
924
|
-
let current = resolved;
|
|
925
|
-
const pendingSegments = [];
|
|
926
|
-
while (!(0, node_fs.existsSync)(current)) {
|
|
927
|
-
const parent = node_path.default.dirname(current);
|
|
928
|
-
if (parent === current) return resolved;
|
|
929
|
-
pendingSegments.unshift(node_path.default.basename(current));
|
|
930
|
-
current = parent;
|
|
931
|
-
}
|
|
932
|
-
try {
|
|
933
|
-
const realPath = node_fs.realpathSync.native(current);
|
|
934
|
-
return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
|
|
935
|
-
} catch {
|
|
936
|
-
return resolved;
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
function normalizeStyleOutputExtension(value) {
|
|
940
|
-
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
941
|
-
const normalized = value.trim().toLowerCase();
|
|
942
|
-
return normalized.startsWith(".") ? normalized : `.${normalized}`;
|
|
943
|
-
}
|
|
944
|
-
function getMatchedStyleOutputExtension(file, cssMatcher) {
|
|
945
|
-
const cleanFile = file.replace(/[?#].*$/, "");
|
|
946
|
-
if (!cssMatcher?.(cleanFile)) return;
|
|
947
|
-
const ext = node_path.default.extname(cleanFile);
|
|
948
|
-
if (!ext || ext === ".css") return;
|
|
949
|
-
return ext;
|
|
950
|
-
}
|
|
951
|
-
function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
|
|
952
|
-
let extension;
|
|
953
|
-
for (const file of files ?? []) {
|
|
954
|
-
const cleanFile = file.replace(/[?#].*$/, "");
|
|
955
|
-
const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
|
|
956
|
-
if (!matchedExtension) continue;
|
|
957
|
-
if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
|
|
958
|
-
if (extension && extension !== matchedExtension) return;
|
|
959
|
-
extension = matchedExtension;
|
|
960
|
-
}
|
|
961
|
-
return extension;
|
|
962
|
-
}
|
|
963
|
-
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
964
|
-
if (!cssMatcher || !stem) return;
|
|
965
|
-
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
966
|
-
}
|
|
967
|
-
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
968
|
-
const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
|
|
969
|
-
const stemSuffix = `/${cleanStem}`;
|
|
970
|
-
const matchedFiles = /* @__PURE__ */ new Set();
|
|
971
|
-
for (const file of files ?? []) {
|
|
972
|
-
const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
973
|
-
if (!cssMatcher?.(cleanFile)) continue;
|
|
974
|
-
const extension = node_path.default.extname(cleanFile);
|
|
975
|
-
if (!extension || extension === ".css") continue;
|
|
976
|
-
const outputStem = cleanFile.slice(0, -extension.length);
|
|
977
|
-
const outputStemSuffix = `/${outputStem}`;
|
|
978
|
-
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
619
|
+
return extension;
|
|
620
|
+
}
|
|
621
|
+
function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
622
|
+
if (!cssMatcher || !stem) return;
|
|
623
|
+
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
624
|
+
}
|
|
625
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
626
|
+
const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
|
|
627
|
+
const stemSuffix = `/${cleanStem}`;
|
|
628
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
629
|
+
for (const file of files ?? []) {
|
|
630
|
+
const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
631
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
632
|
+
const extension = node_path.default.extname(cleanFile);
|
|
633
|
+
if (!extension || extension === ".css") continue;
|
|
634
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
635
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
636
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
979
637
|
}
|
|
980
638
|
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
981
639
|
}
|
|
@@ -1242,18 +900,21 @@ function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
|
1242
900
|
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
1243
901
|
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
1244
902
|
}
|
|
1245
|
-
function shouldKeepRootMiniProgramStyleAsImportShell(
|
|
1246
|
-
return
|
|
903
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(enabled) {
|
|
904
|
+
return enabled === true;
|
|
1247
905
|
}
|
|
1248
|
-
function shouldMoveRootMiniProgramStyleToImportShellOrigin(
|
|
1249
|
-
return
|
|
906
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(enabled) {
|
|
907
|
+
return enabled === true;
|
|
1250
908
|
}
|
|
1251
909
|
//#endregion
|
|
1252
910
|
//#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
|
|
1253
911
|
function resolveCssBundleOutputFile(options) {
|
|
1254
|
-
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
|
|
912
|
+
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, pipelineContext, cssPipelineStrategy, shouldPreserveAppCssExtension } = options;
|
|
1255
913
|
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
1256
|
-
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(
|
|
914
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
915
|
+
...pipelineContext,
|
|
916
|
+
file
|
|
917
|
+
}))) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
1257
918
|
return outputFile;
|
|
1258
919
|
}
|
|
1259
920
|
function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile = file, cssMatcher) {
|
|
@@ -1291,12 +952,16 @@ function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAsset
|
|
|
1291
952
|
return false;
|
|
1292
953
|
}
|
|
1293
954
|
function applyCssResultToBundle(options) {
|
|
1294
|
-
const {
|
|
955
|
+
const { assetSourceFile, bundle, cssPipelineStrategy, emitOrReplayCssAsset, file, originalSource, outputFile, pipelineContext, source, viteProcessedCssAsset } = options;
|
|
1295
956
|
if (outputFile === file) {
|
|
1296
957
|
originalSource.source = source;
|
|
1297
958
|
return;
|
|
1298
959
|
}
|
|
1299
|
-
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(
|
|
960
|
+
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
961
|
+
...pipelineContext,
|
|
962
|
+
css: source,
|
|
963
|
+
file
|
|
964
|
+
})) ? createCssImportShell$1(file, outputFile) : void 0;
|
|
1300
965
|
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
1301
966
|
const existingOutput = bundle[outputFile];
|
|
1302
967
|
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
@@ -1763,7 +1428,7 @@ const basename = function(p, extension) {
|
|
|
1763
1428
|
}
|
|
1764
1429
|
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
1765
1430
|
};
|
|
1766
|
-
const parse = function(p) {
|
|
1431
|
+
const parse$1 = function(p) {
|
|
1767
1432
|
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
1768
1433
|
const base = basename(p);
|
|
1769
1434
|
const extension = extname(base);
|
|
@@ -1789,7 +1454,7 @@ const _path = {
|
|
|
1789
1454
|
matchesGlob,
|
|
1790
1455
|
normalize,
|
|
1791
1456
|
normalizeString,
|
|
1792
|
-
parse,
|
|
1457
|
+
parse: parse$1,
|
|
1793
1458
|
relative,
|
|
1794
1459
|
resolve,
|
|
1795
1460
|
sep: "/",
|
|
@@ -1821,20 +1486,66 @@ const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
|
1821
1486
|
".svelte",
|
|
1822
1487
|
".mpx"
|
|
1823
1488
|
];
|
|
1824
|
-
const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]
|
|
1825
|
-
|
|
1489
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1490
|
+
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1491
|
+
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1492
|
+
function extractSfcStyleBlocks(source) {
|
|
1826
1493
|
const styleSources = [];
|
|
1827
1494
|
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1495
|
+
let index = 0;
|
|
1828
1496
|
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1829
1497
|
while (match !== null) {
|
|
1830
|
-
|
|
1498
|
+
const attrs = match[1] ?? "";
|
|
1499
|
+
styleSources.push({
|
|
1500
|
+
attrs,
|
|
1501
|
+
index,
|
|
1502
|
+
scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
|
|
1503
|
+
source: match[2] ?? ""
|
|
1504
|
+
});
|
|
1505
|
+
index += 1;
|
|
1831
1506
|
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1832
1507
|
}
|
|
1833
1508
|
return styleSources;
|
|
1834
1509
|
}
|
|
1510
|
+
function extractSfcStyleSources(source) {
|
|
1511
|
+
return extractSfcStyleBlocks(source).map((style) => style.source);
|
|
1512
|
+
}
|
|
1835
1513
|
function hasSfcStyleSources(source) {
|
|
1836
1514
|
return extractSfcStyleSources(source).length > 0;
|
|
1837
1515
|
}
|
|
1516
|
+
function resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks) {
|
|
1517
|
+
const scopedStyleBlock = styleBlocks.find((style) => style.scoped);
|
|
1518
|
+
return scopedStyleBlock ? `${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true` : sourceFile;
|
|
1519
|
+
}
|
|
1520
|
+
function normalizeSfcStyleSourceForCompare(source) {
|
|
1521
|
+
return source.replace(/\r\n?/g, "\n").trim();
|
|
1522
|
+
}
|
|
1523
|
+
function resolveSfcStyleBlockLang(attrs) {
|
|
1524
|
+
const match = SFC_LANG_STYLE_ATTR_RE.exec(attrs);
|
|
1525
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
1526
|
+
}
|
|
1527
|
+
function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
1528
|
+
const params = new URLSearchParams();
|
|
1529
|
+
params.set("vue", "");
|
|
1530
|
+
params.set("type", "style");
|
|
1531
|
+
params.set("index", String(styleBlock.index));
|
|
1532
|
+
if (styleBlock.scoped) params.set("scoped", "true");
|
|
1533
|
+
const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
|
|
1534
|
+
if (lang) params.set("lang", lang);
|
|
1535
|
+
return `${sourceFile}?${params.toString()}`;
|
|
1536
|
+
}
|
|
1537
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource) {
|
|
1538
|
+
if (!sfcSource) return sourceFile;
|
|
1539
|
+
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
1540
|
+
if (styleBlocks.length === 0) return sourceFile;
|
|
1541
|
+
const normalizedStyleSource = normalizeSfcStyleSourceForCompare(styleSource);
|
|
1542
|
+
const matchedBlocks = styleBlocks.filter((styleBlock) => {
|
|
1543
|
+
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
1544
|
+
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
1545
|
+
});
|
|
1546
|
+
const styleBlock = matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0;
|
|
1547
|
+
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1548
|
+
}
|
|
1838
1549
|
function hasTailwindGenerationSource(source, options = {}) {
|
|
1839
1550
|
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1840
1551
|
return require_v4_engine.hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source);
|
|
@@ -1854,7 +1565,8 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1854
1565
|
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1855
1566
|
return;
|
|
1856
1567
|
}
|
|
1857
|
-
const
|
|
1568
|
+
const styleBlocks = extractSfcStyleBlocks(source);
|
|
1569
|
+
const rawSource = styleBlocks.map((style) => style.source).join("\n");
|
|
1858
1570
|
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1859
1571
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1860
1572
|
return;
|
|
@@ -1863,7 +1575,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1863
1575
|
return {
|
|
1864
1576
|
outputFile,
|
|
1865
1577
|
rawSource,
|
|
1866
|
-
sourceFile
|
|
1578
|
+
sourceFile: resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks)
|
|
1867
1579
|
};
|
|
1868
1580
|
}
|
|
1869
1581
|
function normalizeSfcSourceFileForCompare(file) {
|
|
@@ -2065,6 +1777,13 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
2065
1777
|
//#endregion
|
|
2066
1778
|
//#region src/bundlers/vite/processed-css-assets.ts
|
|
2067
1779
|
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
1780
|
+
function createCssAssetPipelineContext(options, file, bundle) {
|
|
1781
|
+
const context = options.createCssPipelineContext?.(file);
|
|
1782
|
+
return context ? {
|
|
1783
|
+
...context,
|
|
1784
|
+
bundle
|
|
1785
|
+
} : void 0;
|
|
1786
|
+
}
|
|
2068
1787
|
function isCssOutputFile(file) {
|
|
2069
1788
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
2070
1789
|
}
|
|
@@ -2239,14 +1958,17 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
|
|
|
2239
1958
|
return removed;
|
|
2240
1959
|
}
|
|
2241
1960
|
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
1961
|
+
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
2242
1962
|
function hasVueScopedAttr(value) {
|
|
2243
1963
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2244
|
-
|
|
1964
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
1965
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
|
|
2245
1966
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
1967
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
2246
1968
|
return matched;
|
|
2247
1969
|
}
|
|
2248
1970
|
function normalizeCssSignatureValue(value) {
|
|
2249
|
-
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
1971
|
+
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();
|
|
2250
1972
|
}
|
|
2251
1973
|
function createDeclarationSignature(rule) {
|
|
2252
1974
|
return createDeclarationKeys(rule).sort().join(";");
|
|
@@ -2273,6 +1995,33 @@ function isLikelyTailwindGlobalRule(rule) {
|
|
|
2273
1995
|
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
2274
1996
|
return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
2275
1997
|
}
|
|
1998
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
1999
|
+
"view",
|
|
2000
|
+
"text",
|
|
2001
|
+
"::after",
|
|
2002
|
+
"::before"
|
|
2003
|
+
]);
|
|
2004
|
+
const MINI_PROGRAM_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
2005
|
+
"box-sizing",
|
|
2006
|
+
"margin",
|
|
2007
|
+
"padding",
|
|
2008
|
+
"border"
|
|
2009
|
+
]);
|
|
2010
|
+
function isMiniProgramTailwindPreflightDeclaration(decl) {
|
|
2011
|
+
return decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop);
|
|
2012
|
+
}
|
|
2013
|
+
function isUnscopedMiniProgramTailwindPreflightRule(rule) {
|
|
2014
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2015
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
2016
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2017
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
2018
|
+
})) return false;
|
|
2019
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2020
|
+
return declarations.length > 0 && declarations.every(isMiniProgramTailwindPreflightDeclaration);
|
|
2021
|
+
}
|
|
2022
|
+
function hasUnscopedMiniProgramTailwindPreflightRule(css) {
|
|
2023
|
+
return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
|
|
2024
|
+
}
|
|
2276
2025
|
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2277
2026
|
const rules = /* @__PURE__ */ new Set();
|
|
2278
2027
|
const atRules = /* @__PURE__ */ new Set();
|
|
@@ -2314,8 +2063,9 @@ function isRuleCoveredByRootCss(rule, coverage) {
|
|
|
2314
2063
|
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2315
2064
|
if (!hasVueScopedAttr(css)) return css;
|
|
2316
2065
|
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2066
|
+
const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
|
|
2317
2067
|
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2318
|
-
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
|
|
2068
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight) return css;
|
|
2319
2069
|
try {
|
|
2320
2070
|
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2321
2071
|
let changed = false;
|
|
@@ -2326,7 +2076,7 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
|
2326
2076
|
}
|
|
2327
2077
|
});
|
|
2328
2078
|
root.walkRules((rule) => {
|
|
2329
|
-
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
|
|
2079
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule)) {
|
|
2330
2080
|
rule.remove();
|
|
2331
2081
|
changed = true;
|
|
2332
2082
|
}
|
|
@@ -2425,11 +2175,17 @@ function isRootStyleOutputFile(file) {
|
|
|
2425
2175
|
function isMiniProgramStyleOutputFile(file) {
|
|
2426
2176
|
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2427
2177
|
}
|
|
2428
|
-
function shouldPreserveMiniProgramImportShell(
|
|
2429
|
-
|
|
2178
|
+
function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
|
|
2179
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2180
|
+
return context !== void 0 && options.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
2181
|
+
...context,
|
|
2182
|
+
css,
|
|
2183
|
+
file
|
|
2184
|
+
}) === true && isMiniProgramStyleOutputFile(file) && options.opts.cssMatcher(file) && (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(css);
|
|
2430
2185
|
}
|
|
2431
|
-
function resolvePreservedImportShellInjectionTarget(
|
|
2432
|
-
|
|
2186
|
+
function resolvePreservedImportShellInjectionTarget(options, bundle, file, css) {
|
|
2187
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2188
|
+
if (context === void 0 || options.cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(context) !== true) return;
|
|
2433
2189
|
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2434
2190
|
if (importedStyleFiles.size !== 1) return;
|
|
2435
2191
|
const [importedFile] = importedStyleFiles;
|
|
@@ -2441,15 +2197,25 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
|
2441
2197
|
if (require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2442
2198
|
}
|
|
2443
2199
|
}
|
|
2444
|
-
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
2200
|
+
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bundle) {
|
|
2201
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2445
2202
|
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2446
2203
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2447
2204
|
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
2448
2205
|
const matchedRootWebOutputTargets = records.map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile)).filter((outputFile) => opts.mainCssChunkMatcher(outputFile, opts.appType));
|
|
2449
|
-
if (
|
|
2206
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferMatchedRootWebOutputTarget?.({
|
|
2207
|
+
...context,
|
|
2208
|
+
file,
|
|
2209
|
+
matchedRootWebOutputTargets
|
|
2210
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2450
2211
|
const explicitRootTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2451
2212
|
const explicitWebCssTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isCssOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2452
|
-
if (
|
|
2213
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferExplicitWebCssTargets?.({
|
|
2214
|
+
...context,
|
|
2215
|
+
explicitRootTargets,
|
|
2216
|
+
explicitWebCssTargets,
|
|
2217
|
+
file
|
|
2218
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2453
2219
|
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2454
2220
|
if (records.some((record) => {
|
|
2455
2221
|
if (record.injectIntoMain !== true) return false;
|
|
@@ -2489,7 +2255,7 @@ function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, record
|
|
|
2489
2255
|
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
|
|
2490
2256
|
if (!isRecordFile && !isProcessedSource) continue;
|
|
2491
2257
|
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2492
|
-
if (candidateIsRootWebStyle && !isRecordFile) continue;
|
|
2258
|
+
if (candidateIsRootWebStyle && !isRecordFile && !isProcessedSource) continue;
|
|
2493
2259
|
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2494
2260
|
else clearAssetSource(candidateOutput);
|
|
2495
2261
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
@@ -2541,8 +2307,22 @@ function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
|
2541
2307
|
const fileKey = normalizeComparableStyleFile(file);
|
|
2542
2308
|
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2543
2309
|
}
|
|
2544
|
-
function
|
|
2545
|
-
|
|
2310
|
+
function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
|
|
2311
|
+
const opts = options.opts;
|
|
2312
|
+
if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2313
|
+
const context = createCssAssetPipelineContext(options, outputFile, bundle);
|
|
2314
|
+
if (context === void 0) return;
|
|
2315
|
+
const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
2316
|
+
...context,
|
|
2317
|
+
bundle,
|
|
2318
|
+
isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
|
|
2319
|
+
isMiniProgramStyleOutputFile,
|
|
2320
|
+
isRootStyleOutputFile,
|
|
2321
|
+
outputFile,
|
|
2322
|
+
sourceFile
|
|
2323
|
+
});
|
|
2324
|
+
if (resolvedByStrategy !== void 0) return resolvedByStrategy;
|
|
2325
|
+
if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
|
|
2546
2326
|
const rootCssFiles = [];
|
|
2547
2327
|
const matchedRootCssFiles = [];
|
|
2548
2328
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -2609,7 +2389,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2609
2389
|
options.markCssAssetProcessed?.(output, file);
|
|
2610
2390
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2611
2391
|
const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
|
|
2612
|
-
const webviewRootCssInjectionTarget = options.opts ?
|
|
2392
|
+
const webviewRootCssInjectionTarget = options.opts ? resolveConfiguredCssEntryRootInjectionTarget(bundle, options, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
|
|
2613
2393
|
const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
|
|
2614
2394
|
if (singleMarkerFile && require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile))) {
|
|
2615
2395
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
@@ -2684,10 +2464,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2684
2464
|
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2685
2465
|
if (output.type !== "asset") continue;
|
|
2686
2466
|
let file = getAssetFile$1(bundleFile, output);
|
|
2687
|
-
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2467
|
+
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults, options, bundle)) continue;
|
|
2688
2468
|
let originalSource = readAssetSource$2(output);
|
|
2689
|
-
if (shouldPreserveMiniProgramImportShell(options
|
|
2690
|
-
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options
|
|
2469
|
+
if (shouldPreserveMiniProgramImportShell(options, bundle, file, originalSource)) {
|
|
2470
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options, bundle, file, originalSource);
|
|
2691
2471
|
if (typeof importedTargetFile === "string") {
|
|
2692
2472
|
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2693
2473
|
const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedTargetFile))?.[1];
|
|
@@ -3034,17 +2814,10 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
3034
2814
|
function readAssetSource(asset) {
|
|
3035
2815
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
3036
2816
|
}
|
|
3037
|
-
function isUniAppViteWebviewAppBundle(bundleFiles) {
|
|
3038
|
-
return bundleFiles.some((file) => node_path.default.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
3039
|
-
}
|
|
3040
|
-
function isUniAppViteWebviewOutDir$2(outDir) {
|
|
3041
|
-
const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
3042
|
-
return normalized === "app" || normalized === "app-plus";
|
|
3043
|
-
}
|
|
3044
2817
|
function getAssetFile(bundleFile, asset) {
|
|
3045
2818
|
return asset.fileName || bundleFile;
|
|
3046
2819
|
}
|
|
3047
|
-
function
|
|
2820
|
+
function finalizeWebviewCssCompat(bundle, options) {
|
|
3048
2821
|
if (options.opts.generator?.webCompat === false) return 0;
|
|
3049
2822
|
let transformed = 0;
|
|
3050
2823
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -3057,7 +2830,7 @@ function finalizeUniAppViteWebviewCssCompat(bundle, options) {
|
|
|
3057
2830
|
output.source = nextCss;
|
|
3058
2831
|
options.recordCssAssetResult?.(file, nextCss);
|
|
3059
2832
|
options.onUpdate(file, rawSource, nextCss);
|
|
3060
|
-
options.debug("finalize
|
|
2833
|
+
options.debug("finalize webview css compat: %s bytes=%d", file, nextCss.length);
|
|
3061
2834
|
transformed++;
|
|
3062
2835
|
}
|
|
3063
2836
|
return transformed;
|
|
@@ -3098,8 +2871,8 @@ function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
|
3098
2871
|
} catch {}
|
|
3099
2872
|
return importedFile;
|
|
3100
2873
|
}
|
|
3101
|
-
function
|
|
3102
|
-
if (options.
|
|
2874
|
+
function normalizeRootMiniProgramImportShellAssets(bundle, options) {
|
|
2875
|
+
if (!options.enabled) return 0;
|
|
3103
2876
|
let updated = 0;
|
|
3104
2877
|
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
3105
2878
|
if (rootOutput.type !== "asset") continue;
|
|
@@ -3110,6 +2883,17 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3110
2883
|
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile(bundleFile, output)) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile))?.[1];
|
|
3111
2884
|
if (originOutput?.type !== "asset") continue;
|
|
3112
2885
|
const rootSource = readAssetSource(rootOutput);
|
|
2886
|
+
const importedRootFile = resolveSingleCssImportOutputFile(rootFile, rootSource);
|
|
2887
|
+
if (importedRootFile && require_source_candidate_scan_signature.normalizeOutputPathKey(importedRootFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile)) {
|
|
2888
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2889
|
+
if (rootSource === nextRootSource) continue;
|
|
2890
|
+
rootOutput.source = nextRootSource;
|
|
2891
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2892
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2893
|
+
options.debug("normalize root css import shell request: %s -> %s", rootFile, originFile);
|
|
2894
|
+
updated++;
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
3113
2897
|
if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(rootSource)) continue;
|
|
3114
2898
|
const originSource = readAssetSource(originOutput);
|
|
3115
2899
|
if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(originSource)) {
|
|
@@ -3124,13 +2908,13 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3124
2908
|
options.recordCssAssetResult?.(originFile, rootSource);
|
|
3125
2909
|
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
3126
2910
|
options.onUpdate?.(originFile, originSource, rootSource);
|
|
3127
|
-
options.debug("normalize
|
|
2911
|
+
options.debug("normalize root css import shell: %s -> %s", rootFile, originFile);
|
|
3128
2912
|
updated++;
|
|
3129
2913
|
}
|
|
3130
2914
|
return updated;
|
|
3131
2915
|
}
|
|
3132
2916
|
async function finalizeGenerateBundle(options) {
|
|
3133
|
-
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;
|
|
2917
|
+
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;
|
|
3134
2918
|
const tasksStart = performance.now();
|
|
3135
2919
|
if (cssTaskFactories.length > 0) {
|
|
3136
2920
|
const cssTask = require_hmr_timing.runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -3159,6 +2943,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3159
2943
|
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
3160
2944
|
collectViteProcessedCssAssetResults(bundle, {
|
|
3161
2945
|
opts,
|
|
2946
|
+
cssPipelineStrategy,
|
|
2947
|
+
createCssPipelineContext,
|
|
3162
2948
|
isViteProcessedCssAsset,
|
|
3163
2949
|
markCssAssetProcessed,
|
|
3164
2950
|
recordCssAssetResult,
|
|
@@ -3170,6 +2956,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3170
2956
|
});
|
|
3171
2957
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3172
2958
|
opts,
|
|
2959
|
+
cssPipelineStrategy,
|
|
2960
|
+
createCssPipelineContext,
|
|
3173
2961
|
getViteProcessedCssAssetResults,
|
|
3174
2962
|
markCssAssetProcessed,
|
|
3175
2963
|
recordCssAssetResult,
|
|
@@ -3188,10 +2976,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3188
2976
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
3189
2977
|
syncViteProcessedCssIntoMainCssAssets();
|
|
3190
2978
|
}
|
|
3191
|
-
|
|
3192
|
-
|
|
2979
|
+
const createFinalizeCssPipelineContext = (file = "") => createCssPipelineContext?.(file);
|
|
2980
|
+
const finalizeCssPipelineContext = createFinalizeCssPipelineContext();
|
|
2981
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
3193
2982
|
cssMatcher: opts.cssMatcher,
|
|
3194
2983
|
debug,
|
|
2984
|
+
enabled: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(finalizeCssPipelineContext) === true,
|
|
3195
2985
|
onUpdate,
|
|
3196
2986
|
recordCssAssetResult
|
|
3197
2987
|
});
|
|
@@ -3199,13 +2989,23 @@ async function finalizeGenerateBundle(options) {
|
|
|
3199
2989
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
3200
2990
|
cssMatcher: opts.cssMatcher,
|
|
3201
2991
|
debug,
|
|
3202
|
-
includeTailwindGeneratedCssAssets:
|
|
2992
|
+
includeTailwindGeneratedCssAssets: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.includeTailwindGeneratedCssAssetsInRootCoverage?.({
|
|
2993
|
+
...finalizeCssPipelineContext,
|
|
2994
|
+
bundleFiles,
|
|
2995
|
+
isWebGeneratorTarget,
|
|
2996
|
+
outDir
|
|
2997
|
+
}) === true,
|
|
3203
2998
|
isViteProcessedCssAsset,
|
|
3204
2999
|
onUpdate,
|
|
3205
3000
|
recordCssAssetResult,
|
|
3206
3001
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
3207
3002
|
});
|
|
3208
|
-
if (
|
|
3003
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml?.({
|
|
3004
|
+
...finalizeCssPipelineContext,
|
|
3005
|
+
bundleFiles: Object.keys(bundle),
|
|
3006
|
+
isWebGeneratorTarget,
|
|
3007
|
+
outDir
|
|
3008
|
+
}) === true) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
3209
3009
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
3210
3010
|
cssMatcher: opts.cssMatcher,
|
|
3211
3011
|
debug,
|
|
@@ -3216,7 +3016,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3216
3016
|
recordCssAssetResult,
|
|
3217
3017
|
styleHandler
|
|
3218
3018
|
});
|
|
3219
|
-
if (
|
|
3019
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldApplyFinalWebviewCssCompat?.({
|
|
3020
|
+
...finalizeCssPipelineContext,
|
|
3021
|
+
bundleFiles: Object.keys(bundle),
|
|
3022
|
+
isWebGeneratorTarget,
|
|
3023
|
+
outDir
|
|
3024
|
+
}) === true) finalizeWebviewCssCompat(bundle, {
|
|
3220
3025
|
debug,
|
|
3221
3026
|
onUpdate,
|
|
3222
3027
|
opts,
|
|
@@ -3308,131 +3113,418 @@ function collectClassAttributeValues(source) {
|
|
|
3308
3113
|
break;
|
|
3309
3114
|
}
|
|
3310
3115
|
}
|
|
3311
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3116
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3117
|
+
}
|
|
3118
|
+
return values;
|
|
3119
|
+
}
|
|
3120
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
3121
|
+
const matches = /* @__PURE__ */ new Set();
|
|
3122
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
3123
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
3124
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
3125
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3126
|
+
while (quoted !== null) {
|
|
3127
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
3128
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
|
|
3129
|
+
const normalized = candidate.trim();
|
|
3130
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
3131
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
3132
|
+
matches.add(normalized);
|
|
3133
|
+
}
|
|
3134
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
return [...matches];
|
|
3138
|
+
}
|
|
3139
|
+
//#endregion
|
|
3140
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
3141
|
+
function processHtmlBundleEntry(options) {
|
|
3142
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
3143
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
3144
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3145
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3146
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
|
|
3147
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3148
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3149
|
+
const hashKey = cacheKey;
|
|
3150
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3151
|
+
tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
|
|
3152
|
+
cache,
|
|
3153
|
+
cacheKey,
|
|
3154
|
+
hashKey,
|
|
3155
|
+
hash: htmlProcessHash,
|
|
3156
|
+
applyResult(source) {
|
|
3157
|
+
originalSource.source = source;
|
|
3158
|
+
},
|
|
3159
|
+
onCacheHit() {
|
|
3160
|
+
metrics.html.cacheHits++;
|
|
3161
|
+
debug("html cache hit: %s", file);
|
|
3162
|
+
},
|
|
3163
|
+
async transform() {
|
|
3164
|
+
const start = performance.now();
|
|
3165
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
3166
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3167
|
+
let retryRuntimeSet;
|
|
3168
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
3169
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
3170
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
3171
|
+
retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
3172
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
3173
|
+
}
|
|
3174
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
3175
|
+
_weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3176
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3177
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3178
|
+
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3179
|
+
}
|
|
3180
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
3181
|
+
metrics.html.transformed++;
|
|
3182
|
+
onUpdate(file, rawSource, transformed);
|
|
3183
|
+
debug("html handle: %s", file);
|
|
3184
|
+
return { result: transformed };
|
|
3185
|
+
}
|
|
3186
|
+
})));
|
|
3187
|
+
}
|
|
3188
|
+
//#endregion
|
|
3189
|
+
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
3190
|
+
function createJsEntryResolver(jsEntries) {
|
|
3191
|
+
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
3192
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
|
|
3193
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
|
|
3194
|
+
}
|
|
3195
|
+
//#endregion
|
|
3196
|
+
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
3197
|
+
function resolveUniAppXJsTransformEnabled$1(uniAppX) {
|
|
3198
|
+
return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
3199
|
+
}
|
|
3200
|
+
function createJsHandlerOptionsFactory(options) {
|
|
3201
|
+
return (absoluteFilename, extra) => ({
|
|
3202
|
+
...extra,
|
|
3203
|
+
generateMap: false,
|
|
3204
|
+
filename: absoluteFilename,
|
|
3205
|
+
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
3206
|
+
moduleGraph: options.moduleGraph,
|
|
3207
|
+
babelParserOptions: {
|
|
3208
|
+
...extra?.babelParserOptions ?? {},
|
|
3209
|
+
sourceFilename: absoluteFilename
|
|
3210
|
+
}
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
//#endregion
|
|
3214
|
+
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
3215
|
+
function createLinkedUpdateHelpers(options) {
|
|
3216
|
+
const pendingLinkedUpdates = [];
|
|
3217
|
+
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
3218
|
+
options.onUpdate(fileName, previous, next);
|
|
3219
|
+
options.debug("js linked handle: %s", fileName);
|
|
3220
|
+
};
|
|
3221
|
+
const scheduleLinkedApply = (entry, code) => {
|
|
3222
|
+
pendingLinkedUpdates.push(() => {
|
|
3223
|
+
if (entry.output.type === "chunk") entry.output.code = code;
|
|
3224
|
+
else entry.output.source = code;
|
|
3225
|
+
});
|
|
3226
|
+
};
|
|
3227
|
+
const applyLinkedUpdates = (linked) => {
|
|
3228
|
+
require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
3229
|
+
};
|
|
3230
|
+
return {
|
|
3231
|
+
applyLinkedUpdates,
|
|
3232
|
+
pendingLinkedUpdates
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
3236
|
+
if (!linked || !linkedSet) return;
|
|
3237
|
+
for (const id of Object.keys(linked)) {
|
|
3238
|
+
const linkedEntry = getJsEntry(id);
|
|
3239
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
//#endregion
|
|
3243
|
+
//#region src/bundlers/vite/query.ts
|
|
3244
|
+
function parseVueRequest(id) {
|
|
3245
|
+
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
3246
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
3247
|
+
const query = Object.fromEntries(searchParams);
|
|
3248
|
+
if (query.vue != null) query.vue = true;
|
|
3249
|
+
if (query.index != null) query.index = Number(query.index);
|
|
3250
|
+
if (query.raw != null) query.raw = true;
|
|
3251
|
+
if (query.url != null) query.url = true;
|
|
3252
|
+
if (query.scoped != null) query.scoped = true;
|
|
3253
|
+
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
3254
|
+
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
3255
|
+
if (langType) query.lang = langType;
|
|
3256
|
+
return {
|
|
3257
|
+
filename,
|
|
3258
|
+
query
|
|
3259
|
+
};
|
|
3260
|
+
}
|
|
3261
|
+
//#endregion
|
|
3262
|
+
//#region src/uni-app-x/harmony.ts
|
|
3263
|
+
function isUniAppXHarmonyOutDir(outDir) {
|
|
3264
|
+
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
3265
|
+
}
|
|
3266
|
+
//#endregion
|
|
3267
|
+
//#region src/uni-app-x/style-isolation.ts
|
|
3268
|
+
const manifestCache = /* @__PURE__ */ new Map();
|
|
3269
|
+
function resolveUniAppXStyleIsolationEnabled(root) {
|
|
3270
|
+
if (!root) return false;
|
|
3271
|
+
const normalizedRoot = node_path.default.resolve(root);
|
|
3272
|
+
const cached = manifestCache.get(normalizedRoot);
|
|
3273
|
+
if (cached !== void 0) return cached;
|
|
3274
|
+
const manifestPath = node_path.default.join(normalizedRoot, "manifest.json");
|
|
3275
|
+
let enabled = false;
|
|
3276
|
+
try {
|
|
3277
|
+
enabled = `${(0, comment_json.parse)(node_fs.default.readFileSync(manifestPath, "utf8"))["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
|
|
3278
|
+
} catch {
|
|
3279
|
+
enabled = false;
|
|
3280
|
+
}
|
|
3281
|
+
manifestCache.set(normalizedRoot, enabled);
|
|
3282
|
+
return enabled;
|
|
3283
|
+
}
|
|
3284
|
+
//#endregion
|
|
3285
|
+
//#region src/uni-app-x/vite.ts
|
|
3286
|
+
let transformUVuePromise;
|
|
3287
|
+
function loadTransformUVue() {
|
|
3288
|
+
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-B0BxX3XB.js")).then((mod) => mod.transformUVue));
|
|
3289
|
+
return transformUVuePromise;
|
|
3290
|
+
}
|
|
3291
|
+
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
3292
|
+
"scss",
|
|
3293
|
+
"sass",
|
|
3294
|
+
"less",
|
|
3295
|
+
"styl",
|
|
3296
|
+
"stylus"
|
|
3297
|
+
]);
|
|
3298
|
+
const INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
3299
|
+
const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
3300
|
+
const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
3301
|
+
const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
3302
|
+
const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
|
|
3303
|
+
function isPreprocessorRequest(id, lang) {
|
|
3304
|
+
const normalizedLang = lang?.toLowerCase();
|
|
3305
|
+
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
3306
|
+
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
3307
|
+
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
3308
|
+
return PREPROCESSOR_EXT_RE.test(id);
|
|
3309
|
+
}
|
|
3310
|
+
function resolveUniAppXCssTarget(id) {
|
|
3311
|
+
return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
|
|
3312
|
+
}
|
|
3313
|
+
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
3314
|
+
return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
3315
|
+
}
|
|
3316
|
+
function isCssModuleExport(code) {
|
|
3317
|
+
return CSS_MODULE_EXPORT_RE.test(code);
|
|
3318
|
+
}
|
|
3319
|
+
function createUniAppXPlugins(options) {
|
|
3320
|
+
const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX } = options;
|
|
3321
|
+
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
|
|
3322
|
+
const utsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3323
|
+
const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
|
|
3324
|
+
const isHarmonyPlatform = utsPlatform.isAppHarmony;
|
|
3325
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
3326
|
+
let componentLocalStyleEnabled;
|
|
3327
|
+
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
3328
|
+
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
3329
|
+
function rememberHarmonyApplySource(code) {
|
|
3330
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
3331
|
+
if (styleSources.length === 0) return;
|
|
3332
|
+
for (const styleSource of styleSources) {
|
|
3333
|
+
harmonyApplyStyleSources.add(styleSource);
|
|
3334
|
+
for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
|
|
3335
|
+
}
|
|
3312
3336
|
}
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3337
|
+
function shouldEnableComponentLocalStyle() {
|
|
3338
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
|
|
3339
|
+
componentLocalStyleEnabled = false;
|
|
3340
|
+
return false;
|
|
3341
|
+
}
|
|
3342
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
3343
|
+
componentLocalStyleEnabled = true;
|
|
3344
|
+
return true;
|
|
3345
|
+
}
|
|
3346
|
+
if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
|
|
3347
|
+
const root = getResolvedConfig()?.root;
|
|
3348
|
+
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
3349
|
+
return componentLocalStyleEnabled;
|
|
3350
|
+
}
|
|
3351
|
+
function shouldEnableHarmonyPageLocalStyle() {
|
|
3352
|
+
return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
|
|
3353
|
+
}
|
|
3354
|
+
function isHarmonyBuildTarget() {
|
|
3355
|
+
if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
|
|
3356
|
+
return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
|
|
3357
|
+
}
|
|
3358
|
+
async function transformStyle(code, id, query, hookContext) {
|
|
3359
|
+
const parsed = query ?? parseVueRequest(id).query;
|
|
3360
|
+
if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
3361
|
+
if (isCssModuleExport(code)) return;
|
|
3362
|
+
const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
3363
|
+
rememberHarmonyApplySource(code);
|
|
3364
|
+
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
3365
|
+
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
3366
|
+
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
3367
|
+
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
3368
|
+
if (!styleHandlerOptions) {
|
|
3369
|
+
styleHandlerOptions = require_v4_engine.omitUndefined({
|
|
3370
|
+
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
3371
|
+
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
3372
|
+
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
3373
|
+
postcssOptions: { options: {
|
|
3374
|
+
from: id,
|
|
3375
|
+
map: {
|
|
3376
|
+
inline: false,
|
|
3377
|
+
annotation: false,
|
|
3378
|
+
sourcesContent: true
|
|
3379
|
+
}
|
|
3380
|
+
} }
|
|
3381
|
+
});
|
|
3382
|
+
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
3328
3383
|
}
|
|
3329
|
-
|
|
3384
|
+
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
3385
|
+
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
3386
|
+
for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
|
|
3387
|
+
const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
|
|
3388
|
+
return {
|
|
3389
|
+
code: postcssResult.css,
|
|
3390
|
+
map: postcssMap
|
|
3391
|
+
};
|
|
3330
3392
|
}
|
|
3331
3393
|
}
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3394
|
+
const cssPlugins = [{
|
|
3395
|
+
name: "weapp-tailwindcss:uni-app-x:css",
|
|
3396
|
+
async transform(code, id) {
|
|
3397
|
+
if (!isEnabled()) return;
|
|
3398
|
+
await runtimeState.readyPromise;
|
|
3399
|
+
return transformStyle(code, id, void 0, this);
|
|
3400
|
+
}
|
|
3401
|
+
}, {
|
|
3402
|
+
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
3403
|
+
enforce: "pre",
|
|
3404
|
+
async transform(code, id) {
|
|
3405
|
+
if (!isEnabled()) return;
|
|
3406
|
+
await runtimeState.readyPromise;
|
|
3407
|
+
const { query } = parseVueRequest(id);
|
|
3408
|
+
const lang = query.lang;
|
|
3409
|
+
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
3410
|
+
return transformStyle(code, id, query, this);
|
|
3411
|
+
}
|
|
3412
|
+
}];
|
|
3413
|
+
const nvuePlugin = {
|
|
3414
|
+
name: "weapp-tailwindcss:uni-app-x:nvue",
|
|
3415
|
+
enforce: "pre",
|
|
3416
|
+
async buildStart() {
|
|
3417
|
+
if (!isEnabled()) return;
|
|
3418
|
+
await ensureRuntimeClassSet(true);
|
|
3353
3419
|
},
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3420
|
+
async transform(code, id) {
|
|
3421
|
+
if (!isEnabled()) return;
|
|
3422
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3423
|
+
rememberHarmonyApplySource(code);
|
|
3424
|
+
const resolvedConfig = getResolvedConfig();
|
|
3425
|
+
const isServeCommand = resolvedConfig?.command === "serve";
|
|
3426
|
+
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
3427
|
+
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
3428
|
+
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
3429
|
+
const transformUVue = await loadTransformUVue();
|
|
3430
|
+
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
3431
|
+
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
3432
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
|
|
3433
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
3434
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
3435
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
3436
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
3437
|
+
}));
|
|
3438
|
+
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
3357
3439
|
},
|
|
3358
|
-
async
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
_weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3371
|
-
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3372
|
-
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3373
|
-
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3374
|
-
}
|
|
3375
|
-
metrics.html.elapsed += measureElapsed(start);
|
|
3376
|
-
metrics.html.transformed++;
|
|
3377
|
-
onUpdate(file, rawSource, transformed);
|
|
3378
|
-
debug("html handle: %s", file);
|
|
3379
|
-
return { result: transformed };
|
|
3440
|
+
async handleHotUpdate(ctx) {
|
|
3441
|
+
if (!isEnabled()) return;
|
|
3442
|
+
if (getResolvedConfig()?.command !== "serve") return;
|
|
3443
|
+
if (!UVUE_NVUE_RE.test(ctx.file)) return;
|
|
3444
|
+
await ensureRuntimeClassSet(true);
|
|
3445
|
+
},
|
|
3446
|
+
async watchChange(id) {
|
|
3447
|
+
if (!isEnabled()) return;
|
|
3448
|
+
const resolvedConfig = getResolvedConfig();
|
|
3449
|
+
if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
|
|
3450
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3451
|
+
await ensureRuntimeClassSet(true);
|
|
3380
3452
|
}
|
|
3381
|
-
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3453
|
+
};
|
|
3454
|
+
const stylePlaceholderPlugin = {
|
|
3455
|
+
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
3456
|
+
enforce: "post",
|
|
3457
|
+
generateBundle: {
|
|
3458
|
+
order: "post",
|
|
3459
|
+
async handler(_options, bundle) {
|
|
3460
|
+
if (!isEnabled()) return;
|
|
3461
|
+
const currentUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3462
|
+
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
3463
|
+
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
3464
|
+
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
3465
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3466
|
+
if (isHarmonyTarget) {
|
|
3467
|
+
const cssSources = [];
|
|
3468
|
+
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
3469
|
+
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
3470
|
+
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
3471
|
+
const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
|
|
3472
|
+
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
3473
|
+
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
3474
|
+
}
|
|
3475
|
+
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
3476
|
+
cssSources,
|
|
3477
|
+
excludeComponents: shouldEnableComponentLocalStyle()
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
3481
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
3482
|
+
const currentSource = String(item.source);
|
|
3483
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
3484
|
+
if (nextSource !== currentSource) item.source = nextSource;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3405
3487
|
}
|
|
3406
|
-
});
|
|
3407
|
-
}
|
|
3408
|
-
//#endregion
|
|
3409
|
-
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
3410
|
-
function createLinkedUpdateHelpers(options) {
|
|
3411
|
-
const pendingLinkedUpdates = [];
|
|
3412
|
-
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
3413
|
-
options.onUpdate(fileName, previous, next);
|
|
3414
|
-
options.debug("js linked handle: %s", fileName);
|
|
3415
3488
|
};
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3489
|
+
return [
|
|
3490
|
+
...cssPlugins,
|
|
3491
|
+
nvuePlugin,
|
|
3492
|
+
stylePlaceholderPlugin
|
|
3493
|
+
];
|
|
3494
|
+
}
|
|
3495
|
+
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
3496
|
+
return async () => {
|
|
3497
|
+
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
3498
|
+
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
|
|
3499
|
+
const rawSource = originalSource.source.toString();
|
|
3500
|
+
await require_hmr_timing.processCachedTask({
|
|
3501
|
+
cache,
|
|
3502
|
+
cacheKey: file,
|
|
3503
|
+
hashKey,
|
|
3504
|
+
rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
|
|
3505
|
+
applyResult(source) {
|
|
3506
|
+
originalSource.source = source;
|
|
3507
|
+
},
|
|
3508
|
+
onCacheHit() {
|
|
3509
|
+
debug("js cache hit: %s", file);
|
|
3510
|
+
},
|
|
3511
|
+
async transform() {
|
|
3512
|
+
const currentSource = originalSource.source.toString();
|
|
3513
|
+
const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
|
|
3514
|
+
uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
|
|
3515
|
+
babelParserOptions: {
|
|
3516
|
+
plugins: ["typescript"],
|
|
3517
|
+
sourceType: "unambiguous"
|
|
3518
|
+
}
|
|
3519
|
+
}));
|
|
3520
|
+
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
3521
|
+
onUpdate(file, currentSource, nextCode);
|
|
3522
|
+
debug("js handle: %s", file);
|
|
3523
|
+
applyLinkedResults(linked);
|
|
3524
|
+
return { result: nextCode };
|
|
3525
|
+
}
|
|
3420
3526
|
});
|
|
3421
3527
|
};
|
|
3422
|
-
const applyLinkedUpdates = (linked) => {
|
|
3423
|
-
require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
3424
|
-
};
|
|
3425
|
-
return {
|
|
3426
|
-
applyLinkedUpdates,
|
|
3427
|
-
pendingLinkedUpdates
|
|
3428
|
-
};
|
|
3429
|
-
}
|
|
3430
|
-
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
3431
|
-
if (!linked || !linkedSet) return;
|
|
3432
|
-
for (const id of Object.keys(linked)) {
|
|
3433
|
-
const linkedEntry = getJsEntry(id);
|
|
3434
|
-
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
3435
|
-
}
|
|
3436
3528
|
}
|
|
3437
3529
|
//#endregion
|
|
3438
3530
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
@@ -3540,7 +3632,7 @@ function processJsBundleEntry(options) {
|
|
|
3540
3632
|
}
|
|
3541
3633
|
const currentSource = originalEntrySource;
|
|
3542
3634
|
const precheckOptions = createHandlerOptions(node_path.default.resolve(outDir, file), {
|
|
3543
|
-
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
3635
|
+
uniAppX: resolveUniAppXJsTransformEnabled$1(uniAppX),
|
|
3544
3636
|
babelParserOptions: {
|
|
3545
3637
|
plugins: ["typescript"],
|
|
3546
3638
|
sourceType: "unambiguous"
|
|
@@ -4208,27 +4300,6 @@ function createTransformFilterSignature(options) {
|
|
|
4208
4300
|
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
4209
4301
|
}
|
|
4210
4302
|
//#endregion
|
|
4211
|
-
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
4212
|
-
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
4213
|
-
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
4214
|
-
if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4215
|
-
appType: opts.appType,
|
|
4216
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4217
|
-
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
4218
|
-
uniUtsPlatform
|
|
4219
|
-
}), {
|
|
4220
|
-
appType: opts.appType,
|
|
4221
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4222
|
-
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
4223
|
-
uniUtsPlatform
|
|
4224
|
-
})) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
|
|
4225
|
-
return {
|
|
4226
|
-
uniAppX: true,
|
|
4227
|
-
uniAppXCssTarget: "uvue",
|
|
4228
|
-
uniAppXUnsupported: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
4229
|
-
};
|
|
4230
|
-
}
|
|
4231
|
-
//#endregion
|
|
4232
4303
|
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
4233
4304
|
function resolveSourceRootCandidate(root, value) {
|
|
4234
4305
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
@@ -4290,16 +4361,35 @@ function inferPlatformFromViteOutDir$1(outDir) {
|
|
|
4290
4361
|
const normalized = segment.trim().toLowerCase();
|
|
4291
4362
|
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
4292
4363
|
}
|
|
4293
|
-
function isUniAppViteWebviewOutDir$1(outDir) {
|
|
4294
|
-
const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
4295
|
-
return normalized === "app" || normalized === "app-plus";
|
|
4296
|
-
}
|
|
4297
4364
|
function createGenerateBundleHook(context) {
|
|
4298
4365
|
const state = require_source_candidate_scan_signature.createBundleBuildState();
|
|
4299
4366
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4300
4367
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4301
4368
|
let currentOutDir;
|
|
4302
4369
|
let currentSubpackageRoots;
|
|
4370
|
+
const createInitialCssPipelineContext = (file) => {
|
|
4371
|
+
const resolvedConfig = context.getResolvedConfig();
|
|
4372
|
+
const platform = context.opts.cssOptions?.platform ?? context.opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4373
|
+
const currentGeneratorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(context.opts.generator, {
|
|
4374
|
+
appType: context.opts.appType,
|
|
4375
|
+
platform,
|
|
4376
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4377
|
+
uniAppX: context.opts.uniAppX
|
|
4378
|
+
});
|
|
4379
|
+
return {
|
|
4380
|
+
currentGeneratorBranch: require_generator.resolveGeneratorRuntimeBranch(currentGeneratorOptions, {
|
|
4381
|
+
appType: context.opts.appType,
|
|
4382
|
+
platform,
|
|
4383
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4384
|
+
uniAppX: context.opts.uniAppX
|
|
4385
|
+
}),
|
|
4386
|
+
currentGeneratorOptions,
|
|
4387
|
+
file,
|
|
4388
|
+
opts: context.opts,
|
|
4389
|
+
resolvedConfig,
|
|
4390
|
+
resolveStylePlatform: () => platform
|
|
4391
|
+
};
|
|
4392
|
+
};
|
|
4303
4393
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
4304
4394
|
getAppType: () => context.opts.appType,
|
|
4305
4395
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
@@ -4307,7 +4397,7 @@ function createGenerateBundleHook(context) {
|
|
|
4307
4397
|
getOutputRoot: () => currentOutDir,
|
|
4308
4398
|
getExtraOptions: (file) => ({
|
|
4309
4399
|
...resolveViteCssHandlerExtraOptions(file),
|
|
4310
|
-
...
|
|
4400
|
+
...context.cssPipelineStrategy?.getCssHandlerExtraOptions?.(createInitialCssPipelineContext(file)) ?? {},
|
|
4311
4401
|
...currentSubpackageRoots && isSubpackageOutputFile(file, currentSubpackageRoots) ? { isMainChunk: false } : {}
|
|
4312
4402
|
})
|
|
4313
4403
|
});
|
|
@@ -4338,18 +4428,27 @@ function createGenerateBundleHook(context) {
|
|
|
4338
4428
|
uniAppX,
|
|
4339
4429
|
uniUtsPlatform
|
|
4340
4430
|
});
|
|
4431
|
+
const cssPipelineContext = {
|
|
4432
|
+
bundle,
|
|
4433
|
+
currentGeneratorBranch: generatorBranch,
|
|
4434
|
+
currentGeneratorOptions: generatorOptions,
|
|
4435
|
+
opts,
|
|
4436
|
+
resolvedConfig,
|
|
4437
|
+
resolveStylePlatform: () => generatorPlatform
|
|
4438
|
+
};
|
|
4341
4439
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4342
|
-
const
|
|
4343
|
-
const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
|
|
4440
|
+
const shouldApplyWebCssCompat = context.cssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
4344
4441
|
const transformWebTargetCss = (css) => {
|
|
4345
|
-
|
|
4346
|
-
|
|
4442
|
+
return context.cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
4443
|
+
...cssPipelineContext,
|
|
4444
|
+
defaultWebCssCompat: (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true),
|
|
4445
|
+
removeScopedPreflight: (value) => value,
|
|
4446
|
+
shouldApplyWebCssCompat
|
|
4447
|
+
}) ?? (shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true) : css);
|
|
4347
4448
|
};
|
|
4348
|
-
const
|
|
4349
|
-
const
|
|
4350
|
-
const
|
|
4351
|
-
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
4352
|
-
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
4449
|
+
const isNativeAppStyleTarget = context.cssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
4450
|
+
const isHarmonyAppStyleTarget = context.cssPipelineStrategy?.isHarmonyAppStyleTarget?.(cssPipelineContext) === true;
|
|
4451
|
+
const shouldPreserveAppCssExtension = context.cssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? (isNativeAppStyleTarget || isHarmonyAppStyleTarget);
|
|
4353
4452
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
4354
4453
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
4355
4454
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
@@ -4364,6 +4463,8 @@ function createGenerateBundleHook(context) {
|
|
|
4364
4463
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
4365
4464
|
collectViteProcessedCssAssetResults(bundle, {
|
|
4366
4465
|
opts,
|
|
4466
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4467
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
4367
4468
|
isViteProcessedCssAsset,
|
|
4368
4469
|
markCssAssetProcessed,
|
|
4369
4470
|
recordCssAssetResult,
|
|
@@ -4428,20 +4529,32 @@ function createGenerateBundleHook(context) {
|
|
|
4428
4529
|
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4429
4530
|
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4430
4531
|
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4431
|
-
const
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4532
|
+
const isRootStyleOutputFile = (file) => {
|
|
4533
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4534
|
+
return normalized.endsWith(".css") && !normalized.includes("/");
|
|
4535
|
+
};
|
|
4536
|
+
const isMiniProgramStyleOutputFile = (file) => /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
4537
|
+
const resolveConfiguredCssEntryRootInjectionTarget = (sourceFile, outputFile) => {
|
|
4538
|
+
if (!outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
|
|
4539
|
+
return context.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
4540
|
+
...cssPipelineContext,
|
|
4541
|
+
bundle,
|
|
4542
|
+
isConfiguredCssEntryFile: (file) => typeof file === "string" && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(file)),
|
|
4543
|
+
isMiniProgramStyleOutputFile,
|
|
4544
|
+
isRootStyleOutputFile,
|
|
4545
|
+
outputFile,
|
|
4546
|
+
sourceFile
|
|
4436
4547
|
});
|
|
4437
|
-
const matchedRootCssFiles = rootCssFiles.filter((file) => getCssHandlerOptions(file).isMainChunk);
|
|
4438
|
-
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
4439
|
-
if (matchedRootCssFiles.length > 1) return;
|
|
4440
|
-
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
4441
4548
|
};
|
|
4442
4549
|
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4443
|
-
const
|
|
4444
|
-
|
|
4550
|
+
const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
|
|
4551
|
+
const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
|
|
4552
|
+
if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
|
|
4553
|
+
if (!(context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
|
|
4554
|
+
...cssPipelineContext,
|
|
4555
|
+
isRootStyleOutputFile,
|
|
4556
|
+
outputFile
|
|
4557
|
+
}) === true || cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile))) return;
|
|
4445
4558
|
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4446
4559
|
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4447
4560
|
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
@@ -4614,10 +4727,18 @@ function createGenerateBundleHook(context) {
|
|
|
4614
4727
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4615
4728
|
moduleGraph: moduleGraphOptions
|
|
4616
4729
|
});
|
|
4617
|
-
const
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
}
|
|
4730
|
+
const resolveFrameworkJsHandlerOptions = (absoluteFilename) => context.cssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
4731
|
+
...cssPipelineContext,
|
|
4732
|
+
file: absoluteFilename
|
|
4733
|
+
});
|
|
4734
|
+
const createHandlerOptions = (absoluteFilename, extra) => {
|
|
4735
|
+
const frameworkExtra = resolveFrameworkJsHandlerOptions(absoluteFilename);
|
|
4736
|
+
return createBaseHandlerOptions(absoluteFilename, frameworkExtra || extra ? {
|
|
4737
|
+
...frameworkExtra,
|
|
4738
|
+
...extra
|
|
4739
|
+
} : void 0);
|
|
4740
|
+
};
|
|
4741
|
+
const shouldTransformJsBundle = !isWebGeneratorTarget || context.cssPipelineStrategy?.shouldTransformServeJs?.(cssPipelineContext) === true;
|
|
4621
4742
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4622
4743
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4623
4744
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4674,12 +4795,18 @@ function createGenerateBundleHook(context) {
|
|
|
4674
4795
|
metrics.css.total++;
|
|
4675
4796
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
4676
4797
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
4798
|
+
const cssPipelineContext = {
|
|
4799
|
+
...createInitialCssPipelineContext(file),
|
|
4800
|
+
bundle
|
|
4801
|
+
};
|
|
4677
4802
|
let outputFile = resolveCssBundleOutputFile({
|
|
4678
4803
|
bundleFiles,
|
|
4804
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4679
4805
|
defaultStyleOutputExtension,
|
|
4680
4806
|
file,
|
|
4681
4807
|
isWebGeneratorTarget,
|
|
4682
4808
|
opts,
|
|
4809
|
+
pipelineContext: cssPipelineContext,
|
|
4683
4810
|
shouldPreserveAppCssExtension
|
|
4684
4811
|
});
|
|
4685
4812
|
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
@@ -4688,6 +4815,13 @@ function createGenerateBundleHook(context) {
|
|
|
4688
4815
|
originalFileNames: originalSource.originalFileNames,
|
|
4689
4816
|
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4690
4817
|
});
|
|
4818
|
+
const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((entry) => originalSource.originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true) : void 0;
|
|
4819
|
+
const configuredOriginalOutputFile = configuredOriginalSourceEntry ? resolveMatchedOutputFileForCurrentAsset(configuredOriginalSourceEntry.file) : void 0;
|
|
4820
|
+
let resolvedFromConfiguredOriginalCssEntry = false;
|
|
4821
|
+
if (configuredOriginalOutputFile && require_source_candidate_scan_signature.normalizeOutputPathKey(configuredOriginalOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile)) {
|
|
4822
|
+
outputFile = configuredOriginalOutputFile;
|
|
4823
|
+
resolvedFromConfiguredOriginalCssEntry = true;
|
|
4824
|
+
}
|
|
4691
4825
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4692
4826
|
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile, opts.cssMatcher)) {
|
|
4693
4827
|
delete bundle[file];
|
|
@@ -4699,13 +4833,14 @@ function createGenerateBundleHook(context) {
|
|
|
4699
4833
|
let resolvedFromTemporaryCssAsset = false;
|
|
4700
4834
|
const applyCssResult = (source) => {
|
|
4701
4835
|
applyCssResultToBundle({
|
|
4702
|
-
appType: opts.appType,
|
|
4703
4836
|
assetSourceFile,
|
|
4704
4837
|
bundle,
|
|
4838
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4705
4839
|
emitOrReplayCssAsset,
|
|
4706
4840
|
file,
|
|
4707
4841
|
originalSource,
|
|
4708
4842
|
outputFile,
|
|
4843
|
+
pipelineContext: cssPipelineContext,
|
|
4709
4844
|
source,
|
|
4710
4845
|
viteProcessedCssAsset
|
|
4711
4846
|
});
|
|
@@ -4772,7 +4907,7 @@ function createGenerateBundleHook(context) {
|
|
|
4772
4907
|
if (!hasUsableRememberedTailwindSource) {
|
|
4773
4908
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4774
4909
|
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
4775
|
-
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 :
|
|
4910
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
|
|
4776
4911
|
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
4777
4912
|
outputFile,
|
|
4778
4913
|
rawSource: inferredWebviewRootSourceEntry.source,
|
|
@@ -4860,7 +4995,7 @@ function createGenerateBundleHook(context) {
|
|
|
4860
4995
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
4861
4996
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4862
4997
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4863
|
-
const webviewRootCssInjectionTarget = vitePipelineCssAsset ?
|
|
4998
|
+
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveConfiguredCssEntryRootInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
4864
4999
|
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
4865
5000
|
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
4866
5001
|
usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(generatorSourceFile));
|
|
@@ -4901,7 +5036,7 @@ function createGenerateBundleHook(context) {
|
|
|
4901
5036
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4902
5037
|
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
4903
5038
|
const shouldRecordVitePipelineCssByOutput = require_source_candidate_scan_signature.normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
4904
|
-
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
5039
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
4905
5040
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
4906
5041
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource));
|
|
4907
5042
|
const strippedViteProcessedCss = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
@@ -5047,7 +5182,7 @@ function createGenerateBundleHook(context) {
|
|
|
5047
5182
|
continue;
|
|
5048
5183
|
}
|
|
5049
5184
|
if (type !== "js") continue;
|
|
5050
|
-
if (
|
|
5185
|
+
if (!shouldTransformJsBundle) {
|
|
5051
5186
|
debug("js skip web target: %s", file);
|
|
5052
5187
|
continue;
|
|
5053
5188
|
}
|
|
@@ -5129,6 +5264,8 @@ function createGenerateBundleHook(context) {
|
|
|
5129
5264
|
bundleFiles,
|
|
5130
5265
|
cache,
|
|
5131
5266
|
cssTaskFactories,
|
|
5267
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
5268
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
5132
5269
|
debug,
|
|
5133
5270
|
defaultStyleOutputExtension,
|
|
5134
5271
|
formatIteration: useIncrementalMode ? state.iteration : 0,
|
|
@@ -5202,9 +5339,9 @@ function registerGeneratorDependencies(ctx, dependencies) {
|
|
|
5202
5339
|
throw error;
|
|
5203
5340
|
}
|
|
5204
5341
|
}
|
|
5205
|
-
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
5342
|
+
function createCssHandlerOptions(opts, majorVersion, file, extraOptions = {}) {
|
|
5206
5343
|
return {
|
|
5207
|
-
...
|
|
5344
|
+
...extraOptions,
|
|
5208
5345
|
cssPreflight: opts.cssPreflight,
|
|
5209
5346
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
5210
5347
|
postcssOptions: { options: { from: file } },
|
|
@@ -5229,13 +5366,15 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
5229
5366
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
5230
5367
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
5231
5368
|
}
|
|
5232
|
-
function
|
|
5233
|
-
const
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5369
|
+
function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
5370
|
+
const shouldApplyWebCssCompat = cssPipelineStrategy?.shouldApplyWebCssCompat?.(context) === true;
|
|
5371
|
+
const defaultWebCssCompat = (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true);
|
|
5372
|
+
return cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
5373
|
+
...context,
|
|
5374
|
+
defaultWebCssCompat,
|
|
5375
|
+
removeScopedPreflight: (value) => value,
|
|
5376
|
+
shouldApplyWebCssCompat
|
|
5377
|
+
}) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
|
|
5239
5378
|
}
|
|
5240
5379
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
5241
5380
|
return {
|
|
@@ -5244,7 +5383,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5244
5383
|
generateBundle: {
|
|
5245
5384
|
order: "post",
|
|
5246
5385
|
async handler(_options, bundle) {
|
|
5247
|
-
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
5386
|
+
const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
5248
5387
|
const resolvedConfig = getResolvedConfig();
|
|
5249
5388
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
5250
5389
|
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
@@ -5263,11 +5402,16 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5263
5402
|
uniUtsPlatform
|
|
5264
5403
|
});
|
|
5265
5404
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
5266
|
-
const
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5405
|
+
const createCssPipelineContext = (_file) => ({
|
|
5406
|
+
bundle,
|
|
5407
|
+
currentGeneratorBranch: generatorBranch,
|
|
5408
|
+
currentGeneratorOptions: generatorOptions,
|
|
5409
|
+
opts,
|
|
5410
|
+
resolvedConfig,
|
|
5411
|
+
resolveStylePlatform: () => generatorPlatform
|
|
5412
|
+
});
|
|
5413
|
+
const isHarmonyAppStyleTarget = cssPipelineStrategy?.isHarmonyAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5414
|
+
const isNativeAppStyleTarget = cssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5271
5415
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
5272
5416
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
5273
5417
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -5279,30 +5423,32 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5279
5423
|
const collectViteProcessedCssAssets = () => {
|
|
5280
5424
|
collectViteProcessedCssAssetResults(bundle, {
|
|
5281
5425
|
opts,
|
|
5426
|
+
cssPipelineStrategy,
|
|
5427
|
+
createCssPipelineContext,
|
|
5282
5428
|
isViteProcessedCssAsset,
|
|
5283
5429
|
markCssAssetProcessed,
|
|
5284
5430
|
recordCssAssetResult,
|
|
5285
5431
|
recordViteProcessedCssAssetResult,
|
|
5286
5432
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
5287
|
-
transformCss: (css) => finalizeWebCss(css,
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
}),
|
|
5433
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5434
|
+
...createCssPipelineContext(file),
|
|
5435
|
+
file
|
|
5436
|
+
}, cssPipelineStrategy),
|
|
5292
5437
|
debug
|
|
5293
5438
|
});
|
|
5294
5439
|
};
|
|
5295
5440
|
const injectViteProcessedCssIntoMainCss = () => {
|
|
5296
5441
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
5297
5442
|
opts,
|
|
5443
|
+
cssPipelineStrategy,
|
|
5444
|
+
createCssPipelineContext,
|
|
5298
5445
|
getViteProcessedCssAssetResults,
|
|
5299
5446
|
markCssAssetProcessed,
|
|
5300
5447
|
recordCssAssetResult,
|
|
5301
|
-
transformCss: (css) => finalizeWebCss(css,
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
}),
|
|
5448
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5449
|
+
...createCssPipelineContext(file),
|
|
5450
|
+
file
|
|
5451
|
+
}, cssPipelineStrategy),
|
|
5306
5452
|
debug,
|
|
5307
5453
|
onUpdate: opts.onUpdate
|
|
5308
5454
|
});
|
|
@@ -5314,7 +5460,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5314
5460
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
5315
5461
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
5316
5462
|
const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
|
|
5317
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css"
|
|
5463
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5464
|
+
...createCssPipelineContext("uni-app-x-harmony-apply.css"),
|
|
5465
|
+
file: "uni-app-x-harmony-apply.css"
|
|
5466
|
+
}) ?? {});
|
|
5318
5467
|
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
5319
5468
|
opts,
|
|
5320
5469
|
runtimeState,
|
|
@@ -5349,10 +5498,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5349
5498
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
5350
5499
|
collectViteProcessedCssAssets();
|
|
5351
5500
|
injectViteProcessedCssIntoMainCss();
|
|
5352
|
-
|
|
5353
|
-
appType: opts.appType,
|
|
5501
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5354
5502
|
cssMatcher: opts.cssMatcher,
|
|
5355
5503
|
debug,
|
|
5504
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5356
5505
|
onUpdate: opts.onUpdate,
|
|
5357
5506
|
recordCssAssetResult
|
|
5358
5507
|
});
|
|
@@ -5367,18 +5516,20 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5367
5516
|
const file = output.fileName || bundleFile;
|
|
5368
5517
|
const rawSource = output.source.toString();
|
|
5369
5518
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
5370
|
-
const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource),
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
}));
|
|
5519
|
+
const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource), {
|
|
5520
|
+
...createCssPipelineContext(file),
|
|
5521
|
+
file
|
|
5522
|
+
}, cssPipelineStrategy));
|
|
5375
5523
|
output.source = nextCss;
|
|
5376
5524
|
markCssAssetProcessed(output, file);
|
|
5377
5525
|
recordCssAssetResult?.(file, nextCss);
|
|
5378
5526
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
5379
5527
|
return;
|
|
5380
5528
|
}
|
|
5381
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file
|
|
5529
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5530
|
+
...createCssPipelineContext(file),
|
|
5531
|
+
file
|
|
5532
|
+
}) ?? {});
|
|
5382
5533
|
const cssUserHandlerOptions = {
|
|
5383
5534
|
...cssHandlerOptions,
|
|
5384
5535
|
isMainChunk: false
|
|
@@ -5387,7 +5538,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5387
5538
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
5388
5539
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
5389
5540
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
5390
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile
|
|
5541
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5542
|
+
...createCssPipelineContext(generatorSourceFile),
|
|
5543
|
+
file: generatorSourceFile
|
|
5544
|
+
}) ?? {}) : cssHandlerOptions;
|
|
5391
5545
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
5392
5546
|
...generatorCssHandlerOptions,
|
|
5393
5547
|
isMainChunk: false
|
|
@@ -5406,11 +5560,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5406
5560
|
styleHandler: opts.styleHandler,
|
|
5407
5561
|
debug
|
|
5408
5562
|
}) : void 0;
|
|
5409
|
-
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource,
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
}) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5563
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, {
|
|
5564
|
+
...createCssPipelineContext(file),
|
|
5565
|
+
file
|
|
5566
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5414
5567
|
if (generated) {
|
|
5415
5568
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
5416
5569
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5425,10 +5578,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5425
5578
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
5426
5579
|
collectViteProcessedCssAssets();
|
|
5427
5580
|
injectViteProcessedCssIntoMainCss();
|
|
5428
|
-
|
|
5429
|
-
appType: opts.appType,
|
|
5581
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5430
5582
|
cssMatcher: opts.cssMatcher,
|
|
5431
5583
|
debug,
|
|
5584
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5432
5585
|
onUpdate: opts.onUpdate,
|
|
5433
5586
|
recordCssAssetResult
|
|
5434
5587
|
});
|
|
@@ -6199,7 +6352,7 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
6199
6352
|
return resolvedRoot;
|
|
6200
6353
|
}
|
|
6201
6354
|
//#endregion
|
|
6202
|
-
//#region src/bundlers/vite/
|
|
6355
|
+
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
6203
6356
|
const debug = require_context.createDebug();
|
|
6204
6357
|
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
6205
6358
|
const weappTailwindcssDirPosix = require_source_candidate_scan_signature.slash(weappTailwindcssPackageDir);
|
|
@@ -6238,23 +6391,22 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
6238
6391
|
function isWebOrNativeAppPlatform(platform) {
|
|
6239
6392
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
6240
6393
|
}
|
|
6241
|
-
function
|
|
6242
|
-
return
|
|
6394
|
+
function applyViteWebCssCompat(css, options) {
|
|
6395
|
+
return (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, options.compat);
|
|
6243
6396
|
}
|
|
6244
|
-
function
|
|
6245
|
-
|
|
6246
|
-
return options.safeSelectors ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
6397
|
+
function isInternalUserDefinedOptions(options) {
|
|
6398
|
+
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
6247
6399
|
}
|
|
6248
6400
|
/**
|
|
6249
|
-
*
|
|
6250
|
-
* @description uni-app vite / uni-app-x 版本插件
|
|
6251
|
-
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
6401
|
+
* Vite 各框架分支共享的组合工厂。框架分支只负责选择和拥有各自入口,公共稳定能力放在这里复用。
|
|
6252
6402
|
*/
|
|
6253
|
-
function
|
|
6254
|
-
|
|
6255
|
-
const
|
|
6256
|
-
const
|
|
6257
|
-
const
|
|
6403
|
+
function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
6404
|
+
debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
|
|
6405
|
+
const rawOptions = options.__internalViteRawOptions ?? options;
|
|
6406
|
+
const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
6407
|
+
const hasExplicitTailwindcssBasedir = typeof options.__internalViteRawExplicitTailwindcssBasedir === "boolean" ? options.__internalViteRawExplicitTailwindcssBasedir : typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
6408
|
+
const rawCssEntries = collectConfiguredCssEntries(rawOptions);
|
|
6409
|
+
const opts = isInternalUserDefinedOptions(options) ? options : require_context.getCompilerContext({
|
|
6258
6410
|
...options,
|
|
6259
6411
|
__internalDeferMissingCssEntriesWarning: true
|
|
6260
6412
|
});
|
|
@@ -6275,8 +6427,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6275
6427
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler, styleInjector } = opts;
|
|
6276
6428
|
const initialTailwindRuntime = tailwindRuntime;
|
|
6277
6429
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
6278
|
-
const
|
|
6279
|
-
const
|
|
6430
|
+
const frameworkCssPipelineStrategy = frameworkBranch.cssPipelineStrategy;
|
|
6431
|
+
const uniAppXEnabled = frameworkBranch.isRuntimeClassSetFeatureEnabled?.({ uniAppX }) === true;
|
|
6432
|
+
const shouldEnableFrameworkExtraPlugins = () => frameworkBranch.createExtraPlugins !== void 0;
|
|
6280
6433
|
const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
|
|
6281
6434
|
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
6282
6435
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
@@ -6305,6 +6458,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6305
6458
|
tailwindcssMajorVersion,
|
|
6306
6459
|
uniAppX
|
|
6307
6460
|
});
|
|
6461
|
+
const createCssPipelineContext = (overrides = {}) => ({
|
|
6462
|
+
currentGeneratorBranch: resolveCurrentGeneratorBranch(),
|
|
6463
|
+
currentGeneratorOptions: resolveCurrentGeneratorOptions(),
|
|
6464
|
+
opts,
|
|
6465
|
+
resolvedConfig,
|
|
6466
|
+
resolveStylePlatform: resolveViteStylePlatform,
|
|
6467
|
+
...overrides
|
|
6468
|
+
});
|
|
6308
6469
|
const initialGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6309
6470
|
const transformEarlyMiniProgramCss = (code) => {
|
|
6310
6471
|
const platform = resolveViteStylePlatform();
|
|
@@ -6321,8 +6482,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
6321
6482
|
};
|
|
6322
6483
|
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
6323
6484
|
const hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots({
|
|
6324
|
-
...
|
|
6325
|
-
cssEntries: opts.cssEntries ??
|
|
6485
|
+
...rawOptions,
|
|
6486
|
+
cssEntries: opts.cssEntries ?? rawOptions.cssEntries
|
|
6326
6487
|
});
|
|
6327
6488
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
6328
6489
|
const transientAutoCssSources = /* @__PURE__ */ new Map();
|
|
@@ -6638,10 +6799,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
6638
6799
|
const isUniViteProject = () => {
|
|
6639
6800
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
6640
6801
|
};
|
|
6641
|
-
const isHarmonyAppBuildTarget = () => {
|
|
6642
|
-
if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
|
|
6643
|
-
return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
|
|
6644
|
-
};
|
|
6645
6802
|
const matchesViteProcessedCssSource = (candidate) => {
|
|
6646
6803
|
const normalized = normalizeViteProcessedCssFile(candidate);
|
|
6647
6804
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
@@ -6661,7 +6818,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6661
6818
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? node_path.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
6662
6819
|
getExtraOptions: (file) => ({
|
|
6663
6820
|
...resolveViteCssHandlerExtraOptions(file),
|
|
6664
|
-
...
|
|
6821
|
+
...frameworkCssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
6822
|
+
...createCssPipelineContext(),
|
|
6823
|
+
file
|
|
6824
|
+
}) ?? {}
|
|
6665
6825
|
}),
|
|
6666
6826
|
getDynamicCssOptions: () => ({ cssPreflight: opts.cssPreflight })
|
|
6667
6827
|
});
|
|
@@ -6674,20 +6834,24 @@ function WeappTailwindcss(options = {}) {
|
|
|
6674
6834
|
await runtimeState.readyPromise;
|
|
6675
6835
|
await waitForSourceCandidateSyncs();
|
|
6676
6836
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
6677
|
-
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id : file;
|
|
6837
|
+
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id === file ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : id : file;
|
|
6678
6838
|
if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
|
|
6679
6839
|
const generatorCode = require_v4_engine.normalizeEmptyTailwindCustomVariants(code);
|
|
6680
6840
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
6681
|
-
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
6682
|
-
const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (require_utils.resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
|
|
6683
|
-
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6684
6841
|
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6685
6842
|
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6686
|
-
const
|
|
6843
|
+
const cssPipelineContext = createCssPipelineContext({
|
|
6844
|
+
currentGeneratorBranch,
|
|
6845
|
+
currentGeneratorOptions
|
|
6846
|
+
});
|
|
6847
|
+
const shouldPreserveStyleOutputExtension = frameworkCssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
6848
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6849
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, shouldPreserveStyleOutputExtension, sourceRoot);
|
|
6687
6850
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6851
|
+
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
6688
6852
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6689
6853
|
const cssHandlerOptions = {
|
|
6690
|
-
...
|
|
6854
|
+
...sourceCssHandlerOptions,
|
|
6691
6855
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6692
6856
|
};
|
|
6693
6857
|
const transientCssSource = transientAutoCssSources.get(file) ?? (require_v4_engine.hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || require_v4_engine.hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || require_v4_engine.hasTailwindApplyDirective(generatorCode) ? {
|
|
@@ -6695,7 +6859,11 @@ function WeappTailwindcss(options = {}) {
|
|
|
6695
6859
|
css: generatorCode,
|
|
6696
6860
|
file: node_path.default.resolve(file)
|
|
6697
6861
|
} : void 0);
|
|
6698
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null &&
|
|
6862
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && (frameworkCssPipelineStrategy?.shouldDeferEmptyScopedCssSource?.({
|
|
6863
|
+
...cssPipelineContext,
|
|
6864
|
+
cssHandlerOptions,
|
|
6865
|
+
generatorCode
|
|
6866
|
+
}) ?? true);
|
|
6699
6867
|
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
6700
6868
|
opts,
|
|
6701
6869
|
runtimeState,
|
|
@@ -6704,7 +6872,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6704
6872
|
file,
|
|
6705
6873
|
outputFile,
|
|
6706
6874
|
cssHandlerOptions,
|
|
6707
|
-
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(
|
|
6875
|
+
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(requestFile),
|
|
6708
6876
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6709
6877
|
getSourceCandidatesForEntries,
|
|
6710
6878
|
generatorPlatform: resolveGeneratorPlatform(),
|
|
@@ -6716,12 +6884,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6716
6884
|
});
|
|
6717
6885
|
if (!generated) return;
|
|
6718
6886
|
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6719
|
-
const
|
|
6720
|
-
const tracedCss = require_hmr_timing.annotateCssSourceTrace(
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6887
|
+
const shouldApplyWebCssCompat = currentGeneratorBranch.isWeb || frameworkCssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
6888
|
+
const tracedCss = require_hmr_timing.annotateCssSourceTrace(frameworkCssPipelineStrategy?.transformGeneratedCss?.(finalizedCss, {
|
|
6889
|
+
...cssPipelineContext,
|
|
6890
|
+
defaultWebCssCompat: (css) => applyViteWebCssCompat(css, { compat: currentGeneratorOptions.webCompat ?? true }),
|
|
6891
|
+
removeScopedPreflight: removeScopedTailwindPreflightCss,
|
|
6892
|
+
shouldApplyWebCssCompat
|
|
6893
|
+
}) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ? applyViteWebCssCompat(finalizedCss, { compat: currentGeneratorOptions.webCompat ?? true }) : finalizedCss), {
|
|
6725
6894
|
opts,
|
|
6726
6895
|
tokenSources: require_hmr_timing.createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6727
6896
|
});
|
|
@@ -6736,7 +6905,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6736
6905
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6737
6906
|
outputFile
|
|
6738
6907
|
});
|
|
6739
|
-
if (
|
|
6908
|
+
if (shouldPreserveStyleOutputExtension && outputFile.endsWith(".css")) hookContext?.emitFile?.({
|
|
6740
6909
|
type: "asset",
|
|
6741
6910
|
fileName: outputFile,
|
|
6742
6911
|
source: tracedCss
|
|
@@ -6747,9 +6916,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6747
6916
|
cssMemory.rememberCssSource({
|
|
6748
6917
|
outputFile,
|
|
6749
6918
|
rawSource: code,
|
|
6750
|
-
sourceFile:
|
|
6919
|
+
sourceFile: requestFile
|
|
6751
6920
|
});
|
|
6752
|
-
debug("css generated for vite postcss pipeline: %s bytes=%d",
|
|
6921
|
+
debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
|
|
6753
6922
|
return `${require_source_candidate_scan_signature.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
6754
6923
|
};
|
|
6755
6924
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
@@ -6795,12 +6964,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6795
6964
|
recordGeneratorCandidates,
|
|
6796
6965
|
pruneViteCssCaches,
|
|
6797
6966
|
getViteCssCacheStats,
|
|
6798
|
-
hmrTimingRecorder
|
|
6967
|
+
hmrTimingRecorder,
|
|
6968
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy
|
|
6799
6969
|
});
|
|
6800
6970
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
6801
6971
|
opts,
|
|
6802
6972
|
runtimeState,
|
|
6803
6973
|
ensureRuntimeClassSet,
|
|
6974
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
6804
6975
|
debug,
|
|
6805
6976
|
getResolvedConfig,
|
|
6806
6977
|
markCssAssetProcessed,
|
|
@@ -6821,25 +6992,25 @@ function WeappTailwindcss(options = {}) {
|
|
|
6821
6992
|
}),
|
|
6822
6993
|
getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
|
|
6823
6994
|
});
|
|
6824
|
-
const
|
|
6995
|
+
const extraPluginPlatform = frameworkBranch.getExtraPluginPlatform?.() ?? {};
|
|
6825
6996
|
const prepareTailwindGeneration = async () => {
|
|
6826
6997
|
if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
|
|
6827
6998
|
await syncSourceCandidateScan();
|
|
6828
6999
|
};
|
|
6829
|
-
const
|
|
6830
|
-
appType: opts.appType ?? "uni-app-x",
|
|
7000
|
+
const extraPlugins = frameworkBranch.createExtraPlugins?.({
|
|
6831
7001
|
customAttributesEntities,
|
|
6832
7002
|
disabledDefaultTemplateHandler,
|
|
6833
|
-
|
|
7003
|
+
ensureRuntimeClassSet,
|
|
7004
|
+
generateCss: generateTailwindCssForVitePipeline,
|
|
7005
|
+
getResolvedConfig,
|
|
7006
|
+
isEnabled: shouldEnableFrameworkExtraPlugins,
|
|
7007
|
+
isIosPlatform: extraPluginPlatform.isIosPlatform === true,
|
|
7008
|
+
jsHandler,
|
|
6834
7009
|
mainCssChunkMatcher,
|
|
6835
7010
|
runtimeState,
|
|
6836
7011
|
styleHandler,
|
|
6837
|
-
generateCss: generateTailwindCssForVitePipeline,
|
|
6838
|
-
jsHandler,
|
|
6839
|
-
ensureRuntimeClassSet,
|
|
6840
|
-
getResolvedConfig,
|
|
6841
7012
|
uniAppX
|
|
6842
|
-
})
|
|
7013
|
+
}) ?? [];
|
|
6843
7014
|
const plugins = [
|
|
6844
7015
|
...rewritePlugins,
|
|
6845
7016
|
{
|
|
@@ -6938,10 +7109,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6938
7109
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6939
7110
|
}),
|
|
6940
7111
|
createViteServeJsTransformPlugin({
|
|
6941
|
-
createHandlerOptions: (file) => serveJsHandlerOptions(file,
|
|
7112
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
7113
|
+
...createCssPipelineContext(),
|
|
7114
|
+
file
|
|
7115
|
+
})),
|
|
6942
7116
|
getCommand: () => resolvedConfig?.command,
|
|
6943
7117
|
jsHandler,
|
|
6944
|
-
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb
|
|
7118
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
|
|
6945
7119
|
transformRuntime: ensureRuntimeClassSet
|
|
6946
7120
|
}),
|
|
6947
7121
|
{
|
|
@@ -7016,12 +7190,306 @@ function WeappTailwindcss(options = {}) {
|
|
|
7016
7190
|
}
|
|
7017
7191
|
}
|
|
7018
7192
|
];
|
|
7019
|
-
|
|
7193
|
+
plugins.push(...extraPlugins);
|
|
7020
7194
|
plugins.push(cssFinalizerOutputPlugin);
|
|
7021
|
-
plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () =>
|
|
7195
|
+
plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
|
|
7022
7196
|
return plugins;
|
|
7023
7197
|
}
|
|
7024
7198
|
//#endregion
|
|
7199
|
+
//#region src/bundlers/vite/frameworks/generic/index.ts
|
|
7200
|
+
function createGenericVitePlugins(options = {}) {
|
|
7201
|
+
return createViteFrameworkPlugins(options, {
|
|
7202
|
+
frameworkName: "generic",
|
|
7203
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
|
|
7204
|
+
});
|
|
7205
|
+
}
|
|
7206
|
+
//#endregion
|
|
7207
|
+
//#region src/bundlers/vite/frameworks/taro/index.ts
|
|
7208
|
+
const taroCssPipelineStrategy = {
|
|
7209
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7210
|
+
return true;
|
|
7211
|
+
},
|
|
7212
|
+
shouldMoveRootMiniProgramStyleToImportShellOrigin() {
|
|
7213
|
+
return true;
|
|
7214
|
+
},
|
|
7215
|
+
shouldNormalizeRootMiniProgramImportShell() {
|
|
7216
|
+
return true;
|
|
7217
|
+
}
|
|
7218
|
+
};
|
|
7219
|
+
function createTaroAlipayBrowserslistAssetPlugin() {
|
|
7220
|
+
return {
|
|
7221
|
+
name: "weapp-tailwindcss:taro-alipay-browserslist-asset",
|
|
7222
|
+
enforce: "pre",
|
|
7223
|
+
generateBundle(_options, bundle) {
|
|
7224
|
+
if (node_process.default.env.TARO_ENV !== "alipay") return;
|
|
7225
|
+
bundle[".browserslistrc"] = {
|
|
7226
|
+
type: "asset",
|
|
7227
|
+
fileName: ".browserslistrc",
|
|
7228
|
+
source: "defaults and fully supports es6-module"
|
|
7229
|
+
};
|
|
7230
|
+
}
|
|
7231
|
+
};
|
|
7232
|
+
}
|
|
7233
|
+
function createTaroVitePlugins(options = {}) {
|
|
7234
|
+
return [createTaroAlipayBrowserslistAssetPlugin(), ...createViteFrameworkPlugins(options, {
|
|
7235
|
+
frameworkName: "taro",
|
|
7236
|
+
cssPipelineStrategy: taroCssPipelineStrategy,
|
|
7237
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.taro
|
|
7238
|
+
})];
|
|
7239
|
+
}
|
|
7240
|
+
//#endregion
|
|
7241
|
+
//#region src/bundlers/vite/frameworks/uni-app/index.ts
|
|
7242
|
+
function isUniAppWebviewStylePlatform(platform) {
|
|
7243
|
+
return platform === "app" || platform === "app-plus";
|
|
7244
|
+
}
|
|
7245
|
+
function isUniAppWebviewAppBundle(bundleFiles) {
|
|
7246
|
+
return bundleFiles.some((file) => node_path.default.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
7247
|
+
}
|
|
7248
|
+
function isUniAppWebviewOutDir(outDir) {
|
|
7249
|
+
const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
7250
|
+
return normalized === "app" || normalized === "app-plus";
|
|
7251
|
+
}
|
|
7252
|
+
const uniAppCssPipelineStrategy = {
|
|
7253
|
+
getServeJsHandlerOptions(context) {
|
|
7254
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? { needEscaped: true } : void 0;
|
|
7255
|
+
},
|
|
7256
|
+
shouldApplyWebCssCompat(context) {
|
|
7257
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7258
|
+
},
|
|
7259
|
+
includeTailwindGeneratedCssAssetsInRootCoverage(context) {
|
|
7260
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7261
|
+
},
|
|
7262
|
+
resolveConfiguredCssEntryRootInjectionTarget(context) {
|
|
7263
|
+
if (context.isMiniProgramStyleOutputFile(context.outputFile) || !context.isConfiguredCssEntryFile(context.sourceFile)) return;
|
|
7264
|
+
const rootCssFiles = [];
|
|
7265
|
+
const matchedRootCssFiles = [];
|
|
7266
|
+
for (const [bundleFile, output] of Object.entries(context.bundle)) {
|
|
7267
|
+
if (output.type !== "asset") continue;
|
|
7268
|
+
const file = output.fileName || bundleFile;
|
|
7269
|
+
if (!context.opts.cssMatcher(file) || !context.isRootStyleOutputFile(file) || context.isMiniProgramStyleOutputFile(file)) continue;
|
|
7270
|
+
rootCssFiles.push(file);
|
|
7271
|
+
if (context.opts.mainCssChunkMatcher(file, context.opts.appType)) matchedRootCssFiles.push(file);
|
|
7272
|
+
}
|
|
7273
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
7274
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
7275
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
7276
|
+
},
|
|
7277
|
+
shouldApplyFinalWebviewCssCompat(context) {
|
|
7278
|
+
return isUniAppWebviewAppBundle(context.bundleFiles) || isUniAppWebviewOutDir(context.outDir);
|
|
7279
|
+
},
|
|
7280
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7281
|
+
return true;
|
|
7282
|
+
},
|
|
7283
|
+
shouldPreferExplicitWebCssTargets() {
|
|
7284
|
+
return true;
|
|
7285
|
+
},
|
|
7286
|
+
shouldPreferMatchedRootWebOutputTarget() {
|
|
7287
|
+
return true;
|
|
7288
|
+
},
|
|
7289
|
+
shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml(context) {
|
|
7290
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7291
|
+
},
|
|
7292
|
+
shouldSelectConfiguredCssEntryRootSource(context) {
|
|
7293
|
+
return context.currentGeneratorBranch.isWeb && context.opts.cssMatcher(context.outputFile) && context.isRootStyleOutputFile(context.outputFile);
|
|
7294
|
+
},
|
|
7295
|
+
shouldTransformServeJs(context) {
|
|
7296
|
+
return !context.currentGeneratorBranch.isWeb || isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7297
|
+
},
|
|
7298
|
+
transformGeneratedCss(css, context) {
|
|
7299
|
+
const webCss = context.shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true) : css;
|
|
7300
|
+
const safeCss = isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(webCss, { escapeMap: context.opts.escapeMap }) : webCss;
|
|
7301
|
+
return context.removeScopedPreflight(safeCss);
|
|
7302
|
+
}
|
|
7303
|
+
};
|
|
7304
|
+
function createUniAppVitePlugins(options = {}) {
|
|
7305
|
+
return createViteFrameworkPlugins(options, {
|
|
7306
|
+
frameworkName: "uni-app",
|
|
7307
|
+
cssPipelineStrategy: uniAppCssPipelineStrategy,
|
|
7308
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp
|
|
7309
|
+
});
|
|
7310
|
+
}
|
|
7311
|
+
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
7312
|
+
"uni-ad-draw",
|
|
7313
|
+
"uni-ad-fullscreen-video",
|
|
7314
|
+
"uni-ad-interactive",
|
|
7315
|
+
"uni-ad-interstitial",
|
|
7316
|
+
"uni-ad-rewarded-video",
|
|
7317
|
+
"uni-ad",
|
|
7318
|
+
"uni-animation-view",
|
|
7319
|
+
"uni-audio",
|
|
7320
|
+
"uni-block",
|
|
7321
|
+
"uni-button",
|
|
7322
|
+
"uni-camera",
|
|
7323
|
+
"uni-canvas",
|
|
7324
|
+
"uni-checkbox-group",
|
|
7325
|
+
"uni-checkbox",
|
|
7326
|
+
"uni-cover-image",
|
|
7327
|
+
"uni-cover-view",
|
|
7328
|
+
"uni-custom-tab-bar",
|
|
7329
|
+
"uni-editor",
|
|
7330
|
+
"uni-form",
|
|
7331
|
+
"uni-icon",
|
|
7332
|
+
"uni-image",
|
|
7333
|
+
"uni-input",
|
|
7334
|
+
"uni-label",
|
|
7335
|
+
"uni-list-item",
|
|
7336
|
+
"uni-list-view",
|
|
7337
|
+
"uni-live-player",
|
|
7338
|
+
"uni-live-pusher",
|
|
7339
|
+
"uni-map",
|
|
7340
|
+
"uni-match-media",
|
|
7341
|
+
"uni-movable-area",
|
|
7342
|
+
"uni-movable-view",
|
|
7343
|
+
"uni-navigation-bar",
|
|
7344
|
+
"uni-navigator",
|
|
7345
|
+
"uni-open-data",
|
|
7346
|
+
"uni-page-meta",
|
|
7347
|
+
"uni-picker-view",
|
|
7348
|
+
"uni-picker",
|
|
7349
|
+
"uni-progress",
|
|
7350
|
+
"uni-radio-group",
|
|
7351
|
+
"uni-radio",
|
|
7352
|
+
"uni-rich-text",
|
|
7353
|
+
"uni-scroll-view",
|
|
7354
|
+
"uni-slider",
|
|
7355
|
+
"uni-sticky-header",
|
|
7356
|
+
"uni-sticky-section",
|
|
7357
|
+
"uni-swiper-item",
|
|
7358
|
+
"uni-swiper",
|
|
7359
|
+
"uni-switch",
|
|
7360
|
+
"uni-template",
|
|
7361
|
+
"uni-text",
|
|
7362
|
+
"uni-textarea",
|
|
7363
|
+
"uni-unicloud-db",
|
|
7364
|
+
"uni-video",
|
|
7365
|
+
"uni-view",
|
|
7366
|
+
"uni-web-view"
|
|
7367
|
+
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
7368
|
+
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
7369
|
+
function withUniAppXWebPreflightReset(css, enabled) {
|
|
7370
|
+
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
7371
|
+
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
7372
|
+
}
|
|
7373
|
+
//#endregion
|
|
7374
|
+
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
7375
|
+
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
7376
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
7377
|
+
if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
7378
|
+
appType: opts.appType,
|
|
7379
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7380
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
7381
|
+
uniUtsPlatform
|
|
7382
|
+
}), {
|
|
7383
|
+
appType: opts.appType,
|
|
7384
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7385
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
7386
|
+
uniUtsPlatform
|
|
7387
|
+
})) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
|
|
7388
|
+
return {
|
|
7389
|
+
uniAppX: true,
|
|
7390
|
+
uniAppXCssTarget: "uvue",
|
|
7391
|
+
uniAppXUnsupported: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
7392
|
+
};
|
|
7393
|
+
}
|
|
7394
|
+
//#endregion
|
|
7395
|
+
//#region src/bundlers/vite/frameworks/uni-app-x/index.ts
|
|
7396
|
+
function isUniAppXNativeAppStyleTarget() {
|
|
7397
|
+
return require_utils.resolveUniUtsPlatform().isApp;
|
|
7398
|
+
}
|
|
7399
|
+
function isUniAppXHarmonyAppStyleTarget(context) {
|
|
7400
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
7401
|
+
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
7402
|
+
return uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (context.bundle != null && isUniAppXHarmonyBundle(context.bundle) || isUniAppXHarmonyOutDir(context.resolvedConfig?.build?.outDir));
|
|
7403
|
+
}
|
|
7404
|
+
const uniAppXCssPipelineStrategy = {
|
|
7405
|
+
getCssHandlerExtraOptions(context) {
|
|
7406
|
+
return resolveUniAppXNativeCssHandlerOptions(context.opts);
|
|
7407
|
+
},
|
|
7408
|
+
isNativeAppStyleTarget() {
|
|
7409
|
+
return isUniAppXNativeAppStyleTarget();
|
|
7410
|
+
},
|
|
7411
|
+
isHarmonyAppStyleTarget(context) {
|
|
7412
|
+
return isUniAppXHarmonyAppStyleTarget(context);
|
|
7413
|
+
},
|
|
7414
|
+
shouldPreserveStyleOutputExtension(context) {
|
|
7415
|
+
return isUniAppXNativeAppStyleTarget() || isUniAppXHarmonyAppStyleTarget(context);
|
|
7416
|
+
},
|
|
7417
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7418
|
+
return true;
|
|
7419
|
+
},
|
|
7420
|
+
shouldDeferEmptyScopedCssSource(context) {
|
|
7421
|
+
if (!context.cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(context.generatorCode)) return false;
|
|
7422
|
+
return true;
|
|
7423
|
+
},
|
|
7424
|
+
transformGeneratedCss(css, context) {
|
|
7425
|
+
const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
|
|
7426
|
+
return withUniAppXWebPreflightReset(context.removeScopedPreflight(webCss), context.currentGeneratorBranch.isWeb);
|
|
7427
|
+
}
|
|
7428
|
+
};
|
|
7429
|
+
function createUniAppXVitePlugins(options = {}) {
|
|
7430
|
+
return createViteFrameworkPlugins(options, {
|
|
7431
|
+
frameworkName: "uni-app-x",
|
|
7432
|
+
cssPipelineStrategy: uniAppXCssPipelineStrategy,
|
|
7433
|
+
getExtraPluginPlatform: () => ({ isIosPlatform: require_utils.resolveUniUtsPlatform().isAppIos }),
|
|
7434
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp,
|
|
7435
|
+
isRuntimeClassSetFeatureEnabled: () => true,
|
|
7436
|
+
createExtraPlugins: (context) => createUniAppXPlugins({
|
|
7437
|
+
appType: "uni-app-x",
|
|
7438
|
+
customAttributesEntities: context.customAttributesEntities,
|
|
7439
|
+
disabledDefaultTemplateHandler: context.disabledDefaultTemplateHandler,
|
|
7440
|
+
ensureRuntimeClassSet: context.ensureRuntimeClassSet,
|
|
7441
|
+
generateCss: context.generateCss,
|
|
7442
|
+
getResolvedConfig: context.getResolvedConfig,
|
|
7443
|
+
isEnabled: context.isEnabled,
|
|
7444
|
+
isIosPlatform: context.isIosPlatform,
|
|
7445
|
+
jsHandler: context.jsHandler,
|
|
7446
|
+
mainCssChunkMatcher: context.mainCssChunkMatcher,
|
|
7447
|
+
runtimeState: context.runtimeState,
|
|
7448
|
+
styleHandler: context.styleHandler,
|
|
7449
|
+
uniAppX: context.uniAppX
|
|
7450
|
+
})
|
|
7451
|
+
});
|
|
7452
|
+
}
|
|
7453
|
+
//#endregion
|
|
7454
|
+
//#region src/bundlers/vite/frameworks/weapp-vite/index.ts
|
|
7455
|
+
function createWeappVitePlugins(options = {}) {
|
|
7456
|
+
return createViteFrameworkPlugins(options, {
|
|
7457
|
+
frameworkName: "weapp-vite",
|
|
7458
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
|
|
7459
|
+
});
|
|
7460
|
+
}
|
|
7461
|
+
//#endregion
|
|
7462
|
+
//#region src/bundlers/vite/index.ts
|
|
7463
|
+
/**
|
|
7464
|
+
* @name WeappTailwindcss
|
|
7465
|
+
* @description Vite 入口只负责早期识别框架分支,具体插件组合由各 framework 目录拥有。
|
|
7466
|
+
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
7467
|
+
*/
|
|
7468
|
+
function WeappTailwindcss(options = {}) {
|
|
7469
|
+
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
7470
|
+
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
7471
|
+
const opts = require_context.getCompilerContext({
|
|
7472
|
+
...options,
|
|
7473
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
7474
|
+
});
|
|
7475
|
+
opts.__internalViteRawOptions = options;
|
|
7476
|
+
opts.__internalViteRawExplicitAppType = hasExplicitAppType;
|
|
7477
|
+
opts.__internalViteRawExplicitTailwindcssBasedir = hasExplicitTailwindcssBasedir;
|
|
7478
|
+
switch (require_source_candidate_scan_signature.resolveViteFrameworkProfile({
|
|
7479
|
+
appType: opts.appType,
|
|
7480
|
+
detectEnv: true,
|
|
7481
|
+
env: node_process.default.env,
|
|
7482
|
+
root: opts.tailwindcssBasedir ?? node_process.default.cwd(),
|
|
7483
|
+
uniAppX: opts.uniAppX
|
|
7484
|
+
}).frameworkName) {
|
|
7485
|
+
case "taro": return createTaroVitePlugins(opts);
|
|
7486
|
+
case "uni-app": return createUniAppVitePlugins(opts);
|
|
7487
|
+
case "uni-app-x": return createUniAppXVitePlugins(opts);
|
|
7488
|
+
case "weapp-vite": return createWeappVitePlugins(opts);
|
|
7489
|
+
default: return createGenericVitePlugins(opts);
|
|
7490
|
+
}
|
|
7491
|
+
}
|
|
7492
|
+
//#endregion
|
|
7025
7493
|
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
7026
7494
|
enumerable: true,
|
|
7027
7495
|
get: function() {
|