weapp-tailwindcss 5.1.7 → 5.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundlers/framework-selector.d.ts +26 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +6 -0
- package/dist/bundlers/gulp/index.d.ts +4 -4
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +6 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/generic/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/taro/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app-x/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/weapp-vite/index.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +2 -2
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
- package/dist/bundlers/vite/index.d.ts +2 -4
- package/dist/bundlers/vite/processed-css-assets.d.ts +5 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +35 -0
- package/dist/bundlers/vite/shared/framework-strategy.d.ts +88 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -2
- package/dist/bundlers/webpack/frameworks/generic/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/index.d.ts +8 -0
- package/dist/bundlers/webpack/frameworks/mpx/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/taro/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/uni-app/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/weapp-vite/index.d.ts +5 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +21 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +4 -3
- package/dist/cli.js +8 -0
- package/dist/cli.mjs +8 -0
- package/dist/{context-C7KTDlrG.js → context-CRhUs_5e.js} +11 -3
- package/dist/{context-BqeDu1Ha.mjs → context-CfXr3hWz.mjs} +11 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-DASZwC6t.js → generator-DaaFxR5V.js} +1 -1
- package/dist/{generator-BOt2Tvx3.mjs → generator-DugIHBgl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-alDZryyB.mjs → gulp-CRjkPsbX.mjs} +22 -7
- package/dist/{gulp-D6hsaTLM.js → gulp-JUfnhOOo.js} +22 -7
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-CYwVMRol.mjs → hmr-timing-BecOXMd8.mjs} +5 -5
- package/dist/{hmr-timing-BIr_CiPW.js → hmr-timing-DcIEXnf8.js} +5 -5
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-Djr2Hw8y.js → source-candidate-scan-signature-10tvdJVC.js} +185 -98
- package/dist/{source-candidate-scan-signature-D97ZEXcj.mjs → source-candidate-scan-signature-DAg8QSgh.mjs} +162 -99
- package/dist/style-injector/internal.d.ts +18 -4
- package/dist/{tailwindcss-DPxJpRVP.js → tailwindcss-BZjZZi60.js} +1 -1
- package/dist/{tailwindcss-DDGD90w7.mjs → tailwindcss-PA2jHHpx.mjs} +1 -1
- package/dist/{transform-CvqqZBuq.js → transform-B0BxX3XB.js} +1 -1
- package/dist/{transform-DPPr79r2.mjs → transform-wNEbcZeQ.mjs} +1 -1
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v4-engine-3UmJkAY7.js → v4-engine-BZP2462H.js} +12 -0
- package/dist/{v4-engine-CYSrDVNp.mjs → v4-engine-CjjWONB0.mjs} +12 -0
- package/dist/{vite-BJRlG835.js → vite-CHk7V9EA.js} +1358 -848
- package/dist/{vite-XxJh7Xtu.mjs → vite-ClpyoD9e.mjs} +1357 -847
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +21 -1
- package/dist/{webpack-eN8WzIT-.mjs → webpack-2s-TFhgm.mjs} +321 -216
- package/dist/{webpack-BxBOMUtY.js → webpack-BhM4Hqla.js} +320 -215
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,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
|
}
|
|
@@ -2097,31 +1816,64 @@ function dedupeViteCssResults(records) {
|
|
|
2097
1816
|
return true;
|
|
2098
1817
|
});
|
|
2099
1818
|
}
|
|
2100
|
-
function
|
|
2101
|
-
|
|
1819
|
+
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
1820
|
+
let changed = false;
|
|
1821
|
+
root.walkAtRules("media", (atRule) => {
|
|
1822
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
1823
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
1824
|
+
else atRule.remove();
|
|
1825
|
+
changed = true;
|
|
1826
|
+
});
|
|
1827
|
+
if (changed) root.walkAtRules((atRule) => {
|
|
1828
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
1829
|
+
});
|
|
1830
|
+
return changed;
|
|
1831
|
+
}
|
|
1832
|
+
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
1833
|
+
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
1834
|
+
}
|
|
1835
|
+
function removeTailwindEntryDirectivesFromCss(css) {
|
|
2102
1836
|
try {
|
|
2103
|
-
const
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
1837
|
+
const source = require_v4_engine.stripGeneratorPlaceholderMarkers(css);
|
|
1838
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
1839
|
+
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
1840
|
+
const removedTailwindDirectives = (0, _weapp_tailwindcss_postcss.removeTailwindSourceDirectivesRoot)(root);
|
|
1841
|
+
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
1842
|
+
} catch {
|
|
1843
|
+
return require_v4_engine.removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
1847
|
+
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
1848
|
+
return css.split(/\r?\n/).filter((line) => {
|
|
1849
|
+
const trimmed = line.trim();
|
|
1850
|
+
if (!trimmed.startsWith("@import")) return true;
|
|
1851
|
+
const request = (0, _weapp_tailwindcss_postcss.parseTailwindCssDirectiveRequest)(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
1852
|
+
return request === void 0 || (0, _weapp_tailwindcss_postcss.isMiniProgramLocalCssImportRequest)(request);
|
|
1853
|
+
}).join("\n");
|
|
1854
|
+
}
|
|
1855
|
+
function normalizeInjectableCssForTarget(css, file) {
|
|
1856
|
+
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
1857
|
+
}
|
|
1858
|
+
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
1859
|
+
if (!css.includes("@import")) return {
|
|
1860
|
+
css,
|
|
1861
|
+
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
1862
|
+
};
|
|
1863
|
+
try {
|
|
1864
|
+
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
1865
|
+
return {
|
|
1866
|
+
css: (isMiniProgramStyleOutputFile(file) ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramCssImportsRoot)(root) : false) ? root.toString() : css,
|
|
1867
|
+
importedStyleFiles: collectImportedStyleFilesRoot(root, file)
|
|
1868
|
+
};
|
|
2118
1869
|
} catch {
|
|
2119
|
-
|
|
1870
|
+
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
1871
|
+
return {
|
|
1872
|
+
css: fallbackCss,
|
|
1873
|
+
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
1874
|
+
};
|
|
2120
1875
|
}
|
|
2121
1876
|
}
|
|
2122
|
-
function removeTailwindEntryDirectivesFromCss(css) {
|
|
2123
|
-
return require_v4_engine.removeTailwindSourceDirectives(removeTailwindSourceMediaWrappers(css));
|
|
2124
|
-
}
|
|
2125
1877
|
function stripStyleExtension(file) {
|
|
2126
1878
|
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
2127
1879
|
}
|
|
@@ -2135,15 +1887,23 @@ function resolveImportedStyleFile(targetFile, request) {
|
|
|
2135
1887
|
const targetDir = posix.posix.dirname(require_source_candidate_scan_signature.normalizeOutputPathKey(targetFile));
|
|
2136
1888
|
return require_source_candidate_scan_signature.normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2137
1889
|
}
|
|
2138
|
-
function
|
|
1890
|
+
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
2139
1891
|
const imports = /* @__PURE__ */ new Set();
|
|
1892
|
+
for (const request of requests) {
|
|
1893
|
+
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
1894
|
+
if (importedFile) imports.add(importedFile);
|
|
1895
|
+
}
|
|
1896
|
+
return imports;
|
|
1897
|
+
}
|
|
1898
|
+
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
1899
|
+
return collectImportedStyleFilesFromRequests((0, _weapp_tailwindcss_postcss.collectCssImportRequestsRoot)(root), targetFile);
|
|
1900
|
+
}
|
|
1901
|
+
function collectImportedStyleFiles(css, targetFile) {
|
|
1902
|
+
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
2140
1903
|
try {
|
|
2141
|
-
_weapp_tailwindcss_postcss.postcss.parse(css)
|
|
2142
|
-
const importedFile = resolveImportedStyleFile(targetFile, require_v4_engine.parseImportRequest(atRule.params));
|
|
2143
|
-
if (importedFile) imports.add(importedFile);
|
|
2144
|
-
});
|
|
1904
|
+
return collectImportedStyleFilesRoot(_weapp_tailwindcss_postcss.postcss.parse(css), targetFile);
|
|
2145
1905
|
} catch {}
|
|
2146
|
-
return
|
|
1906
|
+
return /* @__PURE__ */ new Set();
|
|
2147
1907
|
}
|
|
2148
1908
|
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
2149
1909
|
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
@@ -2239,14 +1999,17 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
|
|
|
2239
1999
|
return removed;
|
|
2240
2000
|
}
|
|
2241
2001
|
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
2002
|
+
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
2242
2003
|
function hasVueScopedAttr(value) {
|
|
2243
2004
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2244
|
-
|
|
2005
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
2006
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
|
|
2245
2007
|
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2008
|
+
VUE_SCOPED_CLASS_RE.lastIndex = 0;
|
|
2246
2009
|
return matched;
|
|
2247
2010
|
}
|
|
2248
2011
|
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();
|
|
2012
|
+
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
2013
|
}
|
|
2251
2014
|
function createDeclarationSignature(rule) {
|
|
2252
2015
|
return createDeclarationKeys(rule).sort().join(";");
|
|
@@ -2273,6 +2036,33 @@ function isLikelyTailwindGlobalRule(rule) {
|
|
|
2273
2036
|
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
2274
2037
|
return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
2275
2038
|
}
|
|
2039
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
2040
|
+
"view",
|
|
2041
|
+
"text",
|
|
2042
|
+
"::after",
|
|
2043
|
+
"::before"
|
|
2044
|
+
]);
|
|
2045
|
+
const MINI_PROGRAM_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
2046
|
+
"box-sizing",
|
|
2047
|
+
"margin",
|
|
2048
|
+
"padding",
|
|
2049
|
+
"border"
|
|
2050
|
+
]);
|
|
2051
|
+
function isMiniProgramTailwindPreflightDeclaration(decl) {
|
|
2052
|
+
return decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop);
|
|
2053
|
+
}
|
|
2054
|
+
function isUnscopedMiniProgramTailwindPreflightRule(rule) {
|
|
2055
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2056
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
2057
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2058
|
+
return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
2059
|
+
})) return false;
|
|
2060
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2061
|
+
return declarations.length > 0 && declarations.every(isMiniProgramTailwindPreflightDeclaration);
|
|
2062
|
+
}
|
|
2063
|
+
function hasUnscopedMiniProgramTailwindPreflightRule(css) {
|
|
2064
|
+
return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
|
|
2065
|
+
}
|
|
2276
2066
|
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2277
2067
|
const rules = /* @__PURE__ */ new Set();
|
|
2278
2068
|
const atRules = /* @__PURE__ */ new Set();
|
|
@@ -2314,8 +2104,9 @@ function isRuleCoveredByRootCss(rule, coverage) {
|
|
|
2314
2104
|
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2315
2105
|
if (!hasVueScopedAttr(css)) return css;
|
|
2316
2106
|
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2107
|
+
const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
|
|
2317
2108
|
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2318
|
-
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
|
|
2109
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight) return css;
|
|
2319
2110
|
try {
|
|
2320
2111
|
const root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
2321
2112
|
let changed = false;
|
|
@@ -2326,7 +2117,7 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
|
2326
2117
|
}
|
|
2327
2118
|
});
|
|
2328
2119
|
root.walkRules((rule) => {
|
|
2329
|
-
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
|
|
2120
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule)) {
|
|
2330
2121
|
rule.remove();
|
|
2331
2122
|
changed = true;
|
|
2332
2123
|
}
|
|
@@ -2425,11 +2216,17 @@ function isRootStyleOutputFile(file) {
|
|
|
2425
2216
|
function isMiniProgramStyleOutputFile(file) {
|
|
2426
2217
|
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2427
2218
|
}
|
|
2428
|
-
function shouldPreserveMiniProgramImportShell(
|
|
2429
|
-
|
|
2219
|
+
function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
|
|
2220
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2221
|
+
return context !== void 0 && options.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
2222
|
+
...context,
|
|
2223
|
+
css,
|
|
2224
|
+
file
|
|
2225
|
+
}) === true && isMiniProgramStyleOutputFile(file) && options.opts.cssMatcher(file) && (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(css);
|
|
2430
2226
|
}
|
|
2431
|
-
function resolvePreservedImportShellInjectionTarget(
|
|
2432
|
-
|
|
2227
|
+
function resolvePreservedImportShellInjectionTarget(options, bundle, file, css) {
|
|
2228
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2229
|
+
if (context === void 0 || options.cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(context) !== true) return;
|
|
2433
2230
|
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2434
2231
|
if (importedStyleFiles.size !== 1) return;
|
|
2435
2232
|
const [importedFile] = importedStyleFiles;
|
|
@@ -2441,15 +2238,25 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
|
2441
2238
|
if (require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2442
2239
|
}
|
|
2443
2240
|
}
|
|
2444
|
-
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
2241
|
+
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bundle) {
|
|
2242
|
+
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2445
2243
|
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2446
2244
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2447
2245
|
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
2448
2246
|
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 (
|
|
2247
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferMatchedRootWebOutputTarget?.({
|
|
2248
|
+
...context,
|
|
2249
|
+
file,
|
|
2250
|
+
matchedRootWebOutputTargets
|
|
2251
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2450
2252
|
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
2253
|
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 (
|
|
2254
|
+
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferExplicitWebCssTargets?.({
|
|
2255
|
+
...context,
|
|
2256
|
+
explicitRootTargets,
|
|
2257
|
+
explicitWebCssTargets,
|
|
2258
|
+
file
|
|
2259
|
+
}) === true && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2453
2260
|
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2454
2261
|
if (records.some((record) => {
|
|
2455
2262
|
if (record.injectIntoMain !== true) return false;
|
|
@@ -2489,7 +2296,7 @@ function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, record
|
|
|
2489
2296
|
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
|
|
2490
2297
|
if (!isRecordFile && !isProcessedSource) continue;
|
|
2491
2298
|
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2492
|
-
if (candidateIsRootWebStyle && !isRecordFile) continue;
|
|
2299
|
+
if (candidateIsRootWebStyle && !isRecordFile && !isProcessedSource) continue;
|
|
2493
2300
|
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2494
2301
|
else clearAssetSource(candidateOutput);
|
|
2495
2302
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
@@ -2541,8 +2348,22 @@ function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
|
2541
2348
|
const fileKey = normalizeComparableStyleFile(file);
|
|
2542
2349
|
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2543
2350
|
}
|
|
2544
|
-
function
|
|
2545
|
-
|
|
2351
|
+
function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
|
|
2352
|
+
const opts = options.opts;
|
|
2353
|
+
if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2354
|
+
const context = createCssAssetPipelineContext(options, outputFile, bundle);
|
|
2355
|
+
if (context === void 0) return;
|
|
2356
|
+
const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
2357
|
+
...context,
|
|
2358
|
+
bundle,
|
|
2359
|
+
isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
|
|
2360
|
+
isMiniProgramStyleOutputFile,
|
|
2361
|
+
isRootStyleOutputFile,
|
|
2362
|
+
outputFile,
|
|
2363
|
+
sourceFile
|
|
2364
|
+
});
|
|
2365
|
+
if (resolvedByStrategy !== void 0) return resolvedByStrategy;
|
|
2366
|
+
if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
|
|
2546
2367
|
const rootCssFiles = [];
|
|
2547
2368
|
const matchedRootCssFiles = [];
|
|
2548
2369
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -2609,7 +2430,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2609
2430
|
options.markCssAssetProcessed?.(output, file);
|
|
2610
2431
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2611
2432
|
const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
|
|
2612
|
-
const webviewRootCssInjectionTarget = options.opts ?
|
|
2433
|
+
const webviewRootCssInjectionTarget = options.opts ? resolveConfiguredCssEntryRootInjectionTarget(bundle, options, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
|
|
2613
2434
|
const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
|
|
2614
2435
|
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
2436
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
@@ -2684,10 +2505,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2684
2505
|
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2685
2506
|
if (output.type !== "asset") continue;
|
|
2686
2507
|
let file = getAssetFile$1(bundleFile, output);
|
|
2687
|
-
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2508
|
+
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults, options, bundle)) continue;
|
|
2688
2509
|
let originalSource = readAssetSource$2(output);
|
|
2689
|
-
if (shouldPreserveMiniProgramImportShell(options
|
|
2690
|
-
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options
|
|
2510
|
+
if (shouldPreserveMiniProgramImportShell(options, bundle, file, originalSource)) {
|
|
2511
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options, bundle, file, originalSource);
|
|
2691
2512
|
if (typeof importedTargetFile === "string") {
|
|
2692
2513
|
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2693
2514
|
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];
|
|
@@ -2703,8 +2524,9 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2703
2524
|
}
|
|
2704
2525
|
const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2705
2526
|
const mainFileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
2706
|
-
|
|
2707
|
-
|
|
2527
|
+
const normalizedOriginalCss = normalizeInjectableCssForTargetWithImports(transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file), file);
|
|
2528
|
+
let nextCss = normalizedOriginalCss.css;
|
|
2529
|
+
const importedStyleFiles = normalizedOriginalCss.importedStyleFiles;
|
|
2708
2530
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2709
2531
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2710
2532
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
@@ -2720,7 +2542,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2720
2542
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2721
2543
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2722
2544
|
targetViteCssResults.push(record);
|
|
2723
|
-
let css = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2545
|
+
let css = normalizeInjectableCssForTarget(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim();
|
|
2724
2546
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2725
2547
|
if (css.length === 0) continue;
|
|
2726
2548
|
const mergedLayerCss = require_hmr_timing.mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
@@ -3034,17 +2856,10 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
3034
2856
|
function readAssetSource(asset) {
|
|
3035
2857
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
3036
2858
|
}
|
|
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
2859
|
function getAssetFile(bundleFile, asset) {
|
|
3045
2860
|
return asset.fileName || bundleFile;
|
|
3046
2861
|
}
|
|
3047
|
-
function
|
|
2862
|
+
function finalizeWebviewCssCompat(bundle, options) {
|
|
3048
2863
|
if (options.opts.generator?.webCompat === false) return 0;
|
|
3049
2864
|
let transformed = 0;
|
|
3050
2865
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -3057,7 +2872,7 @@ function finalizeUniAppViteWebviewCssCompat(bundle, options) {
|
|
|
3057
2872
|
output.source = nextCss;
|
|
3058
2873
|
options.recordCssAssetResult?.(file, nextCss);
|
|
3059
2874
|
options.onUpdate(file, rawSource, nextCss);
|
|
3060
|
-
options.debug("finalize
|
|
2875
|
+
options.debug("finalize webview css compat: %s bytes=%d", file, nextCss.length);
|
|
3061
2876
|
transformed++;
|
|
3062
2877
|
}
|
|
3063
2878
|
return transformed;
|
|
@@ -3098,8 +2913,8 @@ function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
|
3098
2913
|
} catch {}
|
|
3099
2914
|
return importedFile;
|
|
3100
2915
|
}
|
|
3101
|
-
function
|
|
3102
|
-
if (options.
|
|
2916
|
+
function normalizeRootMiniProgramImportShellAssets(bundle, options) {
|
|
2917
|
+
if (!options.enabled) return 0;
|
|
3103
2918
|
let updated = 0;
|
|
3104
2919
|
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
3105
2920
|
if (rootOutput.type !== "asset") continue;
|
|
@@ -3110,6 +2925,17 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3110
2925
|
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
2926
|
if (originOutput?.type !== "asset") continue;
|
|
3112
2927
|
const rootSource = readAssetSource(rootOutput);
|
|
2928
|
+
const importedRootFile = resolveSingleCssImportOutputFile(rootFile, rootSource);
|
|
2929
|
+
if (importedRootFile && require_source_candidate_scan_signature.normalizeOutputPathKey(importedRootFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile)) {
|
|
2930
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2931
|
+
if (rootSource === nextRootSource) continue;
|
|
2932
|
+
rootOutput.source = nextRootSource;
|
|
2933
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2934
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2935
|
+
options.debug("normalize root css import shell request: %s -> %s", rootFile, originFile);
|
|
2936
|
+
updated++;
|
|
2937
|
+
continue;
|
|
2938
|
+
}
|
|
3113
2939
|
if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(rootSource)) continue;
|
|
3114
2940
|
const originSource = readAssetSource(originOutput);
|
|
3115
2941
|
if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(originSource)) {
|
|
@@ -3124,13 +2950,13 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
3124
2950
|
options.recordCssAssetResult?.(originFile, rootSource);
|
|
3125
2951
|
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
3126
2952
|
options.onUpdate?.(originFile, originSource, rootSource);
|
|
3127
|
-
options.debug("normalize
|
|
2953
|
+
options.debug("normalize root css import shell: %s -> %s", rootFile, originFile);
|
|
3128
2954
|
updated++;
|
|
3129
2955
|
}
|
|
3130
2956
|
return updated;
|
|
3131
2957
|
}
|
|
3132
2958
|
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;
|
|
2959
|
+
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
2960
|
const tasksStart = performance.now();
|
|
3135
2961
|
if (cssTaskFactories.length > 0) {
|
|
3136
2962
|
const cssTask = require_hmr_timing.runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -3159,6 +2985,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3159
2985
|
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
3160
2986
|
collectViteProcessedCssAssetResults(bundle, {
|
|
3161
2987
|
opts,
|
|
2988
|
+
cssPipelineStrategy,
|
|
2989
|
+
createCssPipelineContext,
|
|
3162
2990
|
isViteProcessedCssAsset,
|
|
3163
2991
|
markCssAssetProcessed,
|
|
3164
2992
|
recordCssAssetResult,
|
|
@@ -3170,6 +2998,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3170
2998
|
});
|
|
3171
2999
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3172
3000
|
opts,
|
|
3001
|
+
cssPipelineStrategy,
|
|
3002
|
+
createCssPipelineContext,
|
|
3173
3003
|
getViteProcessedCssAssetResults,
|
|
3174
3004
|
markCssAssetProcessed,
|
|
3175
3005
|
recordCssAssetResult,
|
|
@@ -3188,10 +3018,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3188
3018
|
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
3019
|
syncViteProcessedCssIntoMainCssAssets();
|
|
3190
3020
|
}
|
|
3191
|
-
|
|
3192
|
-
|
|
3021
|
+
const createFinalizeCssPipelineContext = (file = "") => createCssPipelineContext?.(file);
|
|
3022
|
+
const finalizeCssPipelineContext = createFinalizeCssPipelineContext();
|
|
3023
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
3193
3024
|
cssMatcher: opts.cssMatcher,
|
|
3194
3025
|
debug,
|
|
3026
|
+
enabled: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(finalizeCssPipelineContext) === true,
|
|
3195
3027
|
onUpdate,
|
|
3196
3028
|
recordCssAssetResult
|
|
3197
3029
|
});
|
|
@@ -3199,13 +3031,23 @@ async function finalizeGenerateBundle(options) {
|
|
|
3199
3031
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
3200
3032
|
cssMatcher: opts.cssMatcher,
|
|
3201
3033
|
debug,
|
|
3202
|
-
includeTailwindGeneratedCssAssets:
|
|
3034
|
+
includeTailwindGeneratedCssAssets: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.includeTailwindGeneratedCssAssetsInRootCoverage?.({
|
|
3035
|
+
...finalizeCssPipelineContext,
|
|
3036
|
+
bundleFiles,
|
|
3037
|
+
isWebGeneratorTarget,
|
|
3038
|
+
outDir
|
|
3039
|
+
}) === true,
|
|
3203
3040
|
isViteProcessedCssAsset,
|
|
3204
3041
|
onUpdate,
|
|
3205
3042
|
recordCssAssetResult,
|
|
3206
3043
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
3207
3044
|
});
|
|
3208
|
-
if (
|
|
3045
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml?.({
|
|
3046
|
+
...finalizeCssPipelineContext,
|
|
3047
|
+
bundleFiles: Object.keys(bundle),
|
|
3048
|
+
isWebGeneratorTarget,
|
|
3049
|
+
outDir
|
|
3050
|
+
}) === true) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
3209
3051
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
3210
3052
|
cssMatcher: opts.cssMatcher,
|
|
3211
3053
|
debug,
|
|
@@ -3216,7 +3058,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
3216
3058
|
recordCssAssetResult,
|
|
3217
3059
|
styleHandler
|
|
3218
3060
|
});
|
|
3219
|
-
if (
|
|
3061
|
+
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldApplyFinalWebviewCssCompat?.({
|
|
3062
|
+
...finalizeCssPipelineContext,
|
|
3063
|
+
bundleFiles: Object.keys(bundle),
|
|
3064
|
+
isWebGeneratorTarget,
|
|
3065
|
+
outDir
|
|
3066
|
+
}) === true) finalizeWebviewCssCompat(bundle, {
|
|
3220
3067
|
debug,
|
|
3221
3068
|
onUpdate,
|
|
3222
3069
|
opts,
|
|
@@ -3308,131 +3155,418 @@ function collectClassAttributeValues(source) {
|
|
|
3308
3155
|
break;
|
|
3309
3156
|
}
|
|
3310
3157
|
}
|
|
3311
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3158
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
3159
|
+
}
|
|
3160
|
+
return values;
|
|
3161
|
+
}
|
|
3162
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
3163
|
+
const matches = /* @__PURE__ */ new Set();
|
|
3164
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
3165
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
3166
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
3167
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3168
|
+
while (quoted !== null) {
|
|
3169
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
3170
|
+
for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
|
|
3171
|
+
const normalized = candidate.trim();
|
|
3172
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
3173
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
3174
|
+
matches.add(normalized);
|
|
3175
|
+
}
|
|
3176
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
return [...matches];
|
|
3180
|
+
}
|
|
3181
|
+
//#endregion
|
|
3182
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
3183
|
+
function processHtmlBundleEntry(options) {
|
|
3184
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
3185
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
3186
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3187
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3188
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
|
|
3189
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3190
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3191
|
+
const hashKey = cacheKey;
|
|
3192
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3193
|
+
tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
|
|
3194
|
+
cache,
|
|
3195
|
+
cacheKey,
|
|
3196
|
+
hashKey,
|
|
3197
|
+
hash: htmlProcessHash,
|
|
3198
|
+
applyResult(source) {
|
|
3199
|
+
originalSource.source = source;
|
|
3200
|
+
},
|
|
3201
|
+
onCacheHit() {
|
|
3202
|
+
metrics.html.cacheHits++;
|
|
3203
|
+
debug("html cache hit: %s", file);
|
|
3204
|
+
},
|
|
3205
|
+
async transform() {
|
|
3206
|
+
const start = performance.now();
|
|
3207
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
3208
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3209
|
+
let retryRuntimeSet;
|
|
3210
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
3211
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
3212
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
3213
|
+
retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
3214
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
3215
|
+
}
|
|
3216
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
3217
|
+
_weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3218
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3219
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3220
|
+
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3221
|
+
}
|
|
3222
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
3223
|
+
metrics.html.transformed++;
|
|
3224
|
+
onUpdate(file, rawSource, transformed);
|
|
3225
|
+
debug("html handle: %s", file);
|
|
3226
|
+
return { result: transformed };
|
|
3227
|
+
}
|
|
3228
|
+
})));
|
|
3229
|
+
}
|
|
3230
|
+
//#endregion
|
|
3231
|
+
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
3232
|
+
function createJsEntryResolver(jsEntries) {
|
|
3233
|
+
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
3234
|
+
for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
|
|
3235
|
+
return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
|
|
3236
|
+
}
|
|
3237
|
+
//#endregion
|
|
3238
|
+
//#region src/bundlers/vite/generate-bundle/js-handler-options.ts
|
|
3239
|
+
function resolveUniAppXJsTransformEnabled$1(uniAppX) {
|
|
3240
|
+
return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
3241
|
+
}
|
|
3242
|
+
function createJsHandlerOptionsFactory(options) {
|
|
3243
|
+
return (absoluteFilename, extra) => ({
|
|
3244
|
+
...extra,
|
|
3245
|
+
generateMap: false,
|
|
3246
|
+
filename: absoluteFilename,
|
|
3247
|
+
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
3248
|
+
moduleGraph: options.moduleGraph,
|
|
3249
|
+
babelParserOptions: {
|
|
3250
|
+
...extra?.babelParserOptions ?? {},
|
|
3251
|
+
sourceFilename: absoluteFilename
|
|
3252
|
+
}
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
//#endregion
|
|
3256
|
+
//#region src/bundlers/vite/generate-bundle/js-linking.ts
|
|
3257
|
+
function createLinkedUpdateHelpers(options) {
|
|
3258
|
+
const pendingLinkedUpdates = [];
|
|
3259
|
+
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
3260
|
+
options.onUpdate(fileName, previous, next);
|
|
3261
|
+
options.debug("js linked handle: %s", fileName);
|
|
3262
|
+
};
|
|
3263
|
+
const scheduleLinkedApply = (entry, code) => {
|
|
3264
|
+
pendingLinkedUpdates.push(() => {
|
|
3265
|
+
if (entry.output.type === "chunk") entry.output.code = code;
|
|
3266
|
+
else entry.output.source = code;
|
|
3267
|
+
});
|
|
3268
|
+
};
|
|
3269
|
+
const applyLinkedUpdates = (linked) => {
|
|
3270
|
+
require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
|
|
3271
|
+
};
|
|
3272
|
+
return {
|
|
3273
|
+
applyLinkedUpdates,
|
|
3274
|
+
pendingLinkedUpdates
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
3278
|
+
if (!linked || !linkedSet) return;
|
|
3279
|
+
for (const id of Object.keys(linked)) {
|
|
3280
|
+
const linkedEntry = getJsEntry(id);
|
|
3281
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
//#endregion
|
|
3285
|
+
//#region src/bundlers/vite/query.ts
|
|
3286
|
+
function parseVueRequest(id) {
|
|
3287
|
+
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
3288
|
+
const searchParams = new URLSearchParams(rawQuery);
|
|
3289
|
+
const query = Object.fromEntries(searchParams);
|
|
3290
|
+
if (query.vue != null) query.vue = true;
|
|
3291
|
+
if (query.index != null) query.index = Number(query.index);
|
|
3292
|
+
if (query.raw != null) query.raw = true;
|
|
3293
|
+
if (query.url != null) query.url = true;
|
|
3294
|
+
if (query.scoped != null) query.scoped = true;
|
|
3295
|
+
const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
|
|
3296
|
+
const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
|
|
3297
|
+
if (langType) query.lang = langType;
|
|
3298
|
+
return {
|
|
3299
|
+
filename,
|
|
3300
|
+
query
|
|
3301
|
+
};
|
|
3302
|
+
}
|
|
3303
|
+
//#endregion
|
|
3304
|
+
//#region src/uni-app-x/harmony.ts
|
|
3305
|
+
function isUniAppXHarmonyOutDir(outDir) {
|
|
3306
|
+
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
3307
|
+
}
|
|
3308
|
+
//#endregion
|
|
3309
|
+
//#region src/uni-app-x/style-isolation.ts
|
|
3310
|
+
const manifestCache = /* @__PURE__ */ new Map();
|
|
3311
|
+
function resolveUniAppXStyleIsolationEnabled(root) {
|
|
3312
|
+
if (!root) return false;
|
|
3313
|
+
const normalizedRoot = node_path.default.resolve(root);
|
|
3314
|
+
const cached = manifestCache.get(normalizedRoot);
|
|
3315
|
+
if (cached !== void 0) return cached;
|
|
3316
|
+
const manifestPath = node_path.default.join(normalizedRoot, "manifest.json");
|
|
3317
|
+
let enabled = false;
|
|
3318
|
+
try {
|
|
3319
|
+
enabled = `${(0, comment_json.parse)(node_fs.default.readFileSync(manifestPath, "utf8"))["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
|
|
3320
|
+
} catch {
|
|
3321
|
+
enabled = false;
|
|
3322
|
+
}
|
|
3323
|
+
manifestCache.set(normalizedRoot, enabled);
|
|
3324
|
+
return enabled;
|
|
3325
|
+
}
|
|
3326
|
+
//#endregion
|
|
3327
|
+
//#region src/uni-app-x/vite.ts
|
|
3328
|
+
let transformUVuePromise;
|
|
3329
|
+
function loadTransformUVue() {
|
|
3330
|
+
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-B0BxX3XB.js")).then((mod) => mod.transformUVue));
|
|
3331
|
+
return transformUVuePromise;
|
|
3332
|
+
}
|
|
3333
|
+
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
3334
|
+
"scss",
|
|
3335
|
+
"sass",
|
|
3336
|
+
"less",
|
|
3337
|
+
"styl",
|
|
3338
|
+
"stylus"
|
|
3339
|
+
]);
|
|
3340
|
+
const INLINE_LANG_RE = /lang\.([a-z]+)/i;
|
|
3341
|
+
const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
3342
|
+
const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
3343
|
+
const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
3344
|
+
const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
|
|
3345
|
+
function isPreprocessorRequest(id, lang) {
|
|
3346
|
+
const normalizedLang = lang?.toLowerCase();
|
|
3347
|
+
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
3348
|
+
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
3349
|
+
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
3350
|
+
return PREPROCESSOR_EXT_RE.test(id);
|
|
3351
|
+
}
|
|
3352
|
+
function resolveUniAppXCssTarget(id) {
|
|
3353
|
+
return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
|
|
3354
|
+
}
|
|
3355
|
+
function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
3356
|
+
return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
|
|
3357
|
+
}
|
|
3358
|
+
function isCssModuleExport(code) {
|
|
3359
|
+
return CSS_MODULE_EXPORT_RE.test(code);
|
|
3360
|
+
}
|
|
3361
|
+
function createUniAppXPlugins(options) {
|
|
3362
|
+
const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX } = options;
|
|
3363
|
+
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
|
|
3364
|
+
const utsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3365
|
+
const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
|
|
3366
|
+
const isHarmonyPlatform = utsPlatform.isAppHarmony;
|
|
3367
|
+
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
3368
|
+
let componentLocalStyleEnabled;
|
|
3369
|
+
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
3370
|
+
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
3371
|
+
function rememberHarmonyApplySource(code) {
|
|
3372
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
3373
|
+
if (styleSources.length === 0) return;
|
|
3374
|
+
for (const styleSource of styleSources) {
|
|
3375
|
+
harmonyApplyStyleSources.add(styleSource);
|
|
3376
|
+
for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
|
|
3377
|
+
}
|
|
3312
3378
|
}
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3379
|
+
function shouldEnableComponentLocalStyle() {
|
|
3380
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
|
|
3381
|
+
componentLocalStyleEnabled = false;
|
|
3382
|
+
return false;
|
|
3383
|
+
}
|
|
3384
|
+
if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
|
|
3385
|
+
componentLocalStyleEnabled = true;
|
|
3386
|
+
return true;
|
|
3387
|
+
}
|
|
3388
|
+
if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
|
|
3389
|
+
const root = getResolvedConfig()?.root;
|
|
3390
|
+
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
3391
|
+
return componentLocalStyleEnabled;
|
|
3392
|
+
}
|
|
3393
|
+
function shouldEnableHarmonyPageLocalStyle() {
|
|
3394
|
+
return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
|
|
3395
|
+
}
|
|
3396
|
+
function isHarmonyBuildTarget() {
|
|
3397
|
+
if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
|
|
3398
|
+
return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
|
|
3399
|
+
}
|
|
3400
|
+
async function transformStyle(code, id, query, hookContext) {
|
|
3401
|
+
const parsed = query ?? parseVueRequest(id).query;
|
|
3402
|
+
if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
3403
|
+
if (isCssModuleExport(code)) return;
|
|
3404
|
+
const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
|
|
3405
|
+
rememberHarmonyApplySource(code);
|
|
3406
|
+
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
3407
|
+
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
3408
|
+
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
3409
|
+
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
3410
|
+
if (!styleHandlerOptions) {
|
|
3411
|
+
styleHandlerOptions = require_v4_engine.omitUndefined({
|
|
3412
|
+
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
3413
|
+
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
3414
|
+
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
3415
|
+
postcssOptions: { options: {
|
|
3416
|
+
from: id,
|
|
3417
|
+
map: {
|
|
3418
|
+
inline: false,
|
|
3419
|
+
annotation: false,
|
|
3420
|
+
sourcesContent: true
|
|
3421
|
+
}
|
|
3422
|
+
} }
|
|
3423
|
+
});
|
|
3424
|
+
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
3328
3425
|
}
|
|
3329
|
-
|
|
3426
|
+
const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
|
|
3427
|
+
const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
|
|
3428
|
+
for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
|
|
3429
|
+
const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
|
|
3430
|
+
return {
|
|
3431
|
+
code: postcssResult.css,
|
|
3432
|
+
map: postcssMap
|
|
3433
|
+
};
|
|
3330
3434
|
}
|
|
3331
3435
|
}
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3436
|
+
const cssPlugins = [{
|
|
3437
|
+
name: "weapp-tailwindcss:uni-app-x:css",
|
|
3438
|
+
async transform(code, id) {
|
|
3439
|
+
if (!isEnabled()) return;
|
|
3440
|
+
await runtimeState.readyPromise;
|
|
3441
|
+
return transformStyle(code, id, void 0, this);
|
|
3442
|
+
}
|
|
3443
|
+
}, {
|
|
3444
|
+
name: "weapp-tailwindcss:uni-app-x:css:pre",
|
|
3445
|
+
enforce: "pre",
|
|
3446
|
+
async transform(code, id) {
|
|
3447
|
+
if (!isEnabled()) return;
|
|
3448
|
+
await runtimeState.readyPromise;
|
|
3449
|
+
const { query } = parseVueRequest(id);
|
|
3450
|
+
const lang = query.lang;
|
|
3451
|
+
if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
|
|
3452
|
+
return transformStyle(code, id, query, this);
|
|
3453
|
+
}
|
|
3454
|
+
}];
|
|
3455
|
+
const nvuePlugin = {
|
|
3456
|
+
name: "weapp-tailwindcss:uni-app-x:nvue",
|
|
3457
|
+
enforce: "pre",
|
|
3458
|
+
async buildStart() {
|
|
3459
|
+
if (!isEnabled()) return;
|
|
3460
|
+
await ensureRuntimeClassSet(true);
|
|
3353
3461
|
},
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3462
|
+
async transform(code, id) {
|
|
3463
|
+
if (!isEnabled()) return;
|
|
3464
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3465
|
+
rememberHarmonyApplySource(code);
|
|
3466
|
+
const resolvedConfig = getResolvedConfig();
|
|
3467
|
+
const isServeCommand = resolvedConfig?.command === "serve";
|
|
3468
|
+
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
3469
|
+
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
3470
|
+
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
3471
|
+
const transformUVue = await loadTransformUVue();
|
|
3472
|
+
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
3473
|
+
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
3474
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
|
|
3475
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
3476
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
3477
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
3478
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
3479
|
+
}));
|
|
3480
|
+
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
3357
3481
|
},
|
|
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 };
|
|
3482
|
+
async handleHotUpdate(ctx) {
|
|
3483
|
+
if (!isEnabled()) return;
|
|
3484
|
+
if (getResolvedConfig()?.command !== "serve") return;
|
|
3485
|
+
if (!UVUE_NVUE_RE.test(ctx.file)) return;
|
|
3486
|
+
await ensureRuntimeClassSet(true);
|
|
3487
|
+
},
|
|
3488
|
+
async watchChange(id) {
|
|
3489
|
+
if (!isEnabled()) return;
|
|
3490
|
+
const resolvedConfig = getResolvedConfig();
|
|
3491
|
+
if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
|
|
3492
|
+
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3493
|
+
await ensureRuntimeClassSet(true);
|
|
3380
3494
|
}
|
|
3381
|
-
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3495
|
+
};
|
|
3496
|
+
const stylePlaceholderPlugin = {
|
|
3497
|
+
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
3498
|
+
enforce: "post",
|
|
3499
|
+
generateBundle: {
|
|
3500
|
+
order: "post",
|
|
3501
|
+
async handler(_options, bundle) {
|
|
3502
|
+
if (!isEnabled()) return;
|
|
3503
|
+
const currentUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
3504
|
+
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
3505
|
+
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
3506
|
+
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
3507
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3508
|
+
if (isHarmonyTarget) {
|
|
3509
|
+
const cssSources = [];
|
|
3510
|
+
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
3511
|
+
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
3512
|
+
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
3513
|
+
const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
|
|
3514
|
+
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
3515
|
+
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
3516
|
+
}
|
|
3517
|
+
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
3518
|
+
cssSources,
|
|
3519
|
+
excludeComponents: shouldEnableComponentLocalStyle()
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
3523
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
3524
|
+
const currentSource = String(item.source);
|
|
3525
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
3526
|
+
if (nextSource !== currentSource) item.source = nextSource;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3405
3529
|
}
|
|
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
3530
|
};
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3531
|
+
return [
|
|
3532
|
+
...cssPlugins,
|
|
3533
|
+
nvuePlugin,
|
|
3534
|
+
stylePlaceholderPlugin
|
|
3535
|
+
];
|
|
3536
|
+
}
|
|
3537
|
+
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
3538
|
+
return async () => {
|
|
3539
|
+
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
3540
|
+
const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
|
|
3541
|
+
const rawSource = originalSource.source.toString();
|
|
3542
|
+
await require_hmr_timing.processCachedTask({
|
|
3543
|
+
cache,
|
|
3544
|
+
cacheKey: file,
|
|
3545
|
+
hashKey,
|
|
3546
|
+
rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
|
|
3547
|
+
applyResult(source) {
|
|
3548
|
+
originalSource.source = source;
|
|
3549
|
+
},
|
|
3550
|
+
onCacheHit() {
|
|
3551
|
+
debug("js cache hit: %s", file);
|
|
3552
|
+
},
|
|
3553
|
+
async transform() {
|
|
3554
|
+
const currentSource = originalSource.source.toString();
|
|
3555
|
+
const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
|
|
3556
|
+
uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
|
|
3557
|
+
babelParserOptions: {
|
|
3558
|
+
plugins: ["typescript"],
|
|
3559
|
+
sourceType: "unambiguous"
|
|
3560
|
+
}
|
|
3561
|
+
}));
|
|
3562
|
+
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
3563
|
+
onUpdate(file, currentSource, nextCode);
|
|
3564
|
+
debug("js handle: %s", file);
|
|
3565
|
+
applyLinkedResults(linked);
|
|
3566
|
+
return { result: nextCode };
|
|
3567
|
+
}
|
|
3420
3568
|
});
|
|
3421
3569
|
};
|
|
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
3570
|
}
|
|
3437
3571
|
//#endregion
|
|
3438
3572
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
@@ -3540,7 +3674,7 @@ function processJsBundleEntry(options) {
|
|
|
3540
3674
|
}
|
|
3541
3675
|
const currentSource = originalEntrySource;
|
|
3542
3676
|
const precheckOptions = createHandlerOptions(node_path.default.resolve(outDir, file), {
|
|
3543
|
-
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
3677
|
+
uniAppX: resolveUniAppXJsTransformEnabled$1(uniAppX),
|
|
3544
3678
|
babelParserOptions: {
|
|
3545
3679
|
plugins: ["typescript"],
|
|
3546
3680
|
sourceType: "unambiguous"
|
|
@@ -4208,27 +4342,6 @@ function createTransformFilterSignature(options) {
|
|
|
4208
4342
|
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
4209
4343
|
}
|
|
4210
4344
|
//#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
4345
|
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
4233
4346
|
function resolveSourceRootCandidate(root, value) {
|
|
4234
4347
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
@@ -4290,16 +4403,35 @@ function inferPlatformFromViteOutDir$1(outDir) {
|
|
|
4290
4403
|
const normalized = segment.trim().toLowerCase();
|
|
4291
4404
|
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
4292
4405
|
}
|
|
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
4406
|
function createGenerateBundleHook(context) {
|
|
4298
4407
|
const state = require_source_candidate_scan_signature.createBundleBuildState();
|
|
4299
4408
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4300
4409
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4301
4410
|
let currentOutDir;
|
|
4302
4411
|
let currentSubpackageRoots;
|
|
4412
|
+
const createInitialCssPipelineContext = (file) => {
|
|
4413
|
+
const resolvedConfig = context.getResolvedConfig();
|
|
4414
|
+
const platform = context.opts.cssOptions?.platform ?? context.opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4415
|
+
const currentGeneratorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(context.opts.generator, {
|
|
4416
|
+
appType: context.opts.appType,
|
|
4417
|
+
platform,
|
|
4418
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4419
|
+
uniAppX: context.opts.uniAppX
|
|
4420
|
+
});
|
|
4421
|
+
return {
|
|
4422
|
+
currentGeneratorBranch: require_generator.resolveGeneratorRuntimeBranch(currentGeneratorOptions, {
|
|
4423
|
+
appType: context.opts.appType,
|
|
4424
|
+
platform,
|
|
4425
|
+
tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
|
|
4426
|
+
uniAppX: context.opts.uniAppX
|
|
4427
|
+
}),
|
|
4428
|
+
currentGeneratorOptions,
|
|
4429
|
+
file,
|
|
4430
|
+
opts: context.opts,
|
|
4431
|
+
resolvedConfig,
|
|
4432
|
+
resolveStylePlatform: () => platform
|
|
4433
|
+
};
|
|
4434
|
+
};
|
|
4303
4435
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
4304
4436
|
getAppType: () => context.opts.appType,
|
|
4305
4437
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
@@ -4307,7 +4439,7 @@ function createGenerateBundleHook(context) {
|
|
|
4307
4439
|
getOutputRoot: () => currentOutDir,
|
|
4308
4440
|
getExtraOptions: (file) => ({
|
|
4309
4441
|
...resolveViteCssHandlerExtraOptions(file),
|
|
4310
|
-
...
|
|
4442
|
+
...context.cssPipelineStrategy?.getCssHandlerExtraOptions?.(createInitialCssPipelineContext(file)) ?? {},
|
|
4311
4443
|
...currentSubpackageRoots && isSubpackageOutputFile(file, currentSubpackageRoots) ? { isMainChunk: false } : {}
|
|
4312
4444
|
})
|
|
4313
4445
|
});
|
|
@@ -4338,18 +4470,27 @@ function createGenerateBundleHook(context) {
|
|
|
4338
4470
|
uniAppX,
|
|
4339
4471
|
uniUtsPlatform
|
|
4340
4472
|
});
|
|
4473
|
+
const cssPipelineContext = {
|
|
4474
|
+
bundle,
|
|
4475
|
+
currentGeneratorBranch: generatorBranch,
|
|
4476
|
+
currentGeneratorOptions: generatorOptions,
|
|
4477
|
+
opts,
|
|
4478
|
+
resolvedConfig,
|
|
4479
|
+
resolveStylePlatform: () => generatorPlatform
|
|
4480
|
+
};
|
|
4341
4481
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4342
|
-
const
|
|
4343
|
-
const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
|
|
4482
|
+
const shouldApplyWebCssCompat = context.cssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
4344
4483
|
const transformWebTargetCss = (css) => {
|
|
4345
|
-
|
|
4346
|
-
|
|
4484
|
+
return context.cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
4485
|
+
...cssPipelineContext,
|
|
4486
|
+
defaultWebCssCompat: (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true),
|
|
4487
|
+
removeScopedPreflight: (value) => value,
|
|
4488
|
+
shouldApplyWebCssCompat
|
|
4489
|
+
}) ?? (shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true) : css);
|
|
4347
4490
|
};
|
|
4348
|
-
const
|
|
4349
|
-
const
|
|
4350
|
-
const
|
|
4351
|
-
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
4352
|
-
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
4491
|
+
const isNativeAppStyleTarget = context.cssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
4492
|
+
const isHarmonyAppStyleTarget = context.cssPipelineStrategy?.isHarmonyAppStyleTarget?.(cssPipelineContext) === true;
|
|
4493
|
+
const shouldPreserveAppCssExtension = context.cssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? (isNativeAppStyleTarget || isHarmonyAppStyleTarget);
|
|
4353
4494
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
4354
4495
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
4355
4496
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
@@ -4364,6 +4505,8 @@ function createGenerateBundleHook(context) {
|
|
|
4364
4505
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
4365
4506
|
collectViteProcessedCssAssetResults(bundle, {
|
|
4366
4507
|
opts,
|
|
4508
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4509
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
4367
4510
|
isViteProcessedCssAsset,
|
|
4368
4511
|
markCssAssetProcessed,
|
|
4369
4512
|
recordCssAssetResult,
|
|
@@ -4428,20 +4571,32 @@ function createGenerateBundleHook(context) {
|
|
|
4428
4571
|
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4429
4572
|
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4430
4573
|
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4431
|
-
const
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4574
|
+
const isRootStyleOutputFile = (file) => {
|
|
4575
|
+
const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4576
|
+
return normalized.endsWith(".css") && !normalized.includes("/");
|
|
4577
|
+
};
|
|
4578
|
+
const isMiniProgramStyleOutputFile = (file) => /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
4579
|
+
const resolveConfiguredCssEntryRootInjectionTarget = (sourceFile, outputFile) => {
|
|
4580
|
+
if (!outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
|
|
4581
|
+
return context.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
4582
|
+
...cssPipelineContext,
|
|
4583
|
+
bundle,
|
|
4584
|
+
isConfiguredCssEntryFile: (file) => typeof file === "string" && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(file)),
|
|
4585
|
+
isMiniProgramStyleOutputFile,
|
|
4586
|
+
isRootStyleOutputFile,
|
|
4587
|
+
outputFile,
|
|
4588
|
+
sourceFile
|
|
4436
4589
|
});
|
|
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
4590
|
};
|
|
4442
4591
|
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4443
|
-
const
|
|
4444
|
-
|
|
4592
|
+
const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
|
|
4593
|
+
const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
|
|
4594
|
+
if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
|
|
4595
|
+
if (!(context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
|
|
4596
|
+
...cssPipelineContext,
|
|
4597
|
+
isRootStyleOutputFile,
|
|
4598
|
+
outputFile
|
|
4599
|
+
}) === true || cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile))) return;
|
|
4445
4600
|
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4446
4601
|
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4447
4602
|
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
@@ -4614,10 +4769,18 @@ function createGenerateBundleHook(context) {
|
|
|
4614
4769
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4615
4770
|
moduleGraph: moduleGraphOptions
|
|
4616
4771
|
});
|
|
4617
|
-
const
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
}
|
|
4772
|
+
const resolveFrameworkJsHandlerOptions = (absoluteFilename) => context.cssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
4773
|
+
...cssPipelineContext,
|
|
4774
|
+
file: absoluteFilename
|
|
4775
|
+
});
|
|
4776
|
+
const createHandlerOptions = (absoluteFilename, extra) => {
|
|
4777
|
+
const frameworkExtra = resolveFrameworkJsHandlerOptions(absoluteFilename);
|
|
4778
|
+
return createBaseHandlerOptions(absoluteFilename, frameworkExtra || extra ? {
|
|
4779
|
+
...frameworkExtra,
|
|
4780
|
+
...extra
|
|
4781
|
+
} : void 0);
|
|
4782
|
+
};
|
|
4783
|
+
const shouldTransformJsBundle = !isWebGeneratorTarget || context.cssPipelineStrategy?.shouldTransformServeJs?.(cssPipelineContext) === true;
|
|
4621
4784
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4622
4785
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4623
4786
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4674,12 +4837,18 @@ function createGenerateBundleHook(context) {
|
|
|
4674
4837
|
metrics.css.total++;
|
|
4675
4838
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
4676
4839
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
4840
|
+
const cssPipelineContext = {
|
|
4841
|
+
...createInitialCssPipelineContext(file),
|
|
4842
|
+
bundle
|
|
4843
|
+
};
|
|
4677
4844
|
let outputFile = resolveCssBundleOutputFile({
|
|
4678
4845
|
bundleFiles,
|
|
4846
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4679
4847
|
defaultStyleOutputExtension,
|
|
4680
4848
|
file,
|
|
4681
4849
|
isWebGeneratorTarget,
|
|
4682
4850
|
opts,
|
|
4851
|
+
pipelineContext: cssPipelineContext,
|
|
4683
4852
|
shouldPreserveAppCssExtension
|
|
4684
4853
|
});
|
|
4685
4854
|
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
@@ -4688,6 +4857,13 @@ function createGenerateBundleHook(context) {
|
|
|
4688
4857
|
originalFileNames: originalSource.originalFileNames,
|
|
4689
4858
|
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4690
4859
|
});
|
|
4860
|
+
const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((entry) => originalSource.originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true) : void 0;
|
|
4861
|
+
const configuredOriginalOutputFile = configuredOriginalSourceEntry ? resolveMatchedOutputFileForCurrentAsset(configuredOriginalSourceEntry.file) : void 0;
|
|
4862
|
+
let resolvedFromConfiguredOriginalCssEntry = false;
|
|
4863
|
+
if (configuredOriginalOutputFile && require_source_candidate_scan_signature.normalizeOutputPathKey(configuredOriginalOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile)) {
|
|
4864
|
+
outputFile = configuredOriginalOutputFile;
|
|
4865
|
+
resolvedFromConfiguredOriginalCssEntry = true;
|
|
4866
|
+
}
|
|
4691
4867
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4692
4868
|
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile, opts.cssMatcher)) {
|
|
4693
4869
|
delete bundle[file];
|
|
@@ -4699,13 +4875,14 @@ function createGenerateBundleHook(context) {
|
|
|
4699
4875
|
let resolvedFromTemporaryCssAsset = false;
|
|
4700
4876
|
const applyCssResult = (source) => {
|
|
4701
4877
|
applyCssResultToBundle({
|
|
4702
|
-
appType: opts.appType,
|
|
4703
4878
|
assetSourceFile,
|
|
4704
4879
|
bundle,
|
|
4880
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
4705
4881
|
emitOrReplayCssAsset,
|
|
4706
4882
|
file,
|
|
4707
4883
|
originalSource,
|
|
4708
4884
|
outputFile,
|
|
4885
|
+
pipelineContext: cssPipelineContext,
|
|
4709
4886
|
source,
|
|
4710
4887
|
viteProcessedCssAsset
|
|
4711
4888
|
});
|
|
@@ -4772,7 +4949,7 @@ function createGenerateBundleHook(context) {
|
|
|
4772
4949
|
if (!hasUsableRememberedTailwindSource) {
|
|
4773
4950
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4774
4951
|
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
4775
|
-
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 :
|
|
4952
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
|
|
4776
4953
|
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
4777
4954
|
outputFile,
|
|
4778
4955
|
rawSource: inferredWebviewRootSourceEntry.source,
|
|
@@ -4860,7 +5037,7 @@ function createGenerateBundleHook(context) {
|
|
|
4860
5037
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
4861
5038
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4862
5039
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4863
|
-
const webviewRootCssInjectionTarget = vitePipelineCssAsset ?
|
|
5040
|
+
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveConfiguredCssEntryRootInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
4864
5041
|
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
5042
|
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
4866
5043
|
usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(generatorSourceFile));
|
|
@@ -4901,7 +5078,7 @@ function createGenerateBundleHook(context) {
|
|
|
4901
5078
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4902
5079
|
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
4903
5080
|
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));
|
|
5081
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
4905
5082
|
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
5083
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource));
|
|
4907
5084
|
const strippedViteProcessedCss = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
|
|
@@ -5047,7 +5224,7 @@ function createGenerateBundleHook(context) {
|
|
|
5047
5224
|
continue;
|
|
5048
5225
|
}
|
|
5049
5226
|
if (type !== "js") continue;
|
|
5050
|
-
if (
|
|
5227
|
+
if (!shouldTransformJsBundle) {
|
|
5051
5228
|
debug("js skip web target: %s", file);
|
|
5052
5229
|
continue;
|
|
5053
5230
|
}
|
|
@@ -5129,6 +5306,8 @@ function createGenerateBundleHook(context) {
|
|
|
5129
5306
|
bundleFiles,
|
|
5130
5307
|
cache,
|
|
5131
5308
|
cssTaskFactories,
|
|
5309
|
+
cssPipelineStrategy: context.cssPipelineStrategy,
|
|
5310
|
+
createCssPipelineContext: () => cssPipelineContext,
|
|
5132
5311
|
debug,
|
|
5133
5312
|
defaultStyleOutputExtension,
|
|
5134
5313
|
formatIteration: useIncrementalMode ? state.iteration : 0,
|
|
@@ -5202,9 +5381,9 @@ function registerGeneratorDependencies(ctx, dependencies) {
|
|
|
5202
5381
|
throw error;
|
|
5203
5382
|
}
|
|
5204
5383
|
}
|
|
5205
|
-
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
5384
|
+
function createCssHandlerOptions(opts, majorVersion, file, extraOptions = {}) {
|
|
5206
5385
|
return {
|
|
5207
|
-
...
|
|
5386
|
+
...extraOptions,
|
|
5208
5387
|
cssPreflight: opts.cssPreflight,
|
|
5209
5388
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
5210
5389
|
postcssOptions: { options: { from: file } },
|
|
@@ -5229,13 +5408,15 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
5229
5408
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
5230
5409
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
5231
5410
|
}
|
|
5232
|
-
function
|
|
5233
|
-
const
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5411
|
+
function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
5412
|
+
const shouldApplyWebCssCompat = cssPipelineStrategy?.shouldApplyWebCssCompat?.(context) === true;
|
|
5413
|
+
const defaultWebCssCompat = (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true);
|
|
5414
|
+
return cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
5415
|
+
...context,
|
|
5416
|
+
defaultWebCssCompat,
|
|
5417
|
+
removeScopedPreflight: (value) => value,
|
|
5418
|
+
shouldApplyWebCssCompat
|
|
5419
|
+
}) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
|
|
5239
5420
|
}
|
|
5240
5421
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
5241
5422
|
return {
|
|
@@ -5244,7 +5425,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5244
5425
|
generateBundle: {
|
|
5245
5426
|
order: "post",
|
|
5246
5427
|
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;
|
|
5428
|
+
const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
5248
5429
|
const resolvedConfig = getResolvedConfig();
|
|
5249
5430
|
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
5250
5431
|
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
@@ -5263,11 +5444,16 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5263
5444
|
uniUtsPlatform
|
|
5264
5445
|
});
|
|
5265
5446
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
5266
|
-
const
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5447
|
+
const createCssPipelineContext = (_file) => ({
|
|
5448
|
+
bundle,
|
|
5449
|
+
currentGeneratorBranch: generatorBranch,
|
|
5450
|
+
currentGeneratorOptions: generatorOptions,
|
|
5451
|
+
opts,
|
|
5452
|
+
resolvedConfig,
|
|
5453
|
+
resolveStylePlatform: () => generatorPlatform
|
|
5454
|
+
});
|
|
5455
|
+
const isHarmonyAppStyleTarget = cssPipelineStrategy?.isHarmonyAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5456
|
+
const isNativeAppStyleTarget = cssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5271
5457
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
5272
5458
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
5273
5459
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -5279,30 +5465,32 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5279
5465
|
const collectViteProcessedCssAssets = () => {
|
|
5280
5466
|
collectViteProcessedCssAssetResults(bundle, {
|
|
5281
5467
|
opts,
|
|
5468
|
+
cssPipelineStrategy,
|
|
5469
|
+
createCssPipelineContext,
|
|
5282
5470
|
isViteProcessedCssAsset,
|
|
5283
5471
|
markCssAssetProcessed,
|
|
5284
5472
|
recordCssAssetResult,
|
|
5285
5473
|
recordViteProcessedCssAssetResult,
|
|
5286
5474
|
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
|
-
}),
|
|
5475
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5476
|
+
...createCssPipelineContext(file),
|
|
5477
|
+
file
|
|
5478
|
+
}, cssPipelineStrategy),
|
|
5292
5479
|
debug
|
|
5293
5480
|
});
|
|
5294
5481
|
};
|
|
5295
5482
|
const injectViteProcessedCssIntoMainCss = () => {
|
|
5296
5483
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
5297
5484
|
opts,
|
|
5485
|
+
cssPipelineStrategy,
|
|
5486
|
+
createCssPipelineContext,
|
|
5298
5487
|
getViteProcessedCssAssetResults,
|
|
5299
5488
|
markCssAssetProcessed,
|
|
5300
5489
|
recordCssAssetResult,
|
|
5301
|
-
transformCss: (css) => finalizeWebCss(css,
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
}),
|
|
5490
|
+
transformCss: (css, file) => finalizeWebCss(css, {
|
|
5491
|
+
...createCssPipelineContext(file),
|
|
5492
|
+
file
|
|
5493
|
+
}, cssPipelineStrategy),
|
|
5306
5494
|
debug,
|
|
5307
5495
|
onUpdate: opts.onUpdate
|
|
5308
5496
|
});
|
|
@@ -5314,7 +5502,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5314
5502
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
5315
5503
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
5316
5504
|
const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
|
|
5317
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css"
|
|
5505
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5506
|
+
...createCssPipelineContext("uni-app-x-harmony-apply.css"),
|
|
5507
|
+
file: "uni-app-x-harmony-apply.css"
|
|
5508
|
+
}) ?? {});
|
|
5318
5509
|
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
5319
5510
|
opts,
|
|
5320
5511
|
runtimeState,
|
|
@@ -5349,10 +5540,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5349
5540
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
5350
5541
|
collectViteProcessedCssAssets();
|
|
5351
5542
|
injectViteProcessedCssIntoMainCss();
|
|
5352
|
-
|
|
5353
|
-
appType: opts.appType,
|
|
5543
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5354
5544
|
cssMatcher: opts.cssMatcher,
|
|
5355
5545
|
debug,
|
|
5546
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5356
5547
|
onUpdate: opts.onUpdate,
|
|
5357
5548
|
recordCssAssetResult
|
|
5358
5549
|
});
|
|
@@ -5367,18 +5558,20 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5367
5558
|
const file = output.fileName || bundleFile;
|
|
5368
5559
|
const rawSource = output.source.toString();
|
|
5369
5560
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
5370
|
-
const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource),
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
}));
|
|
5561
|
+
const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource), {
|
|
5562
|
+
...createCssPipelineContext(file),
|
|
5563
|
+
file
|
|
5564
|
+
}, cssPipelineStrategy));
|
|
5375
5565
|
output.source = nextCss;
|
|
5376
5566
|
markCssAssetProcessed(output, file);
|
|
5377
5567
|
recordCssAssetResult?.(file, nextCss);
|
|
5378
5568
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
5379
5569
|
return;
|
|
5380
5570
|
}
|
|
5381
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file
|
|
5571
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5572
|
+
...createCssPipelineContext(file),
|
|
5573
|
+
file
|
|
5574
|
+
}) ?? {});
|
|
5382
5575
|
const cssUserHandlerOptions = {
|
|
5383
5576
|
...cssHandlerOptions,
|
|
5384
5577
|
isMainChunk: false
|
|
@@ -5387,7 +5580,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5387
5580
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
5388
5581
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
5389
5582
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
5390
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile
|
|
5583
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5584
|
+
...createCssPipelineContext(generatorSourceFile),
|
|
5585
|
+
file: generatorSourceFile
|
|
5586
|
+
}) ?? {}) : cssHandlerOptions;
|
|
5391
5587
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
5392
5588
|
...generatorCssHandlerOptions,
|
|
5393
5589
|
isMainChunk: false
|
|
@@ -5406,11 +5602,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5406
5602
|
styleHandler: opts.styleHandler,
|
|
5407
5603
|
debug
|
|
5408
5604
|
}) : void 0;
|
|
5409
|
-
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource,
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
}) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5605
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, {
|
|
5606
|
+
...createCssPipelineContext(file),
|
|
5607
|
+
file
|
|
5608
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
5414
5609
|
if (generated) {
|
|
5415
5610
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
5416
5611
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5425,10 +5620,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5425
5620
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
5426
5621
|
collectViteProcessedCssAssets();
|
|
5427
5622
|
injectViteProcessedCssIntoMainCss();
|
|
5428
|
-
|
|
5429
|
-
appType: opts.appType,
|
|
5623
|
+
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
5430
5624
|
cssMatcher: opts.cssMatcher,
|
|
5431
5625
|
debug,
|
|
5626
|
+
enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
|
|
5432
5627
|
onUpdate: opts.onUpdate,
|
|
5433
5628
|
recordCssAssetResult
|
|
5434
5629
|
});
|
|
@@ -6199,7 +6394,7 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
6199
6394
|
return resolvedRoot;
|
|
6200
6395
|
}
|
|
6201
6396
|
//#endregion
|
|
6202
|
-
//#region src/bundlers/vite/
|
|
6397
|
+
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
6203
6398
|
const debug = require_context.createDebug();
|
|
6204
6399
|
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
6205
6400
|
const weappTailwindcssDirPosix = require_source_candidate_scan_signature.slash(weappTailwindcssPackageDir);
|
|
@@ -6238,23 +6433,22 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
6238
6433
|
function isWebOrNativeAppPlatform(platform) {
|
|
6239
6434
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
6240
6435
|
}
|
|
6241
|
-
function
|
|
6242
|
-
return
|
|
6436
|
+
function applyViteWebCssCompat(css, options) {
|
|
6437
|
+
return (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, options.compat);
|
|
6243
6438
|
}
|
|
6244
|
-
function
|
|
6245
|
-
|
|
6246
|
-
return options.safeSelectors ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
6439
|
+
function isInternalUserDefinedOptions(options) {
|
|
6440
|
+
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
6247
6441
|
}
|
|
6248
6442
|
/**
|
|
6249
|
-
*
|
|
6250
|
-
* @description uni-app vite / uni-app-x 版本插件
|
|
6251
|
-
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
6443
|
+
* Vite 各框架分支共享的组合工厂。框架分支只负责选择和拥有各自入口,公共稳定能力放在这里复用。
|
|
6252
6444
|
*/
|
|
6253
|
-
function
|
|
6254
|
-
|
|
6255
|
-
const
|
|
6256
|
-
const
|
|
6257
|
-
const
|
|
6445
|
+
function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
6446
|
+
debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
|
|
6447
|
+
const rawOptions = options.__internalViteRawOptions ?? options;
|
|
6448
|
+
const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
6449
|
+
const hasExplicitTailwindcssBasedir = typeof options.__internalViteRawExplicitTailwindcssBasedir === "boolean" ? options.__internalViteRawExplicitTailwindcssBasedir : typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
6450
|
+
const rawCssEntries = collectConfiguredCssEntries(rawOptions);
|
|
6451
|
+
const opts = isInternalUserDefinedOptions(options) ? options : require_context.getCompilerContext({
|
|
6258
6452
|
...options,
|
|
6259
6453
|
__internalDeferMissingCssEntriesWarning: true
|
|
6260
6454
|
});
|
|
@@ -6275,8 +6469,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6275
6469
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler, styleInjector } = opts;
|
|
6276
6470
|
const initialTailwindRuntime = tailwindRuntime;
|
|
6277
6471
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
6278
|
-
const
|
|
6279
|
-
const
|
|
6472
|
+
const frameworkCssPipelineStrategy = frameworkBranch.cssPipelineStrategy;
|
|
6473
|
+
const uniAppXEnabled = frameworkBranch.isRuntimeClassSetFeatureEnabled?.({ uniAppX }) === true;
|
|
6474
|
+
const shouldEnableFrameworkExtraPlugins = () => frameworkBranch.createExtraPlugins !== void 0;
|
|
6280
6475
|
const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
|
|
6281
6476
|
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
6282
6477
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
@@ -6305,6 +6500,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6305
6500
|
tailwindcssMajorVersion,
|
|
6306
6501
|
uniAppX
|
|
6307
6502
|
});
|
|
6503
|
+
const createCssPipelineContext = (overrides = {}) => ({
|
|
6504
|
+
currentGeneratorBranch: resolveCurrentGeneratorBranch(),
|
|
6505
|
+
currentGeneratorOptions: resolveCurrentGeneratorOptions(),
|
|
6506
|
+
opts,
|
|
6507
|
+
resolvedConfig,
|
|
6508
|
+
resolveStylePlatform: resolveViteStylePlatform,
|
|
6509
|
+
...overrides
|
|
6510
|
+
});
|
|
6308
6511
|
const initialGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6309
6512
|
const transformEarlyMiniProgramCss = (code) => {
|
|
6310
6513
|
const platform = resolveViteStylePlatform();
|
|
@@ -6321,8 +6524,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
6321
6524
|
};
|
|
6322
6525
|
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
6323
6526
|
const hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots({
|
|
6324
|
-
...
|
|
6325
|
-
cssEntries: opts.cssEntries ??
|
|
6527
|
+
...rawOptions,
|
|
6528
|
+
cssEntries: opts.cssEntries ?? rawOptions.cssEntries
|
|
6326
6529
|
});
|
|
6327
6530
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
6328
6531
|
const transientAutoCssSources = /* @__PURE__ */ new Map();
|
|
@@ -6638,10 +6841,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
6638
6841
|
const isUniViteProject = () => {
|
|
6639
6842
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
6640
6843
|
};
|
|
6641
|
-
const isHarmonyAppBuildTarget = () => {
|
|
6642
|
-
if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
|
|
6643
|
-
return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
|
|
6644
|
-
};
|
|
6645
6844
|
const matchesViteProcessedCssSource = (candidate) => {
|
|
6646
6845
|
const normalized = normalizeViteProcessedCssFile(candidate);
|
|
6647
6846
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
@@ -6661,7 +6860,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6661
6860
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? node_path.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
6662
6861
|
getExtraOptions: (file) => ({
|
|
6663
6862
|
...resolveViteCssHandlerExtraOptions(file),
|
|
6664
|
-
...
|
|
6863
|
+
...frameworkCssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
6864
|
+
...createCssPipelineContext(),
|
|
6865
|
+
file
|
|
6866
|
+
}) ?? {}
|
|
6665
6867
|
}),
|
|
6666
6868
|
getDynamicCssOptions: () => ({ cssPreflight: opts.cssPreflight })
|
|
6667
6869
|
});
|
|
@@ -6674,20 +6876,24 @@ function WeappTailwindcss(options = {}) {
|
|
|
6674
6876
|
await runtimeState.readyPromise;
|
|
6675
6877
|
await waitForSourceCandidateSyncs();
|
|
6676
6878
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
6677
|
-
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id : file;
|
|
6879
|
+
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id === file ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : id : file;
|
|
6678
6880
|
if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
|
|
6679
6881
|
const generatorCode = require_v4_engine.normalizeEmptyTailwindCustomVariants(code);
|
|
6680
6882
|
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
6883
|
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6685
6884
|
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6686
|
-
const
|
|
6885
|
+
const cssPipelineContext = createCssPipelineContext({
|
|
6886
|
+
currentGeneratorBranch,
|
|
6887
|
+
currentGeneratorOptions
|
|
6888
|
+
});
|
|
6889
|
+
const shouldPreserveStyleOutputExtension = frameworkCssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
6890
|
+
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6891
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, shouldPreserveStyleOutputExtension, sourceRoot);
|
|
6687
6892
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6893
|
+
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
6688
6894
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6689
6895
|
const cssHandlerOptions = {
|
|
6690
|
-
...
|
|
6896
|
+
...sourceCssHandlerOptions,
|
|
6691
6897
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6692
6898
|
};
|
|
6693
6899
|
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 +6901,11 @@ function WeappTailwindcss(options = {}) {
|
|
|
6695
6901
|
css: generatorCode,
|
|
6696
6902
|
file: node_path.default.resolve(file)
|
|
6697
6903
|
} : void 0);
|
|
6698
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null &&
|
|
6904
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && (frameworkCssPipelineStrategy?.shouldDeferEmptyScopedCssSource?.({
|
|
6905
|
+
...cssPipelineContext,
|
|
6906
|
+
cssHandlerOptions,
|
|
6907
|
+
generatorCode
|
|
6908
|
+
}) ?? true);
|
|
6699
6909
|
const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
6700
6910
|
opts,
|
|
6701
6911
|
runtimeState,
|
|
@@ -6704,7 +6914,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6704
6914
|
file,
|
|
6705
6915
|
outputFile,
|
|
6706
6916
|
cssHandlerOptions,
|
|
6707
|
-
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(
|
|
6917
|
+
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(requestFile),
|
|
6708
6918
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6709
6919
|
getSourceCandidatesForEntries,
|
|
6710
6920
|
generatorPlatform: resolveGeneratorPlatform(),
|
|
@@ -6716,12 +6926,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6716
6926
|
});
|
|
6717
6927
|
if (!generated) return;
|
|
6718
6928
|
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6719
|
-
const
|
|
6720
|
-
const tracedCss = require_hmr_timing.annotateCssSourceTrace(
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6929
|
+
const shouldApplyWebCssCompat = currentGeneratorBranch.isWeb || frameworkCssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
|
|
6930
|
+
const tracedCss = require_hmr_timing.annotateCssSourceTrace(frameworkCssPipelineStrategy?.transformGeneratedCss?.(finalizedCss, {
|
|
6931
|
+
...cssPipelineContext,
|
|
6932
|
+
defaultWebCssCompat: (css) => applyViteWebCssCompat(css, { compat: currentGeneratorOptions.webCompat ?? true }),
|
|
6933
|
+
removeScopedPreflight: removeScopedTailwindPreflightCss,
|
|
6934
|
+
shouldApplyWebCssCompat
|
|
6935
|
+
}) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ? applyViteWebCssCompat(finalizedCss, { compat: currentGeneratorOptions.webCompat ?? true }) : finalizedCss), {
|
|
6725
6936
|
opts,
|
|
6726
6937
|
tokenSources: require_hmr_timing.createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6727
6938
|
});
|
|
@@ -6736,7 +6947,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6736
6947
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6737
6948
|
outputFile
|
|
6738
6949
|
});
|
|
6739
|
-
if (
|
|
6950
|
+
if (shouldPreserveStyleOutputExtension && outputFile.endsWith(".css")) hookContext?.emitFile?.({
|
|
6740
6951
|
type: "asset",
|
|
6741
6952
|
fileName: outputFile,
|
|
6742
6953
|
source: tracedCss
|
|
@@ -6747,9 +6958,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
6747
6958
|
cssMemory.rememberCssSource({
|
|
6748
6959
|
outputFile,
|
|
6749
6960
|
rawSource: code,
|
|
6750
|
-
sourceFile:
|
|
6961
|
+
sourceFile: requestFile
|
|
6751
6962
|
});
|
|
6752
|
-
debug("css generated for vite postcss pipeline: %s bytes=%d",
|
|
6963
|
+
debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
|
|
6753
6964
|
return `${require_source_candidate_scan_signature.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
6754
6965
|
};
|
|
6755
6966
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
@@ -6795,12 +7006,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
6795
7006
|
recordGeneratorCandidates,
|
|
6796
7007
|
pruneViteCssCaches,
|
|
6797
7008
|
getViteCssCacheStats,
|
|
6798
|
-
hmrTimingRecorder
|
|
7009
|
+
hmrTimingRecorder,
|
|
7010
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy
|
|
6799
7011
|
});
|
|
6800
7012
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
6801
7013
|
opts,
|
|
6802
7014
|
runtimeState,
|
|
6803
7015
|
ensureRuntimeClassSet,
|
|
7016
|
+
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
6804
7017
|
debug,
|
|
6805
7018
|
getResolvedConfig,
|
|
6806
7019
|
markCssAssetProcessed,
|
|
@@ -6821,25 +7034,25 @@ function WeappTailwindcss(options = {}) {
|
|
|
6821
7034
|
}),
|
|
6822
7035
|
getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
|
|
6823
7036
|
});
|
|
6824
|
-
const
|
|
7037
|
+
const extraPluginPlatform = frameworkBranch.getExtraPluginPlatform?.() ?? {};
|
|
6825
7038
|
const prepareTailwindGeneration = async () => {
|
|
6826
7039
|
if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
|
|
6827
7040
|
await syncSourceCandidateScan();
|
|
6828
7041
|
};
|
|
6829
|
-
const
|
|
6830
|
-
appType: opts.appType ?? "uni-app-x",
|
|
7042
|
+
const extraPlugins = frameworkBranch.createExtraPlugins?.({
|
|
6831
7043
|
customAttributesEntities,
|
|
6832
7044
|
disabledDefaultTemplateHandler,
|
|
6833
|
-
|
|
7045
|
+
ensureRuntimeClassSet,
|
|
7046
|
+
generateCss: generateTailwindCssForVitePipeline,
|
|
7047
|
+
getResolvedConfig,
|
|
7048
|
+
isEnabled: shouldEnableFrameworkExtraPlugins,
|
|
7049
|
+
isIosPlatform: extraPluginPlatform.isIosPlatform === true,
|
|
7050
|
+
jsHandler,
|
|
6834
7051
|
mainCssChunkMatcher,
|
|
6835
7052
|
runtimeState,
|
|
6836
7053
|
styleHandler,
|
|
6837
|
-
generateCss: generateTailwindCssForVitePipeline,
|
|
6838
|
-
jsHandler,
|
|
6839
|
-
ensureRuntimeClassSet,
|
|
6840
|
-
getResolvedConfig,
|
|
6841
7054
|
uniAppX
|
|
6842
|
-
})
|
|
7055
|
+
}) ?? [];
|
|
6843
7056
|
const plugins = [
|
|
6844
7057
|
...rewritePlugins,
|
|
6845
7058
|
{
|
|
@@ -6938,10 +7151,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
6938
7151
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6939
7152
|
}),
|
|
6940
7153
|
createViteServeJsTransformPlugin({
|
|
6941
|
-
createHandlerOptions: (file) => serveJsHandlerOptions(file,
|
|
7154
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
7155
|
+
...createCssPipelineContext(),
|
|
7156
|
+
file
|
|
7157
|
+
})),
|
|
6942
7158
|
getCommand: () => resolvedConfig?.command,
|
|
6943
7159
|
jsHandler,
|
|
6944
|
-
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb
|
|
7160
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
|
|
6945
7161
|
transformRuntime: ensureRuntimeClassSet
|
|
6946
7162
|
}),
|
|
6947
7163
|
{
|
|
@@ -7016,12 +7232,306 @@ function WeappTailwindcss(options = {}) {
|
|
|
7016
7232
|
}
|
|
7017
7233
|
}
|
|
7018
7234
|
];
|
|
7019
|
-
|
|
7235
|
+
plugins.push(...extraPlugins);
|
|
7020
7236
|
plugins.push(cssFinalizerOutputPlugin);
|
|
7021
|
-
plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () =>
|
|
7237
|
+
plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
|
|
7022
7238
|
return plugins;
|
|
7023
7239
|
}
|
|
7024
7240
|
//#endregion
|
|
7241
|
+
//#region src/bundlers/vite/frameworks/generic/index.ts
|
|
7242
|
+
function createGenericVitePlugins(options = {}) {
|
|
7243
|
+
return createViteFrameworkPlugins(options, {
|
|
7244
|
+
frameworkName: "generic",
|
|
7245
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
|
|
7246
|
+
});
|
|
7247
|
+
}
|
|
7248
|
+
//#endregion
|
|
7249
|
+
//#region src/bundlers/vite/frameworks/taro/index.ts
|
|
7250
|
+
const taroCssPipelineStrategy = {
|
|
7251
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7252
|
+
return true;
|
|
7253
|
+
},
|
|
7254
|
+
shouldMoveRootMiniProgramStyleToImportShellOrigin() {
|
|
7255
|
+
return true;
|
|
7256
|
+
},
|
|
7257
|
+
shouldNormalizeRootMiniProgramImportShell() {
|
|
7258
|
+
return true;
|
|
7259
|
+
}
|
|
7260
|
+
};
|
|
7261
|
+
function createTaroAlipayBrowserslistAssetPlugin() {
|
|
7262
|
+
return {
|
|
7263
|
+
name: "weapp-tailwindcss:taro-alipay-browserslist-asset",
|
|
7264
|
+
enforce: "pre",
|
|
7265
|
+
generateBundle(_options, bundle) {
|
|
7266
|
+
if (node_process.default.env.TARO_ENV !== "alipay") return;
|
|
7267
|
+
bundle[".browserslistrc"] = {
|
|
7268
|
+
type: "asset",
|
|
7269
|
+
fileName: ".browserslistrc",
|
|
7270
|
+
source: "defaults and fully supports es6-module"
|
|
7271
|
+
};
|
|
7272
|
+
}
|
|
7273
|
+
};
|
|
7274
|
+
}
|
|
7275
|
+
function createTaroVitePlugins(options = {}) {
|
|
7276
|
+
return [createTaroAlipayBrowserslistAssetPlugin(), ...createViteFrameworkPlugins(options, {
|
|
7277
|
+
frameworkName: "taro",
|
|
7278
|
+
cssPipelineStrategy: taroCssPipelineStrategy,
|
|
7279
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.taro
|
|
7280
|
+
})];
|
|
7281
|
+
}
|
|
7282
|
+
//#endregion
|
|
7283
|
+
//#region src/bundlers/vite/frameworks/uni-app/index.ts
|
|
7284
|
+
function isUniAppWebviewStylePlatform(platform) {
|
|
7285
|
+
return platform === "app" || platform === "app-plus";
|
|
7286
|
+
}
|
|
7287
|
+
function isUniAppWebviewAppBundle(bundleFiles) {
|
|
7288
|
+
return bundleFiles.some((file) => node_path.default.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
7289
|
+
}
|
|
7290
|
+
function isUniAppWebviewOutDir(outDir) {
|
|
7291
|
+
const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
7292
|
+
return normalized === "app" || normalized === "app-plus";
|
|
7293
|
+
}
|
|
7294
|
+
const uniAppCssPipelineStrategy = {
|
|
7295
|
+
getServeJsHandlerOptions(context) {
|
|
7296
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? { needEscaped: true } : void 0;
|
|
7297
|
+
},
|
|
7298
|
+
shouldApplyWebCssCompat(context) {
|
|
7299
|
+
return isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7300
|
+
},
|
|
7301
|
+
includeTailwindGeneratedCssAssetsInRootCoverage(context) {
|
|
7302
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7303
|
+
},
|
|
7304
|
+
resolveConfiguredCssEntryRootInjectionTarget(context) {
|
|
7305
|
+
if (context.isMiniProgramStyleOutputFile(context.outputFile) || !context.isConfiguredCssEntryFile(context.sourceFile)) return;
|
|
7306
|
+
const rootCssFiles = [];
|
|
7307
|
+
const matchedRootCssFiles = [];
|
|
7308
|
+
for (const [bundleFile, output] of Object.entries(context.bundle)) {
|
|
7309
|
+
if (output.type !== "asset") continue;
|
|
7310
|
+
const file = output.fileName || bundleFile;
|
|
7311
|
+
if (!context.opts.cssMatcher(file) || !context.isRootStyleOutputFile(file) || context.isMiniProgramStyleOutputFile(file)) continue;
|
|
7312
|
+
rootCssFiles.push(file);
|
|
7313
|
+
if (context.opts.mainCssChunkMatcher(file, context.opts.appType)) matchedRootCssFiles.push(file);
|
|
7314
|
+
}
|
|
7315
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
7316
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
7317
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
7318
|
+
},
|
|
7319
|
+
shouldApplyFinalWebviewCssCompat(context) {
|
|
7320
|
+
return isUniAppWebviewAppBundle(context.bundleFiles) || isUniAppWebviewOutDir(context.outDir);
|
|
7321
|
+
},
|
|
7322
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7323
|
+
return true;
|
|
7324
|
+
},
|
|
7325
|
+
shouldPreferExplicitWebCssTargets() {
|
|
7326
|
+
return true;
|
|
7327
|
+
},
|
|
7328
|
+
shouldPreferMatchedRootWebOutputTarget() {
|
|
7329
|
+
return true;
|
|
7330
|
+
},
|
|
7331
|
+
shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml(context) {
|
|
7332
|
+
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7333
|
+
},
|
|
7334
|
+
shouldSelectConfiguredCssEntryRootSource(context) {
|
|
7335
|
+
return context.currentGeneratorBranch.isWeb && context.opts.cssMatcher(context.outputFile) && context.isRootStyleOutputFile(context.outputFile);
|
|
7336
|
+
},
|
|
7337
|
+
shouldTransformServeJs(context) {
|
|
7338
|
+
return !context.currentGeneratorBranch.isWeb || isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7339
|
+
},
|
|
7340
|
+
transformGeneratedCss(css, context) {
|
|
7341
|
+
const webCss = context.shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true) : css;
|
|
7342
|
+
const safeCss = isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(webCss, { escapeMap: context.opts.escapeMap }) : webCss;
|
|
7343
|
+
return context.removeScopedPreflight(safeCss);
|
|
7344
|
+
}
|
|
7345
|
+
};
|
|
7346
|
+
function createUniAppVitePlugins(options = {}) {
|
|
7347
|
+
return createViteFrameworkPlugins(options, {
|
|
7348
|
+
frameworkName: "uni-app",
|
|
7349
|
+
cssPipelineStrategy: uniAppCssPipelineStrategy,
|
|
7350
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp
|
|
7351
|
+
});
|
|
7352
|
+
}
|
|
7353
|
+
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
7354
|
+
"uni-ad-draw",
|
|
7355
|
+
"uni-ad-fullscreen-video",
|
|
7356
|
+
"uni-ad-interactive",
|
|
7357
|
+
"uni-ad-interstitial",
|
|
7358
|
+
"uni-ad-rewarded-video",
|
|
7359
|
+
"uni-ad",
|
|
7360
|
+
"uni-animation-view",
|
|
7361
|
+
"uni-audio",
|
|
7362
|
+
"uni-block",
|
|
7363
|
+
"uni-button",
|
|
7364
|
+
"uni-camera",
|
|
7365
|
+
"uni-canvas",
|
|
7366
|
+
"uni-checkbox-group",
|
|
7367
|
+
"uni-checkbox",
|
|
7368
|
+
"uni-cover-image",
|
|
7369
|
+
"uni-cover-view",
|
|
7370
|
+
"uni-custom-tab-bar",
|
|
7371
|
+
"uni-editor",
|
|
7372
|
+
"uni-form",
|
|
7373
|
+
"uni-icon",
|
|
7374
|
+
"uni-image",
|
|
7375
|
+
"uni-input",
|
|
7376
|
+
"uni-label",
|
|
7377
|
+
"uni-list-item",
|
|
7378
|
+
"uni-list-view",
|
|
7379
|
+
"uni-live-player",
|
|
7380
|
+
"uni-live-pusher",
|
|
7381
|
+
"uni-map",
|
|
7382
|
+
"uni-match-media",
|
|
7383
|
+
"uni-movable-area",
|
|
7384
|
+
"uni-movable-view",
|
|
7385
|
+
"uni-navigation-bar",
|
|
7386
|
+
"uni-navigator",
|
|
7387
|
+
"uni-open-data",
|
|
7388
|
+
"uni-page-meta",
|
|
7389
|
+
"uni-picker-view",
|
|
7390
|
+
"uni-picker",
|
|
7391
|
+
"uni-progress",
|
|
7392
|
+
"uni-radio-group",
|
|
7393
|
+
"uni-radio",
|
|
7394
|
+
"uni-rich-text",
|
|
7395
|
+
"uni-scroll-view",
|
|
7396
|
+
"uni-slider",
|
|
7397
|
+
"uni-sticky-header",
|
|
7398
|
+
"uni-sticky-section",
|
|
7399
|
+
"uni-swiper-item",
|
|
7400
|
+
"uni-swiper",
|
|
7401
|
+
"uni-switch",
|
|
7402
|
+
"uni-template",
|
|
7403
|
+
"uni-text",
|
|
7404
|
+
"uni-textarea",
|
|
7405
|
+
"uni-unicloud-db",
|
|
7406
|
+
"uni-video",
|
|
7407
|
+
"uni-view",
|
|
7408
|
+
"uni-web-view"
|
|
7409
|
+
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
7410
|
+
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
7411
|
+
function withUniAppXWebPreflightReset(css, enabled) {
|
|
7412
|
+
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
7413
|
+
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
7414
|
+
}
|
|
7415
|
+
//#endregion
|
|
7416
|
+
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
7417
|
+
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
7418
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
7419
|
+
if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
7420
|
+
appType: opts.appType,
|
|
7421
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7422
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
7423
|
+
uniUtsPlatform
|
|
7424
|
+
}), {
|
|
7425
|
+
appType: opts.appType,
|
|
7426
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
7427
|
+
uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
|
|
7428
|
+
uniUtsPlatform
|
|
7429
|
+
})) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
|
|
7430
|
+
return {
|
|
7431
|
+
uniAppX: true,
|
|
7432
|
+
uniAppXCssTarget: "uvue",
|
|
7433
|
+
uniAppXUnsupported: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
7434
|
+
};
|
|
7435
|
+
}
|
|
7436
|
+
//#endregion
|
|
7437
|
+
//#region src/bundlers/vite/frameworks/uni-app-x/index.ts
|
|
7438
|
+
function isUniAppXNativeAppStyleTarget() {
|
|
7439
|
+
return require_utils.resolveUniUtsPlatform().isApp;
|
|
7440
|
+
}
|
|
7441
|
+
function isUniAppXHarmonyAppStyleTarget(context) {
|
|
7442
|
+
const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
|
|
7443
|
+
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
7444
|
+
return uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (context.bundle != null && isUniAppXHarmonyBundle(context.bundle) || isUniAppXHarmonyOutDir(context.resolvedConfig?.build?.outDir));
|
|
7445
|
+
}
|
|
7446
|
+
const uniAppXCssPipelineStrategy = {
|
|
7447
|
+
getCssHandlerExtraOptions(context) {
|
|
7448
|
+
return resolveUniAppXNativeCssHandlerOptions(context.opts);
|
|
7449
|
+
},
|
|
7450
|
+
isNativeAppStyleTarget() {
|
|
7451
|
+
return isUniAppXNativeAppStyleTarget();
|
|
7452
|
+
},
|
|
7453
|
+
isHarmonyAppStyleTarget(context) {
|
|
7454
|
+
return isUniAppXHarmonyAppStyleTarget(context);
|
|
7455
|
+
},
|
|
7456
|
+
shouldPreserveStyleOutputExtension(context) {
|
|
7457
|
+
return isUniAppXNativeAppStyleTarget() || isUniAppXHarmonyAppStyleTarget(context);
|
|
7458
|
+
},
|
|
7459
|
+
shouldKeepRootMiniProgramStyleAsImportShell() {
|
|
7460
|
+
return true;
|
|
7461
|
+
},
|
|
7462
|
+
shouldDeferEmptyScopedCssSource(context) {
|
|
7463
|
+
if (!context.cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(context.generatorCode)) return false;
|
|
7464
|
+
return true;
|
|
7465
|
+
},
|
|
7466
|
+
transformGeneratedCss(css, context) {
|
|
7467
|
+
const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
|
|
7468
|
+
return withUniAppXWebPreflightReset(context.removeScopedPreflight(webCss), context.currentGeneratorBranch.isWeb);
|
|
7469
|
+
}
|
|
7470
|
+
};
|
|
7471
|
+
function createUniAppXVitePlugins(options = {}) {
|
|
7472
|
+
return createViteFrameworkPlugins(options, {
|
|
7473
|
+
frameworkName: "uni-app-x",
|
|
7474
|
+
cssPipelineStrategy: uniAppXCssPipelineStrategy,
|
|
7475
|
+
getExtraPluginPlatform: () => ({ isIosPlatform: require_utils.resolveUniUtsPlatform().isAppIos }),
|
|
7476
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp,
|
|
7477
|
+
isRuntimeClassSetFeatureEnabled: () => true,
|
|
7478
|
+
createExtraPlugins: (context) => createUniAppXPlugins({
|
|
7479
|
+
appType: "uni-app-x",
|
|
7480
|
+
customAttributesEntities: context.customAttributesEntities,
|
|
7481
|
+
disabledDefaultTemplateHandler: context.disabledDefaultTemplateHandler,
|
|
7482
|
+
ensureRuntimeClassSet: context.ensureRuntimeClassSet,
|
|
7483
|
+
generateCss: context.generateCss,
|
|
7484
|
+
getResolvedConfig: context.getResolvedConfig,
|
|
7485
|
+
isEnabled: context.isEnabled,
|
|
7486
|
+
isIosPlatform: context.isIosPlatform,
|
|
7487
|
+
jsHandler: context.jsHandler,
|
|
7488
|
+
mainCssChunkMatcher: context.mainCssChunkMatcher,
|
|
7489
|
+
runtimeState: context.runtimeState,
|
|
7490
|
+
styleHandler: context.styleHandler,
|
|
7491
|
+
uniAppX: context.uniAppX
|
|
7492
|
+
})
|
|
7493
|
+
});
|
|
7494
|
+
}
|
|
7495
|
+
//#endregion
|
|
7496
|
+
//#region src/bundlers/vite/frameworks/weapp-vite/index.ts
|
|
7497
|
+
function createWeappVitePlugins(options = {}) {
|
|
7498
|
+
return createViteFrameworkPlugins(options, {
|
|
7499
|
+
frameworkName: "weapp-vite",
|
|
7500
|
+
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
|
|
7501
|
+
});
|
|
7502
|
+
}
|
|
7503
|
+
//#endregion
|
|
7504
|
+
//#region src/bundlers/vite/index.ts
|
|
7505
|
+
/**
|
|
7506
|
+
* @name WeappTailwindcss
|
|
7507
|
+
* @description Vite 入口只负责早期识别框架分支,具体插件组合由各 framework 目录拥有。
|
|
7508
|
+
* @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
|
|
7509
|
+
*/
|
|
7510
|
+
function WeappTailwindcss(options = {}) {
|
|
7511
|
+
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
7512
|
+
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
7513
|
+
const opts = require_context.getCompilerContext({
|
|
7514
|
+
...options,
|
|
7515
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
7516
|
+
});
|
|
7517
|
+
opts.__internalViteRawOptions = options;
|
|
7518
|
+
opts.__internalViteRawExplicitAppType = hasExplicitAppType;
|
|
7519
|
+
opts.__internalViteRawExplicitTailwindcssBasedir = hasExplicitTailwindcssBasedir;
|
|
7520
|
+
switch (require_source_candidate_scan_signature.resolveViteFrameworkProfile({
|
|
7521
|
+
appType: opts.appType,
|
|
7522
|
+
detectEnv: true,
|
|
7523
|
+
env: node_process.default.env,
|
|
7524
|
+
root: opts.tailwindcssBasedir ?? node_process.default.cwd(),
|
|
7525
|
+
uniAppX: opts.uniAppX
|
|
7526
|
+
}).frameworkName) {
|
|
7527
|
+
case "taro": return createTaroVitePlugins(opts);
|
|
7528
|
+
case "uni-app": return createUniAppVitePlugins(opts);
|
|
7529
|
+
case "uni-app-x": return createUniAppXVitePlugins(opts);
|
|
7530
|
+
case "weapp-vite": return createWeappVitePlugins(opts);
|
|
7531
|
+
default: return createGenericVitePlugins(opts);
|
|
7532
|
+
}
|
|
7533
|
+
}
|
|
7534
|
+
//#endregion
|
|
7025
7535
|
Object.defineProperty(exports, "WeappTailwindcss", {
|
|
7026
7536
|
enumerable: true,
|
|
7027
7537
|
get: function() {
|