weapp-tailwindcss 5.0.12 → 5.0.13
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-DU2ATDhw.js → bundle-state-CKWeTEhv.js} +2 -2
- package/dist/{bundle-state-BxMNKjBV.mjs → bundle-state-zQ2MrDdi.mjs} +1 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
- package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/vite/css-memory.d.ts +27 -0
- package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +8 -7
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
- package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
- package/dist/bundlers/vite/map-cache.d.ts +2 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
- package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
- package/dist/bundlers/vite/source-candidates.d.ts +3 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/vite/source-scan.d.ts +1 -1
- package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/cli.js +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
- package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/framework/index.d.ts +59 -0
- package/dist/framework.d.ts +1 -0
- package/dist/framework.js +198 -0
- package/dist/framework.mjs +180 -0
- package/dist/{generator-Cb1Zp3Al.js → generator-CzpArpCL.js} +1 -1
- package/dist/{generator-mvNFUvns.mjs → generator-ITLd7PTl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-BfZpaYSQ.mjs → gulp-DfOQERcV.mjs} +44 -16
- package/dist/{gulp-CxGZU0-v.js → gulp-XT8Jc7lH.js} +44 -16
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-BMftW7Us.js} +298 -221
- package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-DQIP_8qP.mjs} +297 -220
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -4
- package/dist/index.mjs +6 -5
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/{precheck-30zNPRlI.js → precheck-B0Z8yW7E.js} +98 -27
- package/dist/{precheck-CsFr1q2l.mjs → precheck-CRI90iL1.mjs} +97 -26
- package/dist/presets.js +3 -3
- package/dist/presets.mjs +3 -3
- package/dist/{tailwindcss-CK84uGBp.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
- package/dist/{tailwindcss-Clpkz1oR.js → tailwindcss-DZEwT3C_.js} +3 -3
- package/dist/{transform-Cju08-aJ.mjs → transform-DfcEjsZF.mjs} +29 -21
- package/dist/{transform-CaVEBOuR.js → transform-YmrmxuF3.js} +29 -21
- package/dist/types/user-defined-options/general.d.ts +3 -1
- package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
- package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
- package/dist/{v3-engine-CQE5JJNZ.js → v3-engine-2rrgylhn.js} +53 -6
- package/dist/{v3-engine-DKBaKWGL.mjs → v3-engine-C6eJ0YzK.mjs} +46 -5
- package/dist/{vite-BBGOjh9e.js → vite-CXHVsHmX.js} +1945 -1280
- package/dist/{vite-CS5DE-HD.mjs → vite-DjI09vVN.mjs} +1944 -1279
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +346 -186
- package/dist/weapp-tw-runtime-classset-loader.js +25 -0
- package/dist/{webpack-SPcri_D8.mjs → webpack-BcPpnT90.mjs} +165 -35
- package/dist/{webpack-DIWrcpRo.js → webpack-CfkUkMXG.js} +167 -37
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +9 -4
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const require_watch_dependencies = require("./watch-dependencies-bpG6kmAf.js");
|
|
2
2
|
let node_buffer = require("node:buffer");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_watch_dependencies.__toESM(node_path);
|
|
3
6
|
let node_process = require("node:process");
|
|
4
7
|
node_process = require_watch_dependencies.__toESM(node_process);
|
|
5
8
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
@@ -30,10 +33,32 @@ function removeUnsupportedThemeKeyframes(root) {
|
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
}
|
|
36
|
+
function resolveOriginalCssSource(file, source) {
|
|
37
|
+
if (!isPlainCssResource(file)) return node_buffer.Buffer.isBuffer(source) ? source.toString("utf8") : source;
|
|
38
|
+
try {
|
|
39
|
+
return (0, node_fs.readFileSync)(file, "utf8");
|
|
40
|
+
} catch {
|
|
41
|
+
return node_buffer.Buffer.isBuffer(source) ? source.toString("utf8") : source;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function isPlainCssResource(file) {
|
|
45
|
+
return new Set([
|
|
46
|
+
".acss",
|
|
47
|
+
".css",
|
|
48
|
+
".jxss",
|
|
49
|
+
".qss",
|
|
50
|
+
".ttss",
|
|
51
|
+
".wxss"
|
|
52
|
+
]).has(node_path.default.extname(file.replace(/[?#].*$/, "")).toLowerCase());
|
|
53
|
+
}
|
|
33
54
|
const WeappTwRuntimeClassSetLoader = function(source) {
|
|
34
55
|
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"]) node_process.default.stdout.write(`[weapp-tw-runtime-classset-loader] executing for ${this.resourcePath}\n`);
|
|
35
56
|
const rawOptions = this.getOptions();
|
|
36
57
|
const opt = require_watch_dependencies.getWebpackLoaderRuntime(rawOptions?.weappTailwindcssRuntimeKey)?.classSet ?? rawOptions;
|
|
58
|
+
if (this.resourcePath) opt?.registerCssSourceFile?.({
|
|
59
|
+
file: this.resourcePath,
|
|
60
|
+
css: resolveOriginalCssSource(this.resourcePath, source)
|
|
61
|
+
});
|
|
37
62
|
const maybePromise = opt?.getClassSet?.();
|
|
38
63
|
const applyWatchDependencies = (dependencies) => {
|
|
39
64
|
for (const file of dependencies?.files ?? []) require_watch_dependencies.registerWebpackWatchFile(this, file);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
3
|
-
import { b as refreshTailwindRuntimeState, d as _defineProperty, i as pluginName, n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-
|
|
4
|
-
import { r as getGroupedEntries } from "./utils-
|
|
5
|
-
import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-
|
|
6
|
-
import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, g as annotateCssSourceTrace, h as pruneMiniProgramGeneratedCss, l as pushConcurrentTaskFactories, m as finalizeMiniProgramCss, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, p as isPureLocalCssImportWrapper, r as createSourceCandidateCollector, s as generateCssByGenerator, v as createCssTokenSourceMap, y as isCssSourceTraceEnabled } from "./hmr-timing-
|
|
7
|
-
import { S as toAbsoluteOutputPath, c as hasBundlerGeneratedCssMarker, d as resolvePackageDir, f as resolvePluginDisabledState, n as createBundleBuildState, r as updateBundleBuildState, t as buildBundleSnapshot, u as stripBundlerGeneratedCssMarkers, v as isSourceStyleRequest, x as resolveOutputSpecifier, y as stripRequestQuery } from "./bundle-state-
|
|
1
|
+
import { P as removeTailwindSourceDirectives, Y as getTailwindV4IncrementalGenerateCacheStats, a as getTailwindV3IncrementalGenerateCacheStats, h as resolveViteSourceScanEntries, ot as createDebug, u as getRuntimeClassSetSignature, ut as resolveTailwindcssOptions } from "./v3-engine-C6eJ0YzK.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-ITLd7PTl.mjs";
|
|
3
|
+
import { b as refreshTailwindRuntimeState, d as _defineProperty, i as pluginName, n as getCompilerContext, r as resolveStyleOptionsFromContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-CRI90iL1.mjs";
|
|
4
|
+
import { r as getGroupedEntries } from "./utils-DodxWHGz.mjs";
|
|
5
|
+
import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-DTq3uYBK.mjs";
|
|
6
|
+
import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, g as annotateCssSourceTrace, h as pruneMiniProgramGeneratedCss, l as pushConcurrentTaskFactories, m as finalizeMiniProgramCss, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, p as isPureLocalCssImportWrapper, r as createSourceCandidateCollector, s as generateCssByGenerator, v as createCssTokenSourceMap, y as isCssSourceTraceEnabled } from "./hmr-timing-DQIP_8qP.mjs";
|
|
7
|
+
import { S as toAbsoluteOutputPath, c as hasBundlerGeneratedCssMarker, d as resolvePackageDir, f as resolvePluginDisabledState, n as createBundleBuildState, r as updateBundleBuildState, t as buildBundleSnapshot, u as stripBundlerGeneratedCssMarkers, v as isSourceStyleRequest, x as resolveOutputSpecifier, y as stripRequestQuery } from "./bundle-state-zQ2MrDdi.mjs";
|
|
8
8
|
import Module, { createRequire } from "node:module";
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
@@ -311,6 +311,48 @@ function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandl
|
|
|
311
311
|
pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
312
312
|
pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
|
|
313
313
|
}
|
|
314
|
+
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
315
|
+
return cssHandlerOptions.sourceOptions?.sourceCss ?? rawSource;
|
|
316
|
+
}
|
|
317
|
+
function stripStyleExtension(file) {
|
|
318
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
319
|
+
const ext = path.extname(normalized);
|
|
320
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
321
|
+
}
|
|
322
|
+
function normalizeMatchPath(file) {
|
|
323
|
+
return file.split(path.sep).join("/");
|
|
324
|
+
}
|
|
325
|
+
function isPathWithinRoot(file, root) {
|
|
326
|
+
const relative = path.relative(root, file);
|
|
327
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
328
|
+
}
|
|
329
|
+
function collectWebpackCssMatchBases(file, roots) {
|
|
330
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
331
|
+
const bases = /* @__PURE__ */ new Set();
|
|
332
|
+
const addBase = (candidate) => {
|
|
333
|
+
const stripped = normalizeMatchPath(stripStyleExtension(candidate));
|
|
334
|
+
if (stripped.length > 0) {
|
|
335
|
+
bases.add(stripped);
|
|
336
|
+
const withoutWorkspaceSegment = stripped.replace(/^(?:src|dist)\//, "");
|
|
337
|
+
if (withoutWorkspaceSegment !== stripped && withoutWorkspaceSegment.length > 0) bases.add(withoutWorkspaceSegment);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
addBase(normalizedFile);
|
|
341
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
342
|
+
if (path.isAbsolute(normalizedFile)) {
|
|
343
|
+
for (const root of resolvedRoots) if (isPathWithinRoot(normalizedFile, root)) addBase(path.relative(root, normalizedFile));
|
|
344
|
+
} else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
345
|
+
return bases;
|
|
346
|
+
}
|
|
347
|
+
function scoreWebpackCssSourceFileMatch(outputFile, sourceFile, options) {
|
|
348
|
+
const outputBases = collectWebpackCssMatchBases(outputFile, [options.outputRoot, options.projectRoot]);
|
|
349
|
+
const sourceBases = collectWebpackCssMatchBases(sourceFile, [options.projectRoot]);
|
|
350
|
+
let bestScore = 0;
|
|
351
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
352
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
353
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
354
|
+
return bestScore;
|
|
355
|
+
}
|
|
314
356
|
function resolveWebpackMemoryDebugStats(context) {
|
|
315
357
|
if (process.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
316
358
|
const memory = process.memoryUsage();
|
|
@@ -345,7 +387,7 @@ function resolveWebpackMemoryDebugStats(context) {
|
|
|
345
387
|
};
|
|
346
388
|
}
|
|
347
389
|
function setupWebpackV5ProcessAssetsHook(options) {
|
|
348
|
-
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
|
|
390
|
+
const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, getWebpackCssSources, debug } = options;
|
|
349
391
|
const { Compilation, sources } = compiler.webpack;
|
|
350
392
|
const { ConcatSource } = sources;
|
|
351
393
|
const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
|
|
@@ -415,22 +457,58 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
415
457
|
activeProcessHashKeys.add(hashKey);
|
|
416
458
|
};
|
|
417
459
|
for (const chunk of compilation.chunks) if (chunk.id) activeProcessHashKeys.add(chunk.id);
|
|
460
|
+
const cssSources = new Map([...getWebpackCssSources?.() ?? []].map(([file, css]) => [path.resolve(file), css]));
|
|
461
|
+
const cssSourceFiles = [...cssSources.keys()].sort();
|
|
462
|
+
const resolveWebpackCssSourceFile = (file) => {
|
|
463
|
+
if (cssSourceFiles.length === 0) return;
|
|
464
|
+
const matches = cssSourceFiles.map((sourceFile) => ({
|
|
465
|
+
sourceFile,
|
|
466
|
+
score: scoreWebpackCssSourceFileMatch(file, sourceFile, {
|
|
467
|
+
outputRoot: outputDir,
|
|
468
|
+
projectRoot: compilerOptions.tailwindcssBasedir
|
|
469
|
+
})
|
|
470
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
471
|
+
const bestScore = matches[0]?.score ?? 0;
|
|
472
|
+
const bestMatches = matches.filter((match) => match.score === bestScore);
|
|
473
|
+
return bestMatches.length === 1 ? bestMatches[0]?.sourceFile : void 0;
|
|
474
|
+
};
|
|
418
475
|
const getCssHandlerOptions = (file) => {
|
|
419
476
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
420
477
|
const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
|
|
421
|
-
const
|
|
478
|
+
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
479
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
480
|
+
const cacheKey = [
|
|
481
|
+
majorVersion ?? "unknown",
|
|
482
|
+
isMainChunk ? "1" : "0",
|
|
483
|
+
sourceFile ?? "asset",
|
|
484
|
+
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
485
|
+
file
|
|
486
|
+
].join(":");
|
|
422
487
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
423
488
|
if (cached) return cached;
|
|
424
489
|
const created = {
|
|
425
490
|
isMainChunk,
|
|
426
|
-
postcssOptions: { options: { from: file } },
|
|
491
|
+
postcssOptions: { options: { from: sourceFile ?? file } },
|
|
492
|
+
sourceOptions: {
|
|
493
|
+
outputRoot: outputDir,
|
|
494
|
+
...sourceCss === void 0 ? {} : { sourceCss },
|
|
495
|
+
...sourceFile === void 0 ? {} : { sourceFile }
|
|
496
|
+
},
|
|
427
497
|
...majorVersion === void 0 ? {} : { majorVersion }
|
|
428
498
|
};
|
|
429
499
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
430
500
|
return created;
|
|
431
501
|
};
|
|
432
502
|
const getCssUserHandlerOptions = (file) => {
|
|
433
|
-
const
|
|
503
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
504
|
+
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
505
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
506
|
+
const cacheKey = [
|
|
507
|
+
majorVersion ?? "unknown",
|
|
508
|
+
sourceFile ?? "asset",
|
|
509
|
+
sourceCss === void 0 ? "source:0" : compilerOptions.cache.computeHash(sourceCss),
|
|
510
|
+
file
|
|
511
|
+
].join(":");
|
|
434
512
|
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
435
513
|
if (cached) return cached;
|
|
436
514
|
const created = {
|
|
@@ -440,7 +518,52 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
440
518
|
cssUserHandlerOptionsCache.set(cacheKey, created);
|
|
441
519
|
return created;
|
|
442
520
|
};
|
|
521
|
+
const refreshWebpackSourceCandidates = async () => {
|
|
522
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
523
|
+
if (majorVersion !== 3 && majorVersion !== 4) return;
|
|
524
|
+
const root = compilerOptions.tailwindcssBasedir ?? process.cwd();
|
|
525
|
+
let sourceScan;
|
|
526
|
+
try {
|
|
527
|
+
sourceScan = await resolveViteSourceScanEntries(compilerOptions, runtimeState.twPatcher, {
|
|
528
|
+
root,
|
|
529
|
+
outDir: outputDir
|
|
530
|
+
});
|
|
531
|
+
} catch (error) {
|
|
532
|
+
debug("webpack source candidate scan skipped: %O", error);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const collector = createSourceCandidateCollector({
|
|
536
|
+
bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues,
|
|
537
|
+
extractor: majorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0
|
|
538
|
+
});
|
|
539
|
+
await collector.scanRoot({
|
|
540
|
+
entries: sourceScan?.entries,
|
|
541
|
+
explicit: sourceScan?.explicit,
|
|
542
|
+
root,
|
|
543
|
+
outDir: outputDir
|
|
544
|
+
});
|
|
545
|
+
collector.syncInline(sourceScan?.inlineCandidates);
|
|
546
|
+
const candidates = sourceScan?.entries ? collector.valuesForEntries(sourceScan.entries) : collector.values();
|
|
547
|
+
return {
|
|
548
|
+
candidates,
|
|
549
|
+
getSourceCandidatesForEntries: (entries, options) => collector.valuesForEntries(entries, options),
|
|
550
|
+
signature: compilerOptions.cache.computeHash(JSON.stringify({
|
|
551
|
+
root,
|
|
552
|
+
outDir: outputDir,
|
|
553
|
+
entries: sourceScan?.entries,
|
|
554
|
+
explicit: sourceScan?.explicit ?? false,
|
|
555
|
+
inlineCandidates: sourceScan?.inlineCandidates ? {
|
|
556
|
+
included: [...sourceScan.inlineCandidates.included].sort(),
|
|
557
|
+
excluded: [...sourceScan.inlineCandidates.excluded].sort()
|
|
558
|
+
} : void 0,
|
|
559
|
+
dependencies: [...sourceScan?.dependencies ?? []].sort(),
|
|
560
|
+
candidates: [...candidates].sort()
|
|
561
|
+
})),
|
|
562
|
+
tokenSources: collector.sourcesForEntries(sourceScan?.entries)
|
|
563
|
+
};
|
|
564
|
+
};
|
|
443
565
|
const finalizeCssAssetSource = (source, options = {}) => {
|
|
566
|
+
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
444
567
|
let finalized = removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
445
568
|
if (isWebGeneratorTarget || options.generatedCss !== true) return finalized;
|
|
446
569
|
try {
|
|
@@ -449,34 +572,24 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
449
572
|
finalized = finalizeMiniProgramCss(finalized, {
|
|
450
573
|
cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
|
|
451
574
|
isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
|
|
452
|
-
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3
|
|
575
|
+
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3,
|
|
576
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
453
577
|
});
|
|
454
578
|
}
|
|
455
579
|
return finalized;
|
|
456
580
|
};
|
|
457
581
|
const finalizeMiniProgramUserCssAssetSource = (source) => {
|
|
582
|
+
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
458
583
|
if (isWebGeneratorTarget) return source;
|
|
459
584
|
return finalizeMiniProgramCss(source, {
|
|
460
585
|
cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
|
|
461
586
|
isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
|
|
462
|
-
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3
|
|
587
|
+
preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3,
|
|
588
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
463
589
|
});
|
|
464
590
|
};
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
const sourceScan = await resolveViteSourceScanEntries(compilerOptions, runtimeState.twPatcher, { root });
|
|
468
|
-
const collector = createSourceCandidateCollector({
|
|
469
|
-
bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues,
|
|
470
|
-
extractor: runtimeState.twPatcher.majorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0
|
|
471
|
-
});
|
|
472
|
-
await collector.scanRoot({
|
|
473
|
-
entries: sourceScan?.entries,
|
|
474
|
-
explicit: sourceScan?.explicit,
|
|
475
|
-
root
|
|
476
|
-
});
|
|
477
|
-
collector.syncInline(sourceScan?.inlineCandidates);
|
|
478
|
-
return createCssTokenSourceMap(collector.sourcesForEntries(sourceScan?.entries), compilerOptions);
|
|
479
|
-
})() : void 0;
|
|
591
|
+
const webpackSourceCandidates = groupedEntries.css?.length || isCssSourceTraceEnabled(compilerOptions) ? await refreshWebpackSourceCandidates() : void 0;
|
|
592
|
+
const cssSourceTraceTokenSources = isCssSourceTraceEnabled(compilerOptions) && webpackSourceCandidates ? createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions) : void 0;
|
|
480
593
|
const cssSourceTraceSignature = createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
|
|
481
594
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
482
595
|
opts: compilerOptions,
|
|
@@ -626,10 +739,17 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
626
739
|
}));
|
|
627
740
|
continue;
|
|
628
741
|
}
|
|
742
|
+
if (isWebGeneratorTarget) continue;
|
|
629
743
|
const cacheKey = file;
|
|
630
744
|
const hashKey = `${file}:asset`;
|
|
631
745
|
rememberProcessCacheKey(cacheKey, hashKey);
|
|
632
|
-
const
|
|
746
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
747
|
+
const cssSourceHash = (() => {
|
|
748
|
+
const sourceFile = resolveWebpackCssSourceFile(file);
|
|
749
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile) : void 0;
|
|
750
|
+
return sourceCss === void 0 ? "webpack-css-source:0" : `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}`;
|
|
751
|
+
})();
|
|
752
|
+
const runtimeAwareHash = createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(rawSource), `${runtimeSetHash}:${webpackSourceCandidates?.signature ?? "source-candidates:0"}:${cssSourceTraceSignature}:${cssSourceHash}`);
|
|
633
753
|
tasks.push(processCachedTask({
|
|
634
754
|
cache: compilerOptions.cache,
|
|
635
755
|
cacheKey,
|
|
@@ -645,19 +765,21 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
645
765
|
transform: async () => {
|
|
646
766
|
await runtimeState.readyPromise;
|
|
647
767
|
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
768
|
+
const generatorRawSource = resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions);
|
|
648
769
|
if (isPureLocalCssImportWrapper(rawSource)) return { result: new ConcatSource(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(rawSource), { importFallback: true })) };
|
|
649
770
|
const generated = await generateCssByGenerator({
|
|
650
771
|
opts: compilerOptions,
|
|
651
772
|
runtimeState,
|
|
652
773
|
runtime: runtimeSet,
|
|
653
|
-
rawSource,
|
|
774
|
+
rawSource: generatorRawSource,
|
|
654
775
|
file,
|
|
655
776
|
cssHandlerOptions,
|
|
656
777
|
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
778
|
+
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
657
779
|
styleHandler: compilerOptions.styleHandler,
|
|
658
780
|
debug
|
|
659
781
|
});
|
|
660
|
-
const source = new ConcatSource(finalizeTracedCss(
|
|
782
|
+
const source = new ConcatSource(finalizeTracedCss(generated?.css ?? finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false })));
|
|
661
783
|
if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
|
|
662
784
|
else debug("css handle: %s", file);
|
|
663
785
|
return { result: source };
|
|
@@ -730,10 +852,11 @@ function createLoaderAnchorFinders(appType) {
|
|
|
730
852
|
//#endregion
|
|
731
853
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
732
854
|
function setupWebpackV5Loaders(options) {
|
|
733
|
-
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
855
|
+
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, registerWebpackCssSourceFile, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
734
856
|
const isMpxApp = isMpx(appType);
|
|
735
857
|
if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
736
858
|
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
859
|
+
const shouldInjectRuntimeClassSetLoader = compilerOptions.generator?.target !== "web";
|
|
737
860
|
const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
738
861
|
const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
|
|
739
862
|
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
@@ -749,7 +872,8 @@ function setupWebpackV5Loaders(options) {
|
|
|
749
872
|
setWebpackLoaderRuntime(runtimeRegistryKey, {
|
|
750
873
|
classSet: {
|
|
751
874
|
getClassSet: getClassSetInLoader,
|
|
752
|
-
getWatchDependencies: getRuntimeWatchDependencies
|
|
875
|
+
getWatchDependencies: getRuntimeWatchDependencies,
|
|
876
|
+
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
|
|
753
877
|
},
|
|
754
878
|
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
755
879
|
});
|
|
@@ -807,7 +931,7 @@ function setupWebpackV5Loaders(options) {
|
|
|
807
931
|
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
808
932
|
}
|
|
809
933
|
}
|
|
810
|
-
if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
934
|
+
if (shouldInjectRuntimeClassSetLoader && runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
811
935
|
const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
|
|
812
936
|
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
813
937
|
if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
|
|
@@ -915,6 +1039,7 @@ var WeappTailwindcss = class {
|
|
|
915
1039
|
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
916
1040
|
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
917
1041
|
const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
1042
|
+
const webpackCssSources = /* @__PURE__ */ new Map();
|
|
918
1043
|
let runtimeMetadataPrepared = false;
|
|
919
1044
|
const updateRuntimeWatchDependencies = async () => {
|
|
920
1045
|
runtimeWatchDependencyFiles.clear();
|
|
@@ -962,7 +1087,7 @@ var WeappTailwindcss = class {
|
|
|
962
1087
|
syncRuntimeRefreshRequirement();
|
|
963
1088
|
};
|
|
964
1089
|
const registerAutoCssSource = async (source) => {
|
|
965
|
-
if (
|
|
1090
|
+
if ((runtimeState.twPatcher.majorVersion ?? 0) < 4 || !source.file) return;
|
|
966
1091
|
if (!upsertTailwindV4CssSource(this.options, source)) return;
|
|
967
1092
|
runtimeSetPrepared = false;
|
|
968
1093
|
runtimeMetadataPrepared = false;
|
|
@@ -976,6 +1101,9 @@ var WeappTailwindcss = class {
|
|
|
976
1101
|
const markWebpackProcessedCssSource = (file) => {
|
|
977
1102
|
webpackProcessedCssSourceFiles.add(path.resolve(file));
|
|
978
1103
|
};
|
|
1104
|
+
const registerWebpackCssSourceFile = (source) => {
|
|
1105
|
+
webpackCssSources.set(path.resolve(source.file), source.css);
|
|
1106
|
+
};
|
|
979
1107
|
const isWebpackProcessedTailwindEntryAsset = (file) => {
|
|
980
1108
|
if ((runtimeState.twPatcher.majorVersion ?? 0) < 4 || !this.options.mainCssChunkMatcher(file, this.appType) || webpackProcessedCssSourceFiles.size === 0) return false;
|
|
981
1109
|
const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
@@ -1023,6 +1151,7 @@ var WeappTailwindcss = class {
|
|
|
1023
1151
|
getClassSetInLoader,
|
|
1024
1152
|
getRuntimeSetInLoader,
|
|
1025
1153
|
markWebpackProcessedCssSource,
|
|
1154
|
+
registerWebpackCssSourceFile,
|
|
1026
1155
|
getRuntimeWatchDependencies() {
|
|
1027
1156
|
return {
|
|
1028
1157
|
files: runtimeWatchDependencyFiles,
|
|
@@ -1046,6 +1175,7 @@ var WeappTailwindcss = class {
|
|
|
1046
1175
|
},
|
|
1047
1176
|
isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
|
|
1048
1177
|
runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
|
|
1178
|
+
getWebpackCssSources: () => webpackCssSources,
|
|
1049
1179
|
debug
|
|
1050
1180
|
});
|
|
1051
1181
|
}
|