weapp-tailwindcss 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bundle-state-CBF5YX1m.js → bundle-state-Bvj01pW7.js} +35 -3
- package/dist/{bundle-state-CQmxxx0R.mjs → bundle-state-DY3eq4Gz.mjs} +24 -4
- package/dist/bundlers/shared/generated-css-marker.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -5
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -0
- package/dist/bundlers/shared/generator-css.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +5 -1
- package/dist/bundlers/vite/css-finalizer.d.ts +12 -3
- package/dist/bundlers/vite/generate-bundle.d.ts +22 -6
- package/dist/bundlers/vite/processed-css-assets.d.ts +10 -2
- package/dist/bundlers/vite/source-candidates.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +8 -0
- package/dist/cli.js +1 -0
- package/dist/cli.mjs +1 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-CvmsIQFI.js → generator-Bd1LntD3.js} +1 -1
- package/dist/{generator-DDtsUvkH.mjs → generator-DRHWC1t-.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +16 -10
- package/dist/gulp.mjs +14 -8
- package/dist/{incremental-runtime-class-set-BffodqHh.js → incremental-runtime-class-set-Bl18sFqt.js} +540 -694
- package/dist/{incremental-runtime-class-set-DArodvWs.mjs → incremental-runtime-class-set-CAEuUesH.mjs} +495 -619
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-BzNYQUOH.mjs → postcss-CJrmfXvi.mjs} +4 -4
- package/dist/{postcss-DE0TOtV9.js → postcss-DfnqZ4Bm.js} +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-BzYPm-EG.js → precheck-Bj5ReSOU.js} +2 -2
- package/dist/{precheck-jZvTVXXG.mjs → precheck-CUr1DYyy.mjs} +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{source-candidates-BuTlMabx.mjs → source-candidates-D7b-Jzsx.mjs} +44 -11
- package/dist/{source-candidates-CxoIaS88.js → source-candidates-DQxvGPSw.js} +49 -10
- package/dist/tailwindcss/source-scan.d.ts +3 -1
- package/dist/{tailwindcss-CCZcu0lr.mjs → tailwindcss-D5RogwtV.mjs} +2 -2
- package/dist/{tailwindcss-DZckITp1.js → tailwindcss-jvoYizzX.js} +7 -1
- package/dist/{v3-engine-DGBhUnjn.mjs → v3-engine-BCUGX3gX.mjs} +637 -31
- package/dist/{v3-engine-M6Aqru5T.js → v3-engine-CmIF_gsq.js} +768 -30
- package/dist/{vite-DgRkWVPG.js → vite-D1ZdgbWa.js} +533 -290
- package/dist/{vite-BBcQIJpD.mjs → vite-jBTi5CwO.mjs} +532 -289
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/{runtime-registry-DpcR3IHI.js → watch-dependencies-zwx4EhBn.js} +39 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +1932 -1621
- package/dist/weapp-tw-runtime-classset-loader.js +6 -6
- package/dist/{webpack-D43aMQzO.mjs → webpack-CChDqRrl.mjs} +6 -6
- package/dist/{webpack-D-gb4ZvO.js → webpack-vk2uqSnK.js} +7 -7
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as __esmMin, S as __commonJSMin, _ as toCustomAttributesEntities, a as vitePluginName, c as createAttributeMatcher, d as _defineProperty, f as init_defineProperty, h as babelParse, l as analyzeSource, m as replaceWxml, n as getCompilerContext, p as isClassContextLiteralPath, s as generateCode, t as shouldSkipJsTransform, u as JsTokenUpdater, v as collectRuntimeClassSet, w as __require, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-
|
|
2
|
-
import {
|
|
3
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
4
|
-
import { a as validateCandidatesByGenerator, c as hasTailwindRootDirectives, f as hasTailwindGeneratedCssMarkers, i as generateCssByGenerator, l as hasTailwindSourceDirectives, n as createHmrTimingRecorder, o as mergeMarkedUserLayerComponentsCss, s as processCachedTask, t as createBundleRuntimeClassSetManager, u as normalizeTailwindSourceForGenerator } from "./incremental-runtime-class-set-DArodvWs.mjs";
|
|
1
|
+
import { C as __esmMin, S as __commonJSMin, _ as toCustomAttributesEntities, a as vitePluginName, c as createAttributeMatcher, d as _defineProperty, f as init_defineProperty, h as babelParse, l as analyzeSource, m as replaceWxml, n as getCompilerContext, p as isClassContextLiteralPath, s as generateCode, t as shouldSkipJsTransform, u as JsTokenUpdater, v as collectRuntimeClassSet, w as __require, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-CUr1DYyy.mjs";
|
|
2
|
+
import { E as normalizeTailwindConfigDirectives, I as hasTailwindGeneratedCssMarkers, J as filterUnsupportedMiniProgramTailwindV4Candidates, O as normalizeTailwindSourceForGenerator, T as hasTailwindSourceDirectives, _ as resolveViteSourceScanEntries, ct as createDebug, dt as findTailwindConfig, ft as resolveTailwindcssOptions, g as resolveTailwindV4EntriesFromCssCached, gt as findNearestPackageRoot, ht as omitUndefined, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, ot as resolveTailwindV4CssSourceBase, p as createViteSourceScanMatcher, v as resolveViteTailwindV4CssDependencies, w as hasTailwindRootDirectives } from "./v3-engine-BCUGX3gX.mjs";
|
|
3
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-DRHWC1t-.mjs";
|
|
5
4
|
import { o as resolveUniUtsPlatform } from "./utils-DsaS975I.mjs";
|
|
6
|
-
import { c as
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
5
|
+
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-D5RogwtV.mjs";
|
|
6
|
+
import { a as validateCandidatesByGenerator, i as generateCssByGenerator, n as createHmrTimingRecorder, o as mergeMarkedUserLayerComponentsCss, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-CAEuUesH.mjs";
|
|
7
|
+
import { n as createTailwindV3DefaultExtractor, r as isSourceCandidateRequest, t as createSourceCandidateCollector } from "./source-candidates-D7b-Jzsx.mjs";
|
|
8
|
+
import { S as toAbsoluteOutputPath, _ as slash, a as applyLinkedResults, b as normalizeOutputPathKey, c as createBundlerGeneratedCssMarker, d as stripBundlerGeneratedCssMarkers, f as resolvePackageDir, g as isCSSRequest, h as formatPostcssSourceMap, i as createRuntimeAffectingSourceSignature, l as hasBundlerGeneratedCssMarker, m as cleanUrl, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as resolvePluginDisabledState, r as updateBundleBuildState, s as pushConcurrentTaskFactories, t as buildBundleSnapshot, u as parseBundlerGeneratedCssMarkerBlocks, v as isSourceStyleRequest } from "./bundle-state-DY3eq4Gz.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
10
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
11
11
|
import postcss from "postcss";
|
|
@@ -14,6 +14,7 @@ import process$1 from "node:process";
|
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
16
16
|
import { readFile } from "node:fs/promises";
|
|
17
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
17
18
|
import MagicString from "magic-string";
|
|
18
19
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
19
20
|
import { parse } from "comment-json";
|
|
@@ -22343,200 +22344,6 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
22343
22344
|
};
|
|
22344
22345
|
}
|
|
22345
22346
|
//#endregion
|
|
22346
|
-
//#region src/bundlers/vite/processed-css-assets.ts
|
|
22347
|
-
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
22348
|
-
function isCssOutputFile(file) {
|
|
22349
|
-
return CSS_OUTPUT_FILE_RE.test(file);
|
|
22350
|
-
}
|
|
22351
|
-
function getAssetFile(bundleFile, asset) {
|
|
22352
|
-
return asset.fileName || bundleFile;
|
|
22353
|
-
}
|
|
22354
|
-
function readAssetSource(asset) {
|
|
22355
|
-
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
22356
|
-
}
|
|
22357
|
-
function appendCss(baseCss, css) {
|
|
22358
|
-
if (baseCss.length === 0) return css;
|
|
22359
|
-
if (css.length === 0) return baseCss;
|
|
22360
|
-
return `${baseCss}\n${css}`;
|
|
22361
|
-
}
|
|
22362
|
-
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
22363
|
-
let collected = 0;
|
|
22364
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
22365
|
-
if (output.type !== "asset") continue;
|
|
22366
|
-
const file = getAssetFile(bundleFile, output);
|
|
22367
|
-
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
22368
|
-
const rawSource = readAssetSource(output);
|
|
22369
|
-
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
22370
|
-
if (nextCss !== rawSource) output.source = nextCss;
|
|
22371
|
-
options.markCssAssetProcessed?.(output, file);
|
|
22372
|
-
options.recordCssAssetResult?.(file, nextCss);
|
|
22373
|
-
options.recordViteProcessedCssAssetResult?.(file, nextCss);
|
|
22374
|
-
options.debug?.("collect vite-processed css asset: %s bytes=%d", file, nextCss.length);
|
|
22375
|
-
collected++;
|
|
22376
|
-
}
|
|
22377
|
-
return collected;
|
|
22378
|
-
}
|
|
22379
|
-
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
22380
|
-
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].filter(([, css]) => css.length > 0);
|
|
22381
|
-
if (viteCssResults.length === 0) return 0;
|
|
22382
|
-
let injected = 0;
|
|
22383
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
22384
|
-
if (output.type !== "asset") continue;
|
|
22385
|
-
const file = getAssetFile(bundleFile, output);
|
|
22386
|
-
if (!options.opts.cssMatcher(file) || !options.opts.mainCssChunkMatcher(file, options.opts.appType)) continue;
|
|
22387
|
-
const mainFileKey = normalizeOutputPathKey(file);
|
|
22388
|
-
const originalSource = readAssetSource(output);
|
|
22389
|
-
let nextCss = originalSource;
|
|
22390
|
-
for (const [sourceFile, sourceCss] of viteCssResults) {
|
|
22391
|
-
if (normalizeOutputPathKey(sourceFile) === mainFileKey || options.opts.mainCssChunkMatcher(sourceFile, options.opts.appType)) continue;
|
|
22392
|
-
const css = stripBundlerGeneratedCssMarkers(sourceCss).trim();
|
|
22393
|
-
if (css.length === 0) continue;
|
|
22394
|
-
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
22395
|
-
if (mergedLayerCss.merged) {
|
|
22396
|
-
nextCss = mergedLayerCss.css;
|
|
22397
|
-
continue;
|
|
22398
|
-
}
|
|
22399
|
-
if (nextCss.includes(css)) continue;
|
|
22400
|
-
nextCss = appendCss(nextCss, css);
|
|
22401
|
-
}
|
|
22402
|
-
if (nextCss === originalSource) continue;
|
|
22403
|
-
output.source = nextCss;
|
|
22404
|
-
options.markCssAssetProcessed?.(output, file);
|
|
22405
|
-
options.recordCssAssetResult?.(file, nextCss);
|
|
22406
|
-
options.onUpdate?.(file, originalSource, nextCss);
|
|
22407
|
-
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
22408
|
-
injected++;
|
|
22409
|
-
}
|
|
22410
|
-
return injected;
|
|
22411
|
-
}
|
|
22412
|
-
//#endregion
|
|
22413
|
-
//#region src/bundlers/vite/css-finalizer.ts
|
|
22414
|
-
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
22415
|
-
const candidate = error;
|
|
22416
|
-
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
22417
|
-
}
|
|
22418
|
-
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
22419
|
-
if (typeof ctx.addWatchFile !== "function") return;
|
|
22420
|
-
for (const dependency of dependencies ?? []) try {
|
|
22421
|
-
ctx.addWatchFile(dependency);
|
|
22422
|
-
} catch (error) {
|
|
22423
|
-
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
22424
|
-
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
22425
|
-
continue;
|
|
22426
|
-
}
|
|
22427
|
-
throw error;
|
|
22428
|
-
}
|
|
22429
|
-
}
|
|
22430
|
-
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
22431
|
-
return {
|
|
22432
|
-
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
22433
|
-
postcssOptions: { options: { from: file } },
|
|
22434
|
-
...majorVersion === void 0 ? {} : { majorVersion }
|
|
22435
|
-
};
|
|
22436
|
-
}
|
|
22437
|
-
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
22438
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
22439
|
-
if (generatorOptions.target === "web" && opts.twPatcher.majorVersion !== 3) return false;
|
|
22440
|
-
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
22441
|
-
if (opts.twPatcher.majorVersion === 3) return false;
|
|
22442
|
-
return processed && shouldFinalizeProcessedCssAsset(opts, file);
|
|
22443
|
-
}
|
|
22444
|
-
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
22445
|
-
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
22446
|
-
}
|
|
22447
|
-
function createViteCssFinalizerOutputPlugin(context) {
|
|
22448
|
-
return {
|
|
22449
|
-
name: "weapp-tailwindcss:adaptor:css-finalizer",
|
|
22450
|
-
enforce: "post",
|
|
22451
|
-
generateBundle: {
|
|
22452
|
-
order: "post",
|
|
22453
|
-
async handler(_options, bundle) {
|
|
22454
|
-
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
22455
|
-
if (getResolvedConfig()?.command !== "build") return;
|
|
22456
|
-
collectViteProcessedCssAssetResults(bundle, {
|
|
22457
|
-
isViteProcessedCssAsset,
|
|
22458
|
-
markCssAssetProcessed,
|
|
22459
|
-
recordCssAssetResult,
|
|
22460
|
-
recordViteProcessedCssAssetResult,
|
|
22461
|
-
debug
|
|
22462
|
-
});
|
|
22463
|
-
const isCssOutputAssetEntry = (entry) => {
|
|
22464
|
-
const [, output] = entry;
|
|
22465
|
-
return output.type === "asset" && opts.cssMatcher(output.fileName) && (!isCssAssetProcessed(output, output.fileName) || shouldFinalizeProcessedCssAsset(opts, output.fileName));
|
|
22466
|
-
};
|
|
22467
|
-
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
22468
|
-
if (entries.length === 0) {
|
|
22469
|
-
injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
22470
|
-
opts,
|
|
22471
|
-
getViteProcessedCssAssetResults,
|
|
22472
|
-
markCssAssetProcessed,
|
|
22473
|
-
recordCssAssetResult,
|
|
22474
|
-
debug,
|
|
22475
|
-
onUpdate: opts.onUpdate
|
|
22476
|
-
});
|
|
22477
|
-
return;
|
|
22478
|
-
}
|
|
22479
|
-
await runtimeState.readyPromise;
|
|
22480
|
-
await waitForSourceCandidateSyncs?.();
|
|
22481
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
22482
|
-
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
22483
|
-
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
22484
|
-
const generatorRuntime = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
22485
|
-
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
22486
|
-
const file = output.fileName || bundleFile;
|
|
22487
|
-
const rawSource = output.source.toString();
|
|
22488
|
-
if (isViteProcessedCssAsset?.(output, file)) {
|
|
22489
|
-
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
22490
|
-
output.source = nextCss;
|
|
22491
|
-
markCssAssetProcessed(output, file);
|
|
22492
|
-
recordCssAssetResult?.(file, nextCss);
|
|
22493
|
-
debug("css finalizer skip vite-processed css: %s", file);
|
|
22494
|
-
return;
|
|
22495
|
-
}
|
|
22496
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.twPatcher.majorVersion, file);
|
|
22497
|
-
const cssUserHandlerOptions = {
|
|
22498
|
-
...cssHandlerOptions,
|
|
22499
|
-
isMainChunk: false
|
|
22500
|
-
};
|
|
22501
|
-
const processed = isCssAssetProcessed(output, file);
|
|
22502
|
-
const generatorRawSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) ?? rawSource : rawSource;
|
|
22503
|
-
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await generateCssByGenerator({
|
|
22504
|
-
opts,
|
|
22505
|
-
runtimeState,
|
|
22506
|
-
runtime: generatorRuntime,
|
|
22507
|
-
rawSource: generatorRawSource,
|
|
22508
|
-
file,
|
|
22509
|
-
cssHandlerOptions,
|
|
22510
|
-
cssUserHandlerOptions,
|
|
22511
|
-
getSourceCandidatesForEntries,
|
|
22512
|
-
styleHandler: opts.styleHandler,
|
|
22513
|
-
debug
|
|
22514
|
-
}) : void 0;
|
|
22515
|
-
const nextCss = generated?.css ?? (generatorOptions.target === "web" ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css);
|
|
22516
|
-
if (generated) {
|
|
22517
|
-
registerGeneratorDependencies$1(this, generated.dependencies);
|
|
22518
|
-
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
22519
|
-
recordCssAssetResult?.(file, nextCss);
|
|
22520
|
-
if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, generatorRawSource);
|
|
22521
|
-
}
|
|
22522
|
-
output.source = nextCss;
|
|
22523
|
-
markCssAssetProcessed(output, file);
|
|
22524
|
-
opts.onUpdate(file, rawSource, nextCss);
|
|
22525
|
-
debug("css finalizer handle: %s", file);
|
|
22526
|
-
}));
|
|
22527
|
-
injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
22528
|
-
opts,
|
|
22529
|
-
getViteProcessedCssAssetResults,
|
|
22530
|
-
markCssAssetProcessed,
|
|
22531
|
-
recordCssAssetResult,
|
|
22532
|
-
debug,
|
|
22533
|
-
onUpdate: opts.onUpdate
|
|
22534
|
-
});
|
|
22535
|
-
}
|
|
22536
|
-
}
|
|
22537
|
-
};
|
|
22538
|
-
}
|
|
22539
|
-
//#endregion
|
|
22540
22347
|
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
22541
22348
|
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
22542
22349
|
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
@@ -22616,12 +22423,13 @@ function createCssHandlerOptionsCache(options) {
|
|
|
22616
22423
|
const appType = options.getAppType();
|
|
22617
22424
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
22618
22425
|
const outputRoot = options.getOutputRoot?.();
|
|
22426
|
+
const from = outputRoot ? path.resolve(outputRoot, file) : file;
|
|
22619
22427
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}`;
|
|
22620
22428
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
22621
22429
|
if (cached) return cached;
|
|
22622
22430
|
const created = {
|
|
22623
22431
|
isMainChunk,
|
|
22624
|
-
postcssOptions: { options: { from
|
|
22432
|
+
postcssOptions: { options: { from } },
|
|
22625
22433
|
majorVersion,
|
|
22626
22434
|
sourceOptions: { outputRoot }
|
|
22627
22435
|
};
|
|
@@ -22671,7 +22479,7 @@ function createCssTransformShareScope(file, rawSource) {
|
|
|
22671
22479
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
22672
22480
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${normalizeOutputPathKey(file)}`;
|
|
22673
22481
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
22674
|
-
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${normalizeOutputPathKey(file)}`;
|
|
22482
|
+
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback }) || opts.twPatcher.majorVersion === 3 && (opts.cssEntries?.length ?? 0) > 1 && rawSource.includes("@tailwind")) return `source:${normalizeOutputPathKey(file)}`;
|
|
22675
22483
|
return createCssTransformShareScope(file, rawSource);
|
|
22676
22484
|
}
|
|
22677
22485
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -22797,16 +22605,16 @@ function createReplayCssAsset(fileName, source) {
|
|
|
22797
22605
|
originalFileNames: []
|
|
22798
22606
|
};
|
|
22799
22607
|
}
|
|
22800
|
-
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
22608
|
+
function isAddWatchFileInvalidRollupPhaseError$1(error) {
|
|
22801
22609
|
const candidate = error;
|
|
22802
22610
|
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
22803
22611
|
}
|
|
22804
|
-
function registerGeneratorDependencies(ctx, dependencies) {
|
|
22612
|
+
function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
22805
22613
|
if (typeof ctx.addWatchFile !== "function") return;
|
|
22806
22614
|
for (const dependency of dependencies ?? []) try {
|
|
22807
22615
|
ctx.addWatchFile(dependency);
|
|
22808
22616
|
} catch (error) {
|
|
22809
|
-
if (isAddWatchFileInvalidRollupPhaseError(error)) {
|
|
22617
|
+
if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
|
|
22810
22618
|
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
22811
22619
|
continue;
|
|
22812
22620
|
}
|
|
@@ -22862,6 +22670,111 @@ function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
|
22862
22670
|
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
22863
22671
|
}
|
|
22864
22672
|
//#endregion
|
|
22673
|
+
//#region src/bundlers/vite/processed-css-assets.ts
|
|
22674
|
+
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
22675
|
+
function isCssOutputFile(file) {
|
|
22676
|
+
return CSS_OUTPUT_FILE_RE.test(file);
|
|
22677
|
+
}
|
|
22678
|
+
function getAssetFile(bundleFile, asset) {
|
|
22679
|
+
return asset.fileName || bundleFile;
|
|
22680
|
+
}
|
|
22681
|
+
function readAssetSource(asset) {
|
|
22682
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
22683
|
+
}
|
|
22684
|
+
function appendCss(baseCss, css) {
|
|
22685
|
+
if (baseCss.length === 0) return css;
|
|
22686
|
+
if (css.length === 0) return baseCss;
|
|
22687
|
+
return `${baseCss}\n${css}`;
|
|
22688
|
+
}
|
|
22689
|
+
function stripStyleExtension(file) {
|
|
22690
|
+
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
22691
|
+
}
|
|
22692
|
+
function isAppOriginCssFile$1(file) {
|
|
22693
|
+
return stripStyleExtension(file).split("/").pop() === "app-origin";
|
|
22694
|
+
}
|
|
22695
|
+
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
22696
|
+
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
22697
|
+
}
|
|
22698
|
+
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
22699
|
+
if (!markerFile) return false;
|
|
22700
|
+
return normalizeOutputPathKey(stripStyleExtension(targetFile)) === normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
22701
|
+
}
|
|
22702
|
+
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
22703
|
+
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
22704
|
+
if (blocks.length <= 1) return stripBundlerGeneratedCssMarkers(rawSource);
|
|
22705
|
+
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
22706
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : stripBundlerGeneratedCssMarkers(rawSource);
|
|
22707
|
+
}
|
|
22708
|
+
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
22709
|
+
if (options.injectIntoMain === true) return true;
|
|
22710
|
+
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
22711
|
+
const sourceFileKey = normalizeOutputPathKey(sourceFile);
|
|
22712
|
+
const sourceBaseName = sourceFileKey.replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i, "").split("/").pop();
|
|
22713
|
+
return sourceFileKey !== targetFileKey && (opts.mainCssChunkMatcher(sourceFile, opts.appType) || sourceBaseName === "app" || sourceBaseName === "main");
|
|
22714
|
+
}
|
|
22715
|
+
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
22716
|
+
let collected = 0;
|
|
22717
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
22718
|
+
if (output.type !== "asset") continue;
|
|
22719
|
+
const file = getAssetFile(bundleFile, output);
|
|
22720
|
+
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
22721
|
+
const rawSource = readAssetSource(output);
|
|
22722
|
+
const nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
22723
|
+
if (nextCss !== rawSource) output.source = nextCss;
|
|
22724
|
+
options.markCssAssetProcessed?.(output, file);
|
|
22725
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
22726
|
+
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
22727
|
+
const shouldReplayIntoMainCss = options.opts != null && (normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType) || isAppOriginCssFile$1(file));
|
|
22728
|
+
options.recordViteProcessedCssAssetResult?.(file, nextCss, { injectIntoMain: shouldReplayIntoMainCss || void 0 });
|
|
22729
|
+
options.debug?.("collect vite-processed css asset: %s bytes=%d", file, nextCss.length);
|
|
22730
|
+
collected++;
|
|
22731
|
+
}
|
|
22732
|
+
return collected;
|
|
22733
|
+
}
|
|
22734
|
+
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
22735
|
+
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
22736
|
+
return typeof record === "string" ? {
|
|
22737
|
+
file,
|
|
22738
|
+
css: record,
|
|
22739
|
+
injectIntoMain: void 0
|
|
22740
|
+
} : {
|
|
22741
|
+
file,
|
|
22742
|
+
css: record.css,
|
|
22743
|
+
injectIntoMain: record.injectIntoMain
|
|
22744
|
+
};
|
|
22745
|
+
}).filter((record) => record.css.length > 0);
|
|
22746
|
+
if (viteCssResults.length === 0) return 0;
|
|
22747
|
+
let injected = 0;
|
|
22748
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
22749
|
+
if (output.type !== "asset") continue;
|
|
22750
|
+
const file = getAssetFile(bundleFile, output);
|
|
22751
|
+
if (!options.opts.cssMatcher(file) || !options.opts.mainCssChunkMatcher(file, options.opts.appType)) continue;
|
|
22752
|
+
const mainFileKey = normalizeOutputPathKey(file);
|
|
22753
|
+
const originalSource = readAssetSource(output);
|
|
22754
|
+
let nextCss = originalSource;
|
|
22755
|
+
for (const record of viteCssResults) {
|
|
22756
|
+
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
22757
|
+
const css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
22758
|
+
if (css.length === 0) continue;
|
|
22759
|
+
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
22760
|
+
if (mergedLayerCss.merged) {
|
|
22761
|
+
nextCss = mergedLayerCss.css;
|
|
22762
|
+
continue;
|
|
22763
|
+
}
|
|
22764
|
+
if (nextCss.includes(css)) continue;
|
|
22765
|
+
nextCss = appendCss(nextCss, css);
|
|
22766
|
+
}
|
|
22767
|
+
if (nextCss === originalSource) continue;
|
|
22768
|
+
output.source = nextCss;
|
|
22769
|
+
options.markCssAssetProcessed?.(output, file);
|
|
22770
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
22771
|
+
options.onUpdate?.(file, originalSource, nextCss);
|
|
22772
|
+
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
22773
|
+
injected++;
|
|
22774
|
+
}
|
|
22775
|
+
return injected;
|
|
22776
|
+
}
|
|
22777
|
+
//#endregion
|
|
22865
22778
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
22866
22779
|
function addSiblingCssFile(files, file) {
|
|
22867
22780
|
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
@@ -22879,11 +22792,18 @@ function resolveReplayCssOutputFile(rootDir, file) {
|
|
|
22879
22792
|
return normalizedFile;
|
|
22880
22793
|
}
|
|
22881
22794
|
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
22795
|
+
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
22796
|
+
const MINI_PROGRAM_STYLE_OUTPUT_EXT_RE = /\.(?:wx|ac|jx|tt|q|ty)ss$/i;
|
|
22882
22797
|
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
22883
22798
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget) {
|
|
22884
22799
|
if (isWebGeneratorTarget || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
22885
22800
|
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, ".wxss");
|
|
22886
22801
|
}
|
|
22802
|
+
function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false) {
|
|
22803
|
+
const normalizedFile = resolveReplayCssOutputFile(rootDir, file);
|
|
22804
|
+
if (isWebGeneratorTarget || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
22805
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".wxss");
|
|
22806
|
+
}
|
|
22887
22807
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
22888
22808
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
22889
22809
|
try {
|
|
@@ -22893,6 +22813,120 @@ function canProcessViteSourceStyleAsCss(source, file) {
|
|
|
22893
22813
|
return false;
|
|
22894
22814
|
}
|
|
22895
22815
|
}
|
|
22816
|
+
function isPackageJsonImportRequest(request) {
|
|
22817
|
+
return request.startsWith("#");
|
|
22818
|
+
}
|
|
22819
|
+
function normalizeMatchedCssSourcePath(file) {
|
|
22820
|
+
if (!file || !path.isAbsolute(file)) return;
|
|
22821
|
+
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
22822
|
+
}
|
|
22823
|
+
function stripStyleFileExtension(file) {
|
|
22824
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
22825
|
+
const ext = path.extname(normalized);
|
|
22826
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
22827
|
+
}
|
|
22828
|
+
function isAppOriginCssFile(file) {
|
|
22829
|
+
return path.basename(stripStyleFileExtension(file)) === "app-origin";
|
|
22830
|
+
}
|
|
22831
|
+
function normalizeCssSourceForCompare(css) {
|
|
22832
|
+
return css.trim();
|
|
22833
|
+
}
|
|
22834
|
+
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
22835
|
+
if (!getSourceCandidatesForEntries || !rawSource.includes("@source")) return fallbackSignature;
|
|
22836
|
+
const resolved = await resolveTailwindV4EntriesFromCssCached(rawSource, path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, ""))));
|
|
22837
|
+
if (resolved?.entries === void 0) return fallbackSignature;
|
|
22838
|
+
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
22839
|
+
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
22840
|
+
}
|
|
22841
|
+
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
22842
|
+
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
22843
|
+
}
|
|
22844
|
+
function collectStyleFileMatchBases(file, roots) {
|
|
22845
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
22846
|
+
const bases = /* @__PURE__ */ new Set();
|
|
22847
|
+
const addBase = (candidate) => {
|
|
22848
|
+
const base = slash(stripStyleFileExtension(candidate));
|
|
22849
|
+
if (base.length > 0) bases.add(base);
|
|
22850
|
+
};
|
|
22851
|
+
addBase(normalizedFile);
|
|
22852
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
22853
|
+
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
22854
|
+
const relative = path.relative(root, normalizedFile);
|
|
22855
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
22856
|
+
}
|
|
22857
|
+
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
22858
|
+
return bases;
|
|
22859
|
+
}
|
|
22860
|
+
function collectParentDirectories(file) {
|
|
22861
|
+
const directories = [];
|
|
22862
|
+
let current = path.dirname(path.resolve(file.replace(/[?#].*$/, "")));
|
|
22863
|
+
while (true) {
|
|
22864
|
+
directories.push(current);
|
|
22865
|
+
const parent = path.dirname(current);
|
|
22866
|
+
if (parent === current) break;
|
|
22867
|
+
current = parent;
|
|
22868
|
+
}
|
|
22869
|
+
return directories;
|
|
22870
|
+
}
|
|
22871
|
+
function hasMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
22872
|
+
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
22873
|
+
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
22874
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
22875
|
+
return false;
|
|
22876
|
+
}
|
|
22877
|
+
function collectConfiguredTailwindV4CssSources(opts) {
|
|
22878
|
+
const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
22879
|
+
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...patcherCssSources ?? []];
|
|
22880
|
+
}
|
|
22881
|
+
function collectConfiguredCssEntries(opts) {
|
|
22882
|
+
const patcherCssEntries = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
22883
|
+
return [
|
|
22884
|
+
...opts.cssEntries ?? [],
|
|
22885
|
+
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
22886
|
+
...patcherCssEntries ?? []
|
|
22887
|
+
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
22888
|
+
}
|
|
22889
|
+
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
22890
|
+
const candidates = [];
|
|
22891
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22892
|
+
const addCandidate = (candidate) => {
|
|
22893
|
+
if (!candidate) return;
|
|
22894
|
+
const normalized = path.resolve(candidate);
|
|
22895
|
+
if (seen.has(normalized)) return;
|
|
22896
|
+
seen.add(normalized);
|
|
22897
|
+
candidates.push(normalized);
|
|
22898
|
+
};
|
|
22899
|
+
addCandidate(path.dirname(path.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
22900
|
+
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
22901
|
+
const patcherProjectRoot = typeof opts.tailwindcssPatcherOptions?.projectRoot === "string" ? opts.tailwindcssPatcherOptions.projectRoot : void 0;
|
|
22902
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? patcherProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
22903
|
+
const sourceRoot = opts.tailwindcssBasedir ?? patcherProjectRoot;
|
|
22904
|
+
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
22905
|
+
for (const cssEntry of configuredCssEntries) {
|
|
22906
|
+
const resolvedCssEntry = path.resolve(cssEntry);
|
|
22907
|
+
if (configuredCssEntries.length === 1 || isMatchingCssSourceFile(file, resolvedCssEntry, outputRoot) || hasMatchingStyleFileBase(file, resolvedCssEntry, outputRoot, sourceRoot)) addCandidate(path.dirname(resolvedCssEntry));
|
|
22908
|
+
}
|
|
22909
|
+
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
22910
|
+
const cssSourceFile = normalizeMatchedCssSourcePath(cssSource.file);
|
|
22911
|
+
const cssSourceCss = typeof cssSource.css === "string" ? normalizeCssSourceForCompare(cssSource.css) : void 0;
|
|
22912
|
+
if (cssSourceFile && !isMatchingCssSourceFile(file, cssSourceFile, outputRoot) && cssSourceCss !== normalizedSource) continue;
|
|
22913
|
+
addCandidate(cssSourceFile ? path.dirname(cssSourceFile) : void 0);
|
|
22914
|
+
addCandidate(resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback));
|
|
22915
|
+
}
|
|
22916
|
+
return candidates;
|
|
22917
|
+
}
|
|
22918
|
+
function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
22919
|
+
if (!source.includes("@config")) return source;
|
|
22920
|
+
const baseCandidates = collectCssConfigBaseCandidates(source, file, outputRoot, opts);
|
|
22921
|
+
return source.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
|
|
22922
|
+
if (path.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
22923
|
+
for (const base of baseCandidates) {
|
|
22924
|
+
const configFile = path.resolve(base, request);
|
|
22925
|
+
if (existsSync(configFile)) return `@config ${quote}${slash(configFile)}${quote};`;
|
|
22926
|
+
}
|
|
22927
|
+
return full;
|
|
22928
|
+
});
|
|
22929
|
+
}
|
|
22896
22930
|
function createGenerateBundleHook(context) {
|
|
22897
22931
|
const state = createBundleBuildState();
|
|
22898
22932
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -22905,20 +22939,25 @@ function createGenerateBundleHook(context) {
|
|
|
22905
22939
|
});
|
|
22906
22940
|
return async function generateBundle(_opt, bundle) {
|
|
22907
22941
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
22908
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs,
|
|
22942
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, recordGeneratorCandidates, hmrTimingRecorder } = context;
|
|
22909
22943
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
22910
22944
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
22911
22945
|
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
22912
22946
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget && runtimeState.twPatcher.majorVersion === 3;
|
|
22913
22947
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
22948
|
+
const resolvedConfig = getResolvedConfig();
|
|
22949
|
+
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
22950
|
+
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
22914
22951
|
await runtimeState.readyPromise;
|
|
22915
22952
|
debug("start");
|
|
22916
22953
|
onStart();
|
|
22917
22954
|
collectViteProcessedCssAssetResults(bundle, {
|
|
22955
|
+
opts,
|
|
22918
22956
|
isViteProcessedCssAsset,
|
|
22919
22957
|
markCssAssetProcessed,
|
|
22920
22958
|
recordCssAssetResult,
|
|
22921
22959
|
recordViteProcessedCssAssetResult,
|
|
22960
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget),
|
|
22922
22961
|
debug
|
|
22923
22962
|
});
|
|
22924
22963
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -22940,16 +22979,14 @@ function createGenerateBundleHook(context) {
|
|
|
22940
22979
|
const disableJsPrecheck = process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1";
|
|
22941
22980
|
const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
22942
22981
|
const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
22943
|
-
const resolvedConfig = getResolvedConfig();
|
|
22944
22982
|
const bundleFiles = Object.keys(bundle);
|
|
22945
22983
|
const buildCommand = resolvedConfig?.command === "build";
|
|
22946
22984
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
22947
|
-
const
|
|
22948
|
-
const
|
|
22949
|
-
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
22985
|
+
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
22986
|
+
const useIncrementalMode = !buildCommand || hasPreviousBundleState || hasOmittedKnownFiles;
|
|
22950
22987
|
currentOutDir = outDir;
|
|
22951
22988
|
const snapshotStart = performance.now();
|
|
22952
|
-
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode);
|
|
22989
|
+
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
22953
22990
|
recordTimingDetail("snapshot", snapshotStart);
|
|
22954
22991
|
const useBundleRuntimeClassSet = !isWebGeneratorTarget && (useIncrementalMode || runtimeState.twPatcher.majorVersion === 4);
|
|
22955
22992
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -22979,10 +23016,11 @@ function createGenerateBundleHook(context) {
|
|
|
22979
23016
|
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
22980
23017
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
22981
23018
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
22982
|
-
|
|
23019
|
+
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
22983
23020
|
let transformRuntime = transformBaseRuntime ?? runtime;
|
|
22984
|
-
|
|
22985
|
-
|
|
23021
|
+
let generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, runtimeState.twPatcher.majorVersion === 3 && hasRuntimeAffectingChanges && transformBaseRuntime ? new Set([...filteredGeneratorCandidates, ...transformBaseRuntime]) : filteredGeneratorCandidates);
|
|
23022
|
+
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
23023
|
+
if (runtimeState.twPatcher.majorVersion === 3 && useV3OxideSourceRuntime && generatorRuntime.size > 0 && (state.iteration === 0 || !hasRuntimeAffectingChanges) && cssEntries.length <= 1) {
|
|
22986
23024
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
22987
23025
|
if (mainCssEntry) {
|
|
22988
23026
|
const validatedRuntime = await validateCandidatesByGenerator({
|
|
@@ -23065,7 +23103,7 @@ function createGenerateBundleHook(context) {
|
|
|
23065
23103
|
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
23066
23104
|
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
23067
23105
|
retryRuntimeSet = new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
23068
|
-
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet
|
|
23106
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
23069
23107
|
}
|
|
23070
23108
|
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
23071
23109
|
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
@@ -23084,7 +23122,7 @@ function createGenerateBundleHook(context) {
|
|
|
23084
23122
|
}
|
|
23085
23123
|
if (type === "css" && originalSource.type === "asset") {
|
|
23086
23124
|
metrics.css.total++;
|
|
23087
|
-
const rawSource = originalEntrySource;
|
|
23125
|
+
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, file, outDir, opts);
|
|
23088
23126
|
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget);
|
|
23089
23127
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
23090
23128
|
delete bundle[file];
|
|
@@ -23099,12 +23137,45 @@ function createGenerateBundleHook(context) {
|
|
|
23099
23137
|
fileName: outputFile,
|
|
23100
23138
|
source
|
|
23101
23139
|
});
|
|
23102
|
-
else bundle[outputFile] =
|
|
23140
|
+
else bundle[outputFile] = createReplayCssAsset(outputFile, source);
|
|
23103
23141
|
originalSource.fileName = outputFile;
|
|
23104
23142
|
}
|
|
23105
23143
|
originalSource.source = source;
|
|
23106
23144
|
};
|
|
23107
|
-
if (
|
|
23145
|
+
if (isWebGeneratorTarget && !shouldGenerateWebCssByGenerator) {
|
|
23146
|
+
applyCssResult(rawSource);
|
|
23147
|
+
markCssAssetProcessed?.(originalSource, outputFile);
|
|
23148
|
+
onUpdate(outputFile, rawSource, rawSource);
|
|
23149
|
+
debug("css skip web target: %s", outputFile);
|
|
23150
|
+
continue;
|
|
23151
|
+
}
|
|
23152
|
+
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
23153
|
+
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
23154
|
+
const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
|
|
23155
|
+
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
23156
|
+
const rememberedCssSource = viteProcessedCssAsset && getRememberedCssSources != null ? [...getRememberedCssSources()].map(([, remembered]) => remembered).find((remembered) => {
|
|
23157
|
+
const originalFiles = [
|
|
23158
|
+
file,
|
|
23159
|
+
originalSource.originalFileName,
|
|
23160
|
+
...originalSource.originalFileNames ?? []
|
|
23161
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
23162
|
+
return normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile) || originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile));
|
|
23163
|
+
}) : void 0;
|
|
23164
|
+
const generatorRawSource = viteProcessedCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
23165
|
+
const generatorSourceFile = viteProcessedCssAsset ? rememberedCssSource?.sourceFile ?? file : file;
|
|
23166
|
+
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
23167
|
+
const cssHandlerOptions = viteProcessedCssAsset ? {
|
|
23168
|
+
...getCssHandlerOptions(generatorSourceFile),
|
|
23169
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk || isAppOriginCssFile(file)
|
|
23170
|
+
} : getCssHandlerOptions(file);
|
|
23171
|
+
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
23172
|
+
const cssRuntimeAffectingSignature = snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
23173
|
+
const cssRuntimeAffectingHash = snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
23174
|
+
const cssShareScope = createCssTransformShareScopeKey(opts, generatorSourceFile, generatorRawSource);
|
|
23175
|
+
const shouldRegenerateAppOriginCss = viteProcessedCssAsset && isAppOriginCssFile(file);
|
|
23176
|
+
const shouldTrackGeneratorRuntime = shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || shouldRegenerateAppOriginCss);
|
|
23177
|
+
const canRegenerateProcessedMainCss = cssHandlerOptions.isMainChunk && (getViteProcessedCssAssetResult?.(file)?.injectIntoMain === true || shouldRegenerateAppOriginCss);
|
|
23178
|
+
if (alreadyProcessedCssAsset && (!shouldTrackGeneratorRuntime || !canRegenerateProcessedMainCss)) {
|
|
23108
23179
|
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
23109
23180
|
applyCssResult(nextCss);
|
|
23110
23181
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -23113,18 +23184,8 @@ function createGenerateBundleHook(context) {
|
|
|
23113
23184
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
23114
23185
|
continue;
|
|
23115
23186
|
}
|
|
23116
|
-
|
|
23117
|
-
|
|
23118
|
-
markCssAssetProcessed?.(originalSource, outputFile);
|
|
23119
|
-
onUpdate(outputFile, rawSource, rawSource);
|
|
23120
|
-
debug("css skip web target: %s", outputFile);
|
|
23121
|
-
continue;
|
|
23122
|
-
}
|
|
23123
|
-
const cssRuntimeAffectingSignature = snapshot.runtimeAffectingSignatureByFile.get(file) ?? rawSource;
|
|
23124
|
-
const cssShareScope = createCssTransformShareScopeKey(opts, file, rawSource);
|
|
23125
|
-
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
23126
|
-
const shouldTrackGeneratorRuntime = shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file));
|
|
23127
|
-
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? generatorCandidateSignature : "generator:stable";
|
|
23187
|
+
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? generatorCandidateSignature : "generator:stable";
|
|
23188
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, getSourceCandidatesForEntries, { includeFallbackSignature: cssHandlerOptions.isMainChunk }) : trackedGeneratorCandidateSignature;
|
|
23128
23189
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
23129
23190
|
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}`;
|
|
23130
23191
|
if (!shouldTrackGeneratorRuntime) {
|
|
@@ -23141,12 +23202,16 @@ function createGenerateBundleHook(context) {
|
|
|
23141
23202
|
cache,
|
|
23142
23203
|
cacheKey: file,
|
|
23143
23204
|
hashKey: `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`,
|
|
23144
|
-
hash: `${getSnapshotHash(snapshot.runtimeAffectingHashByFile, file,
|
|
23205
|
+
hash: `${getSnapshotHash(snapshot.runtimeAffectingHashByFile, file, cssRuntimeAffectingHash)}:${scopedGeneratorCandidateSignature}`,
|
|
23145
23206
|
applyResult(source) {
|
|
23146
23207
|
applyCssResult(source);
|
|
23147
23208
|
lastCssResultByFile.set(outputFile, source);
|
|
23148
23209
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
23149
|
-
|
|
23210
|
+
rememberCssSource?.({
|
|
23211
|
+
outputFile,
|
|
23212
|
+
rawSource: generatorRawSource,
|
|
23213
|
+
sourceFile: generatorSourceFile
|
|
23214
|
+
}, cssRuntimeSignature);
|
|
23150
23215
|
},
|
|
23151
23216
|
onCacheHit() {
|
|
23152
23217
|
metrics.css.cacheHits++;
|
|
@@ -23166,25 +23231,26 @@ function createGenerateBundleHook(context) {
|
|
|
23166
23231
|
const runTransform = async () => {
|
|
23167
23232
|
const start = performance.now();
|
|
23168
23233
|
await runtimeState.readyPromise;
|
|
23169
|
-
const previousCss = useIncrementalMode && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(file) : void 0;
|
|
23234
|
+
const previousCss = useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file) : void 0;
|
|
23170
23235
|
const generated = await generateCssByGenerator({
|
|
23171
23236
|
opts,
|
|
23172
23237
|
runtimeState,
|
|
23173
23238
|
runtime: generatorRuntime,
|
|
23174
|
-
rawSource,
|
|
23175
|
-
file,
|
|
23239
|
+
rawSource: generatorRawSource,
|
|
23240
|
+
file: generatorSourceFile,
|
|
23176
23241
|
cssHandlerOptions,
|
|
23177
|
-
cssUserHandlerOptions:
|
|
23242
|
+
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
23178
23243
|
getSourceCandidatesForEntries,
|
|
23179
23244
|
styleHandler,
|
|
23180
23245
|
debug,
|
|
23181
23246
|
previousCss
|
|
23182
23247
|
});
|
|
23183
23248
|
if (generated) {
|
|
23184
|
-
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
23185
|
-
if (debugCssDiff) debug("css diff %s: %s",
|
|
23249
|
+
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
23250
|
+
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, generated.css));
|
|
23186
23251
|
debug("css generated result: %s bytes=%d", file, generated.css.length);
|
|
23187
23252
|
recordCssAssetResult?.(outputFile, generated.css);
|
|
23253
|
+
if (viteProcessedCssAsset && cssHandlerOptions.isMainChunk) recordViteProcessedCssAssetResult?.(file, generated.css, { injectIntoMain: true });
|
|
23188
23254
|
metrics.css.elapsed += measureElapsed(start);
|
|
23189
23255
|
metrics.css.transformed++;
|
|
23190
23256
|
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, outputFile);
|
|
@@ -23312,30 +23378,32 @@ function createGenerateBundleHook(context) {
|
|
|
23312
23378
|
});
|
|
23313
23379
|
}
|
|
23314
23380
|
}
|
|
23315
|
-
|
|
23316
|
-
|
|
23317
|
-
|
|
23318
|
-
const
|
|
23381
|
+
if (useIncrementalMode) for (const [key, remembered] of getRememberedCssSources?.() ?? []) {
|
|
23382
|
+
const { outputFile: rememberedOutputFile, rawSource, sourceFile } = remembered;
|
|
23383
|
+
const outputFile = resolveViteCssPipelineOutputFile(rememberedOutputFile, opts, rootDir, isWebGeneratorTarget);
|
|
23384
|
+
const cssHandlerOptions = getCssHandlerOptions(sourceFile);
|
|
23385
|
+
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, await createScopedGeneratorCandidateSignature(rawSource, sourceFile, generatorCandidateSignature, getSourceCandidatesForEntries, { includeFallbackSignature: cssHandlerOptions.isMainChunk }));
|
|
23386
|
+
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || getRememberedCssSignature?.(key) === cssRuntimeSignature) continue;
|
|
23319
23387
|
tasks.push(timeTask("css.replay", async () => {
|
|
23320
23388
|
const start = performance.now();
|
|
23321
|
-
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
23322
23389
|
const generated = await generateCssByGenerator({
|
|
23323
23390
|
opts,
|
|
23324
23391
|
runtimeState,
|
|
23325
23392
|
runtime: generatorRuntime,
|
|
23326
23393
|
rawSource,
|
|
23327
|
-
file:
|
|
23394
|
+
file: sourceFile,
|
|
23328
23395
|
cssHandlerOptions,
|
|
23329
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(
|
|
23396
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
23330
23397
|
getSourceCandidatesForEntries,
|
|
23331
23398
|
styleHandler,
|
|
23332
23399
|
debug
|
|
23333
23400
|
});
|
|
23334
23401
|
const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
|
|
23335
|
-
|
|
23402
|
+
setRememberedCssSignature?.(key, cssRuntimeSignature);
|
|
23336
23403
|
if (generated) {
|
|
23337
|
-
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
23404
|
+
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
23338
23405
|
recordCssAssetResult?.(outputFile, generated.css);
|
|
23406
|
+
recordViteProcessedCssAssetResult?.(sourceFile, generated.css, { injectIntoMain: cssHandlerOptions.isMainChunk });
|
|
23339
23407
|
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
23340
23408
|
}
|
|
23341
23409
|
const replayAsset = createReplayCssAsset(outputFile, css);
|
|
@@ -23379,6 +23447,145 @@ function createGenerateBundleHook(context) {
|
|
|
23379
23447
|
};
|
|
23380
23448
|
}
|
|
23381
23449
|
//#endregion
|
|
23450
|
+
//#region src/bundlers/vite/css-finalizer.ts
|
|
23451
|
+
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
23452
|
+
const candidate = error;
|
|
23453
|
+
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
23454
|
+
}
|
|
23455
|
+
function registerGeneratorDependencies(ctx, dependencies) {
|
|
23456
|
+
if (typeof ctx.addWatchFile !== "function") return;
|
|
23457
|
+
for (const dependency of dependencies ?? []) try {
|
|
23458
|
+
ctx.addWatchFile(dependency);
|
|
23459
|
+
} catch (error) {
|
|
23460
|
+
if (isAddWatchFileInvalidRollupPhaseError(error)) {
|
|
23461
|
+
logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
|
|
23462
|
+
continue;
|
|
23463
|
+
}
|
|
23464
|
+
throw error;
|
|
23465
|
+
}
|
|
23466
|
+
}
|
|
23467
|
+
function createCssHandlerOptions(opts, majorVersion, file) {
|
|
23468
|
+
return {
|
|
23469
|
+
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
23470
|
+
postcssOptions: { options: { from: file } },
|
|
23471
|
+
...majorVersion === void 0 ? {} : { majorVersion }
|
|
23472
|
+
};
|
|
23473
|
+
}
|
|
23474
|
+
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
23475
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
23476
|
+
if (generatorOptions.target === "web" && opts.twPatcher.majorVersion !== 3) return false;
|
|
23477
|
+
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
23478
|
+
if (opts.twPatcher.majorVersion === 3) return false;
|
|
23479
|
+
return processed && shouldFinalizeProcessedCssAsset(opts, file);
|
|
23480
|
+
}
|
|
23481
|
+
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
23482
|
+
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
23483
|
+
}
|
|
23484
|
+
function createViteCssFinalizerOutputPlugin(context) {
|
|
23485
|
+
return {
|
|
23486
|
+
name: "weapp-tailwindcss:adaptor:css-finalizer",
|
|
23487
|
+
enforce: "post",
|
|
23488
|
+
generateBundle: {
|
|
23489
|
+
order: "post",
|
|
23490
|
+
async handler(_options, bundle) {
|
|
23491
|
+
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
23492
|
+
const resolvedConfig = getResolvedConfig();
|
|
23493
|
+
if (resolvedConfig?.command !== "build") return;
|
|
23494
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
23495
|
+
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
23496
|
+
const rootDir = resolvedConfig.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
23497
|
+
collectViteProcessedCssAssetResults(bundle, {
|
|
23498
|
+
opts,
|
|
23499
|
+
isViteProcessedCssAsset,
|
|
23500
|
+
markCssAssetProcessed,
|
|
23501
|
+
recordCssAssetResult,
|
|
23502
|
+
recordViteProcessedCssAssetResult,
|
|
23503
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget),
|
|
23504
|
+
debug
|
|
23505
|
+
});
|
|
23506
|
+
const isCssOutputAssetEntry = (entry) => {
|
|
23507
|
+
const [, output] = entry;
|
|
23508
|
+
return output.type === "asset" && opts.cssMatcher(output.fileName) && !isCssAssetProcessed(output, output.fileName);
|
|
23509
|
+
};
|
|
23510
|
+
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
23511
|
+
if (entries.length === 0) {
|
|
23512
|
+
injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
23513
|
+
opts,
|
|
23514
|
+
getViteProcessedCssAssetResults,
|
|
23515
|
+
markCssAssetProcessed,
|
|
23516
|
+
recordCssAssetResult,
|
|
23517
|
+
debug,
|
|
23518
|
+
onUpdate: opts.onUpdate
|
|
23519
|
+
});
|
|
23520
|
+
return;
|
|
23521
|
+
}
|
|
23522
|
+
await runtimeState.readyPromise;
|
|
23523
|
+
await waitForSourceCandidateSyncs?.();
|
|
23524
|
+
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
23525
|
+
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
23526
|
+
const generatorRuntime = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
23527
|
+
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
23528
|
+
const file = output.fileName || bundleFile;
|
|
23529
|
+
const rawSource = output.source.toString();
|
|
23530
|
+
if (isViteProcessedCssAsset?.(output, file)) {
|
|
23531
|
+
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
23532
|
+
output.source = nextCss;
|
|
23533
|
+
markCssAssetProcessed(output, file);
|
|
23534
|
+
recordCssAssetResult?.(file, nextCss);
|
|
23535
|
+
debug("css finalizer skip vite-processed css: %s", file);
|
|
23536
|
+
return;
|
|
23537
|
+
}
|
|
23538
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.twPatcher.majorVersion, file);
|
|
23539
|
+
const cssUserHandlerOptions = {
|
|
23540
|
+
...cssHandlerOptions,
|
|
23541
|
+
isMainChunk: false
|
|
23542
|
+
};
|
|
23543
|
+
const processed = isCssAssetProcessed(output, file);
|
|
23544
|
+
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
23545
|
+
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
23546
|
+
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
23547
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.twPatcher.majorVersion, generatorSourceFile) : cssHandlerOptions;
|
|
23548
|
+
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
23549
|
+
...generatorCssHandlerOptions,
|
|
23550
|
+
isMainChunk: false
|
|
23551
|
+
} : cssUserHandlerOptions;
|
|
23552
|
+
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await generateCssByGenerator({
|
|
23553
|
+
opts,
|
|
23554
|
+
runtimeState,
|
|
23555
|
+
runtime: generatorRuntime,
|
|
23556
|
+
rawSource: generatorRawSource,
|
|
23557
|
+
file: generatorSourceFile,
|
|
23558
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
23559
|
+
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
23560
|
+
getSourceCandidatesForEntries,
|
|
23561
|
+
styleHandler: opts.styleHandler,
|
|
23562
|
+
debug
|
|
23563
|
+
}) : void 0;
|
|
23564
|
+
const nextCss = generated?.css ?? (generatorOptions.target === "web" ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css);
|
|
23565
|
+
if (generated) {
|
|
23566
|
+
registerGeneratorDependencies(this, generated.dependencies);
|
|
23567
|
+
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
23568
|
+
recordCssAssetResult?.(file, nextCss);
|
|
23569
|
+
if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, generatorRawSource);
|
|
23570
|
+
}
|
|
23571
|
+
output.source = nextCss;
|
|
23572
|
+
markCssAssetProcessed(output, file);
|
|
23573
|
+
opts.onUpdate(file, rawSource, nextCss);
|
|
23574
|
+
debug("css finalizer handle: %s", file);
|
|
23575
|
+
}));
|
|
23576
|
+
injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
23577
|
+
opts,
|
|
23578
|
+
getViteProcessedCssAssetResults,
|
|
23579
|
+
markCssAssetProcessed,
|
|
23580
|
+
recordCssAssetResult,
|
|
23581
|
+
debug,
|
|
23582
|
+
onUpdate: opts.onUpdate
|
|
23583
|
+
});
|
|
23584
|
+
}
|
|
23585
|
+
}
|
|
23586
|
+
};
|
|
23587
|
+
}
|
|
23588
|
+
//#endregion
|
|
23382
23589
|
//#region src/bundlers/vite/official-tailwind-plugins.ts
|
|
23383
23590
|
const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
|
|
23384
23591
|
function getPostcssPluginName(plugin) {
|
|
@@ -23586,10 +23793,12 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
23586
23793
|
},
|
|
23587
23794
|
async transform(code, id) {
|
|
23588
23795
|
if (!isCSSRequest(id)) return null;
|
|
23589
|
-
|
|
23590
|
-
|
|
23796
|
+
const file = cleanUrl(id);
|
|
23797
|
+
const normalizedCode = hasTailwindRootDirectives(code) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
23798
|
+
if (hasTailwindRootDirectives(normalizedCode)) {
|
|
23799
|
+
await options.onTailwindRootCss?.(id, normalizedCode);
|
|
23591
23800
|
if (options.shouldOwnTailwindGeneration) {
|
|
23592
|
-
const generatedCss = await options.generateTailwindCss?.(id,
|
|
23801
|
+
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
|
|
23593
23802
|
if (generatedCss !== void 0) return {
|
|
23594
23803
|
code: generatedCss,
|
|
23595
23804
|
map: null
|
|
@@ -23597,12 +23806,12 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
23597
23806
|
}
|
|
23598
23807
|
}
|
|
23599
23808
|
if (!options.shouldRewrite) return null;
|
|
23600
|
-
const rewritten = rewriteTailwindcssImportsInCode(
|
|
23809
|
+
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
23601
23810
|
join: joinPosixPath,
|
|
23602
23811
|
appType: resolveAppType(),
|
|
23603
23812
|
rootImport
|
|
23604
23813
|
});
|
|
23605
|
-
const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ??
|
|
23814
|
+
const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ?? normalizedCode) : rewritten;
|
|
23606
23815
|
if (!nextCode || nextCode === code) return null;
|
|
23607
23816
|
return {
|
|
23608
23817
|
code: nextCode,
|
|
@@ -23887,6 +24096,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
23887
24096
|
...options,
|
|
23888
24097
|
__internalDeferMissingCssEntriesWarning: true
|
|
23889
24098
|
});
|
|
24099
|
+
const normalizedCssEntries = normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? process$1.cwd());
|
|
24100
|
+
if (normalizedCssEntries) opts.cssEntries ?? (opts.cssEntries = normalizedCssEntries);
|
|
24101
|
+
if (opts.cssEntries?.length) {
|
|
24102
|
+
var _opts$tailwindcss, _opts$tailwindcss$v;
|
|
24103
|
+
opts.tailwindcss ?? (opts.tailwindcss = {});
|
|
24104
|
+
(_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
|
|
24105
|
+
(_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
|
|
24106
|
+
}
|
|
23890
24107
|
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
23891
24108
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
23892
24109
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
@@ -23912,16 +24129,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
23912
24129
|
const file = cleanUrl(id);
|
|
23913
24130
|
if (!path.isAbsolute(file)) return;
|
|
23914
24131
|
const sourceFile = path.normalize(file);
|
|
23915
|
-
const
|
|
24132
|
+
const sourceBase = path.dirname(sourceFile);
|
|
24133
|
+
const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
23916
24134
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
|
|
23917
24135
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
23918
24136
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
23919
|
-
const dependencies = await resolveViteTailwindV4CssDependencies(sourceCss, path.dirname(sourceFile));
|
|
23920
24137
|
if (!upsertTailwindV4CssSource(opts, {
|
|
23921
24138
|
file: sourceFile,
|
|
23922
|
-
base:
|
|
24139
|
+
base: sourceBase,
|
|
23923
24140
|
css: sourceCss,
|
|
23924
|
-
dependencies
|
|
24141
|
+
dependencies: await resolveViteTailwindV4CssDependencies(sourceCss, sourceBase)
|
|
23925
24142
|
})) return;
|
|
23926
24143
|
invalidateSourceCandidateScan();
|
|
23927
24144
|
debug("detected tailwindcss v4 css source from vite css module: %s", sourceFile);
|
|
@@ -23939,16 +24156,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
23939
24156
|
let changed = false;
|
|
23940
24157
|
for (const cssEntry of cssEntries) {
|
|
23941
24158
|
const sourceFile = path.resolve(cssEntry);
|
|
23942
|
-
const
|
|
24159
|
+
const sourceBase = path.dirname(sourceFile);
|
|
24160
|
+
const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(await readFile(sourceFile, "utf8"), sourceBase), { importFallback: true });
|
|
23943
24161
|
if (autoCssSourceContent.get(sourceFile) === sourceCss) continue;
|
|
23944
24162
|
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
23945
24163
|
await syncTailwindCssSourceCandidates(sourceFile, sourceCss);
|
|
23946
|
-
const resolved = await resolveTailwindV4EntriesFromCssCached(sourceCss, path.dirname(sourceFile));
|
|
23947
24164
|
changed = upsertTailwindV4CssSource(opts, {
|
|
23948
24165
|
file: sourceFile,
|
|
23949
|
-
base:
|
|
24166
|
+
base: sourceBase,
|
|
23950
24167
|
css: sourceCss,
|
|
23951
|
-
dependencies:
|
|
24168
|
+
dependencies: (await resolveTailwindV4EntriesFromCssCached(sourceCss, sourceBase))?.dependencies ?? []
|
|
23952
24169
|
}) || changed;
|
|
23953
24170
|
}
|
|
23954
24171
|
if (!changed) return;
|
|
@@ -23958,7 +24175,11 @@ function WeappTailwindcss(options = {}) {
|
|
|
23958
24175
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
23959
24176
|
let resolvedConfig;
|
|
23960
24177
|
let recordedGeneratorCandidates;
|
|
23961
|
-
const
|
|
24178
|
+
const sourceCandidateExtractor = tailwindcssMajorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0;
|
|
24179
|
+
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
24180
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
24181
|
+
extractor: sourceCandidateExtractor
|
|
24182
|
+
});
|
|
23962
24183
|
const sourceCandidateScanCache = /* @__PURE__ */ new Map();
|
|
23963
24184
|
let sourceScanEntries;
|
|
23964
24185
|
let sourceScanMatcher;
|
|
@@ -23969,12 +24190,11 @@ function WeappTailwindcss(options = {}) {
|
|
|
23969
24190
|
const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
|
|
23970
24191
|
const pendingSourceCandidateSyncByFile = /* @__PURE__ */ new Map();
|
|
23971
24192
|
const processedCssAssets = /* @__PURE__ */ new WeakSet();
|
|
23972
|
-
const processedCssAssetFiles = /* @__PURE__ */ new Set();
|
|
23973
24193
|
const viteProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
23974
24194
|
const viteGeneratedCssByFile = /* @__PURE__ */ new Map();
|
|
23975
24195
|
const viteProcessedCssAssetResults = /* @__PURE__ */ new Map();
|
|
23976
|
-
const
|
|
23977
|
-
const
|
|
24196
|
+
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
24197
|
+
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
23978
24198
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
23979
24199
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
23980
24200
|
opts,
|
|
@@ -23989,12 +24209,15 @@ function WeappTailwindcss(options = {}) {
|
|
|
23989
24209
|
refreshRuntimeStateForAutoCssSources = refreshRuntimeState;
|
|
23990
24210
|
onLoad();
|
|
23991
24211
|
const getResolvedConfig = () => resolvedConfig;
|
|
23992
|
-
const markCssAssetProcessed = (asset,
|
|
24212
|
+
const markCssAssetProcessed = (asset, _file) => {
|
|
23993
24213
|
processedCssAssets.add(asset);
|
|
23994
|
-
if (file) processedCssAssetFiles.add(normalizeOutputPathKey(file));
|
|
23995
24214
|
};
|
|
23996
24215
|
const isCssAssetProcessed = (asset, file) => {
|
|
23997
|
-
|
|
24216
|
+
if (processedCssAssets.has(asset)) return true;
|
|
24217
|
+
if (!file) return false;
|
|
24218
|
+
const record = viteProcessedCssAssetResults.get(normalizeOutputPathKey(file));
|
|
24219
|
+
if (!record) return false;
|
|
24220
|
+
return (typeof asset.source === "string" ? asset.source : asset.source instanceof Uint8Array ? Buffer$1.from(asset.source).toString() : String(asset.source ?? "")) === record.css;
|
|
23998
24221
|
};
|
|
23999
24222
|
const recordGeneratorCandidates = (candidates) => {
|
|
24000
24223
|
recordedGeneratorCandidates = new Set(candidates);
|
|
@@ -24141,23 +24364,28 @@ function WeappTailwindcss(options = {}) {
|
|
|
24141
24364
|
const file = cleanUrl(id);
|
|
24142
24365
|
return !/\.(?:vue|uvue|nvue|svelte|mpx)$/i.test(file);
|
|
24143
24366
|
};
|
|
24144
|
-
const
|
|
24145
|
-
|
|
24146
|
-
|
|
24367
|
+
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
24368
|
+
const key = normalizeOutputPathKey(entry.outputFile);
|
|
24369
|
+
rememberedCssSources.set(key, entry);
|
|
24370
|
+
if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
|
|
24147
24371
|
};
|
|
24148
|
-
const
|
|
24149
|
-
const
|
|
24150
|
-
const
|
|
24151
|
-
const
|
|
24152
|
-
|
|
24372
|
+
const getRememberedCssSources = () => rememberedCssSources;
|
|
24373
|
+
const getRememberedCssSourceEntry = (file) => rememberedCssSources.get(normalizeOutputPathKey(file));
|
|
24374
|
+
const getRememberedCssSignature = (file) => rememberedCssSignatureByFile.get(normalizeOutputPathKey(file));
|
|
24375
|
+
const setRememberedCssSignature = (file, cssRuntimeSignature) => {
|
|
24376
|
+
rememberedCssSignatureByFile.set(normalizeOutputPathKey(file), cssRuntimeSignature);
|
|
24153
24377
|
};
|
|
24154
24378
|
const recordCssAssetResult = (file, css) => {
|
|
24155
24379
|
viteGeneratedCssByFile.set(file, css);
|
|
24156
24380
|
};
|
|
24157
|
-
const recordViteProcessedCssAssetResult = (file, css) => {
|
|
24158
|
-
viteProcessedCssAssetResults.set(normalizeOutputPathKey(file),
|
|
24381
|
+
const recordViteProcessedCssAssetResult = (file, css, options = {}) => {
|
|
24382
|
+
viteProcessedCssAssetResults.set(normalizeOutputPathKey(file), {
|
|
24383
|
+
css,
|
|
24384
|
+
injectIntoMain: options.injectIntoMain
|
|
24385
|
+
});
|
|
24159
24386
|
};
|
|
24160
24387
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
24388
|
+
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeOutputPathKey(file));
|
|
24161
24389
|
const normalizeViteProcessedCssFile = (file) => path.resolve(cleanUrl(file));
|
|
24162
24390
|
const markViteProcessedCssSource = (file) => {
|
|
24163
24391
|
viteProcessedCssSourceFiles.add(normalizeViteProcessedCssFile(file));
|
|
@@ -24260,27 +24488,34 @@ function WeappTailwindcss(options = {}) {
|
|
|
24260
24488
|
await waitForSourceCandidateSyncs();
|
|
24261
24489
|
const file = cleanUrl(id);
|
|
24262
24490
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
24491
|
+
const cssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(file);
|
|
24263
24492
|
const generated = await generateCssByGenerator({
|
|
24264
24493
|
opts,
|
|
24265
24494
|
runtimeState,
|
|
24266
24495
|
runtime,
|
|
24267
24496
|
rawSource: code,
|
|
24268
24497
|
file,
|
|
24269
|
-
cssHandlerOptions
|
|
24498
|
+
cssHandlerOptions,
|
|
24270
24499
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
24271
24500
|
getSourceCandidatesForEntries,
|
|
24272
24501
|
styleHandler,
|
|
24273
24502
|
debug,
|
|
24274
|
-
previousCss: viteGeneratedCssByFile.get(file)
|
|
24503
|
+
previousCss: viteGeneratedCssByFile.get(file),
|
|
24504
|
+
deferEmptyScopedCssSource: true
|
|
24275
24505
|
});
|
|
24276
24506
|
if (!generated) return;
|
|
24507
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd(), generatorOptions.target === "web");
|
|
24277
24508
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
24278
24509
|
viteGeneratedCssByFile.set(file, generated.css);
|
|
24279
|
-
if (generated.css.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, generated.css);
|
|
24510
|
+
if (generated.css.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, generated.css, { injectIntoMain: cssHandlerOptions.isMainChunk });
|
|
24280
24511
|
markViteProcessedCssSource(file);
|
|
24281
24512
|
rememberTailwindRootCssModule(id);
|
|
24282
24513
|
recordGeneratorCandidates(runtime);
|
|
24283
|
-
|
|
24514
|
+
rememberCssSource({
|
|
24515
|
+
outputFile,
|
|
24516
|
+
rawSource: code,
|
|
24517
|
+
sourceFile: file
|
|
24518
|
+
});
|
|
24284
24519
|
debug("css generated for vite postcss pipeline: %s bytes=%d", file, generated.css.length);
|
|
24285
24520
|
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${generated.css}`;
|
|
24286
24521
|
};
|
|
@@ -24302,17 +24537,19 @@ function WeappTailwindcss(options = {}) {
|
|
|
24302
24537
|
debug,
|
|
24303
24538
|
getResolvedConfig,
|
|
24304
24539
|
markCssAssetProcessed,
|
|
24540
|
+
isCssAssetProcessed,
|
|
24305
24541
|
isViteProcessedCssAsset,
|
|
24306
24542
|
recordCssAssetResult,
|
|
24307
24543
|
recordViteProcessedCssAssetResult,
|
|
24308
24544
|
getViteProcessedCssAssetResults,
|
|
24545
|
+
getViteProcessedCssAssetResult,
|
|
24309
24546
|
getSourceCandidates,
|
|
24310
24547
|
getSourceCandidatesForEntries,
|
|
24311
24548
|
waitForSourceCandidateSyncs,
|
|
24312
|
-
|
|
24313
|
-
|
|
24314
|
-
|
|
24315
|
-
|
|
24549
|
+
rememberCssSource,
|
|
24550
|
+
getRememberedCssSources,
|
|
24551
|
+
getRememberedCssSignature,
|
|
24552
|
+
setRememberedCssSignature,
|
|
24316
24553
|
recordGeneratorCandidates,
|
|
24317
24554
|
hmrTimingRecorder
|
|
24318
24555
|
});
|
|
@@ -24332,8 +24569,12 @@ function WeappTailwindcss(options = {}) {
|
|
|
24332
24569
|
getSourceCandidates,
|
|
24333
24570
|
getSourceCandidatesForEntries,
|
|
24334
24571
|
waitForSourceCandidateSyncs,
|
|
24335
|
-
rememberMainCssSource,
|
|
24336
|
-
|
|
24572
|
+
rememberMainCssSource: (file, rawSource) => rememberCssSource({
|
|
24573
|
+
outputFile: file,
|
|
24574
|
+
rawSource,
|
|
24575
|
+
sourceFile: file
|
|
24576
|
+
}),
|
|
24577
|
+
getRememberedMainCssSource: getRememberedCssSourceEntry
|
|
24337
24578
|
});
|
|
24338
24579
|
const isIosPlatform = resolveUniUtsPlatform().isAppIos;
|
|
24339
24580
|
const prepareTailwindGeneration = async () => {
|
|
@@ -24361,6 +24602,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
24361
24602
|
async transform(code, id) {
|
|
24362
24603
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
|
|
24363
24604
|
return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
|
|
24605
|
+
invalidateRecordedGeneratorCandidates();
|
|
24364
24606
|
const file = cleanUrl(id);
|
|
24365
24607
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
24366
24608
|
sourceCandidateCollector.remove(file);
|
|
@@ -24377,6 +24619,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
24377
24619
|
},
|
|
24378
24620
|
async watchChange(id, change) {
|
|
24379
24621
|
await hmrTimingRecorder.measure("sourceCandidates.watchChange", async () => {
|
|
24622
|
+
if (shouldOwnTailwindGeneration && isSourceCandidateRequest(id)) invalidateRecordedGeneratorCandidates();
|
|
24380
24623
|
if (isSourceScanDependency(id)) invalidateSourceCandidateScan();
|
|
24381
24624
|
if (change.event === "delete") {
|
|
24382
24625
|
sourceCandidateCollector.remove(id);
|
|
@@ -24390,7 +24633,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
24390
24633
|
return hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
|
|
24391
24634
|
const isSourceCandidateHotUpdate = shouldOwnTailwindGeneration && isSourceCandidateRequest(ctx.file);
|
|
24392
24635
|
await syncChangedSourceCandidateFile(ctx.file);
|
|
24393
|
-
invalidateRecordedGeneratorCandidates();
|
|
24636
|
+
if (isSourceCandidateHotUpdate) invalidateRecordedGeneratorCandidates();
|
|
24394
24637
|
const cssModules = resolveHotTailwindCssModules(ctx);
|
|
24395
24638
|
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && (!hasSelfAcceptingNonStyleHotModule(ctx.modules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
24396
24639
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|