weapp-tailwindcss 5.1.14 → 5.1.16
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/auto-2dg_uhEJ.mjs +13 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +2 -0
- package/dist/bundlers/gulp/index.d.ts +2 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +4 -2
- package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
- package/dist/bundlers/shared/generated-css-marker.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
- package/dist/bundlers/shared/generator-css/types.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
- package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
- package/dist/bundlers/shared/generator-css.d.ts +1 -2
- package/dist/bundlers/shared/style-requests.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
- package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
- package/dist/bundlers/vite/generate-bundle/bundle-markup-candidates.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
- package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
- package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
- package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
- package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
- package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +4 -2
- package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
- package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
- package/dist/bundlers/vite/source-candidates.d.ts +4 -68
- package/dist/bundlers/vite/watch-css-post.d.ts +10 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -217
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +6 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-generation-loader.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
- package/dist/cli.js +14 -18
- package/dist/cli.mjs +14 -18
- package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
- package/dist/{context-BL8Gy71H.mjs → context-JzwzSX36.mjs} +3 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
- package/dist/{generator-B59OA64h.mjs → generator-Bv7myuhY.mjs} +557 -432
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/{gulp-DUYWxmZC.mjs → gulp-CKSklPlH.mjs} +218 -153
- package/dist/{gulp-C1Q3LRzg.js → gulp-Q1wITegn.js} +218 -153
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-C3ed5vCx.mjs → hmr-timing-BXg7nI8N.mjs} +3406 -3145
- package/dist/{hmr-timing-BZ5sWIqO.js → hmr-timing-CMPaWn9P.js} +3474 -3147
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/shared/mpx-plugin-owner.d.ts +2 -0
- package/dist/shared/mpx.d.ts +4 -1
- package/dist/{source-candidate-scan-signature-R3dzamcm.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -96
- package/dist/{source-candidate-scan-signature-D7RWjWsY.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -60
- package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
- package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
- package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
- package/dist/{tailwindcss-DPcKMLxL.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
- package/dist/{transform-D5JUgMpE.mjs → transform-B_KM9sLX.mjs} +47 -5
- package/dist/{transform-COFRlmDF.js → transform-CcYptivi.js} +47 -5
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +1 -1
- package/dist/{vite-CBU5NXTX.mjs → vite-BwQWl9ft.mjs} +1269 -878
- package/dist/{vite-BNlPdsGM.js → vite-DhVnXvAQ.js} +1314 -923
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-generation-loader.js +12 -0
- package/dist/weapp-tw-css-import-rewrite-loader-B0tVkJLH.js +10524 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +6 -10255
- package/dist/weapp-tw-runtime-classset-loader.js +10 -4
- package/dist/{webpack-CZ38fMGC.mjs → webpack-Bo1QrFPf.mjs} +1518 -1079
- package/dist/{webpack-Jpe048pQ.js → webpack-kh78iMSS.js} +1519 -1080
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +17 -7
- package/dist/auto-CrJJc5rK.mjs +0 -13
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-
|
|
1
|
+
import { $ as normalizeTailwindConfigDirectives, A as isCommentOnlyCss, B as removeTailwindV4GeneratedUserCssArtifacts, Dt as resolveSourceScanPath, E as resolveTailwindcssOptions, F as finalizeMiniProgramCss, L as pruneMiniProgramGeneratedCss, M as removeTailwindV4GeneratorAtRules, N as stripTailwindSourceMediaFragments, Nt as getTailwindV4IncrementalGenerateCacheStats, P as stripUnmatchedTailwindSourceMediaCloseFragments, Q as hasTailwindSourceDirectives, Y as hasTailwindApplyDirective, Z as hasTailwindRootDirectives, ct as hasTailwindGeneratedCss, g as upsertTailwindV4CssSource, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, j as removeMiniProgramHoverSelectors, lt as hasTailwindGeneratedCssMarkers, nt as parseImportRequest, o as resolveRuntimeBranch, rt as removeTailwindSourceDirectives, z as stripMiniProgramCssSpecificityPlaceholders } from "./generator-Bv7myuhY.mjs";
|
|
2
|
+
import { g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-BTcXX8Ka.mjs";
|
|
3
3
|
import { r as getGroupedEntries } from "./utils-MVwpU07P.mjs";
|
|
4
4
|
import { b as md5Hash, c as _defineProperty, y as createDebug } from "./wxml-DdGdeqaH.mjs";
|
|
5
|
-
import { d as refreshTailwindRuntimeState, i as pluginName, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, r as resolveStyleOptionsFromContext, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-
|
|
5
|
+
import { d as refreshTailwindRuntimeState, i as pluginName, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, r as resolveStyleOptionsFromContext, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-JzwzSX36.mjs";
|
|
6
6
|
import { getDefaultCssPreflight } from "./defaults.mjs";
|
|
7
|
-
import { A as processCachedTask, C as
|
|
8
|
-
import {
|
|
7
|
+
import { A as processCachedTask, C as hasBundlerGeneratedCssMarker, D as createCssSourceTraceCacheSignature, E as annotateCssSourceTrace, F as resolveSourceCandidateScanFiles, I as createBundleRuntimeClassSetManager, L as collectStrictEscapedRuntimeCandidates, M as createSourceCandidateStore, N as isSourceCandidateRequest, O as createCssTokenSourceMap, R as createEscapeFragments, T as stripBundlerGeneratedCssMarkers, c as pushConcurrentTaskFactories, g as isSourceStyleRequest, h as hasMiniProgramTailwindV4PreflightReset, k as isCssSourceTraceEnabled, l as resolveTaskConcurrency, n as emitHmrTiming, p as createCssSourceOrderAppend, s as collectRawSourceClassSelectors, v as stripRequestQuery, x as removeGeneratedSelectorCompatCss, y as scoreTailwindV4CssSourceFileMatch, z as isPureLocalCssImportWrapper } from "./hmr-timing-BXg7nI8N.mjs";
|
|
8
|
+
import { A as collectFrameworkPostcssOptionsFromLoaderEntries, D as toAbsoluteOutputPath, E as resolveOutputSpecifier, I as webpackStyleInjectorDelegates, M as resolvePluginDisabledState, P as createBuiltinWebpackStyleInjectorPlugin, R as resolveWebpackFrameworkProfile, a as createCandidateSignature, f as classifyBundleEntry, j as resolvePackageDir, k as captureResolvedFrameworkPostcssOptions, m as updateBundleBuildState, p as createBundleBuildState, r as createScopedGeneratorRuntime, t as createSourceCandidateScanSignature, w as generateTailwindV4Css, x as createRuntimeAffectingSourceSignature } from "./source-candidate-scan-signature-CtK-mB_C.mjs";
|
|
9
9
|
import Module, { createRequire } from "node:module";
|
|
10
10
|
import fs from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process from "node:process";
|
|
13
|
-
import { filterExistingCssRules, postcss } from "@weapp-tailwindcss/postcss";
|
|
13
|
+
import { dedupeCoveredCssRules, filterExistingCssRules, mergeCoveredCssRuleDeclarations, postcss } from "@weapp-tailwindcss/postcss";
|
|
14
14
|
import { readFile, stat } from "node:fs/promises";
|
|
15
15
|
import micromatch from "micromatch";
|
|
16
16
|
import { MappingChars2String } from "@weapp-core/escape";
|
|
@@ -67,17 +67,27 @@ function resolveSingleActiveWebpackCssResource(assetResources, activeWebpackAsse
|
|
|
67
67
|
const activeAssetResourceMatches = [...assetResources ?? []].map((sourceFile) => path.resolve(sourceFile)).filter((sourceFile) => activeWebpackAssetResourceFiles.has(sourceFile)).sort();
|
|
68
68
|
return activeAssetResourceMatches.length === 1 ? activeAssetResourceMatches[0] : void 0;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function resolveWebpackCssModuleIdentifierResource(module) {
|
|
71
|
+
if (!module.type?.startsWith("css/") || typeof module.identifier !== "function") return;
|
|
72
|
+
const identifier = module.identifier();
|
|
73
|
+
const request = identifier.startsWith("css|") ? identifier.slice(4) : identifier;
|
|
74
|
+
const resourceWithMetadata = request.slice(request.lastIndexOf("!") + 1);
|
|
75
|
+
const metadataIndex = resourceWithMetadata.indexOf("|");
|
|
76
|
+
return metadataIndex === -1 ? resourceWithMetadata : resourceWithMetadata.slice(0, metadataIndex);
|
|
77
|
+
}
|
|
78
|
+
function createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, onlyUnambiguousCssAssets) {
|
|
71
79
|
const resourcesByAsset = /* @__PURE__ */ new Map();
|
|
72
80
|
if (!chunkGraph?.getChunkModulesIterable) return resourcesByAsset;
|
|
73
81
|
const collectModuleResources = (module, resources, seen = /* @__PURE__ */ new Set()) => {
|
|
74
82
|
if (!module || seen.has(module)) return;
|
|
75
83
|
seen.add(module);
|
|
76
|
-
|
|
84
|
+
const candidates = [
|
|
77
85
|
module.resource,
|
|
78
86
|
module.request,
|
|
79
87
|
module.userRequest
|
|
80
|
-
]
|
|
88
|
+
];
|
|
89
|
+
if (onlyUnambiguousCssAssets) candidates.push(resolveWebpackCssModuleIdentifierResource(module));
|
|
90
|
+
for (const candidate of candidates) {
|
|
81
91
|
if (typeof candidate !== "string") continue;
|
|
82
92
|
const normalized = normalizeResource(candidate, module);
|
|
83
93
|
if (normalized) resources.add(normalized);
|
|
@@ -97,7 +107,7 @@ function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normal
|
|
|
97
107
|
};
|
|
98
108
|
for (const chunk of chunks) {
|
|
99
109
|
const cssFiles = toChunkFiles(chunk.files).filter((file) => cssMatcher(file));
|
|
100
|
-
if (cssFiles.length === 0) continue;
|
|
110
|
+
if (cssFiles.length === 0 || onlyUnambiguousCssAssets && cssFiles.length !== 1) continue;
|
|
101
111
|
const modules = chunkGraph.getChunkModulesIterable(chunk);
|
|
102
112
|
if (!modules) continue;
|
|
103
113
|
const cssResources = /* @__PURE__ */ new Set();
|
|
@@ -107,6 +117,12 @@ function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normal
|
|
|
107
117
|
}
|
|
108
118
|
return resourcesByAsset;
|
|
109
119
|
}
|
|
120
|
+
function createWebpackCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
|
|
121
|
+
return createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, false);
|
|
122
|
+
}
|
|
123
|
+
function createWebpackDirectCssAssetResourceMap(chunks, chunkGraph, cssMatcher, normalizeResource) {
|
|
124
|
+
return createWebpackCssAssetResourceMapInternal(chunks, chunkGraph, cssMatcher, normalizeResource, true);
|
|
125
|
+
}
|
|
110
126
|
function createAssetHashByChunkMap(chunks) {
|
|
111
127
|
const partsByFile = /* @__PURE__ */ new Map();
|
|
112
128
|
for (const chunk of chunks) {
|
|
@@ -137,13 +153,243 @@ function isWatchFileInRuntimeDependencies(file, dependencies) {
|
|
|
137
153
|
return false;
|
|
138
154
|
}
|
|
139
155
|
//#endregion
|
|
140
|
-
//#region src/bundlers/webpack/
|
|
141
|
-
function
|
|
142
|
-
return
|
|
156
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.ts
|
|
157
|
+
function isRuntimeTransformCandidate(candidate) {
|
|
158
|
+
return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.ts
|
|
162
|
+
function collectWebpackAssetUserCssMarkers(source) {
|
|
163
|
+
const markers = /* @__PURE__ */ new Set();
|
|
164
|
+
for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
165
|
+
for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
|
|
166
|
+
try {
|
|
167
|
+
const root = postcss.parse(source);
|
|
168
|
+
root.walkRules((rule) => {
|
|
169
|
+
for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
|
|
170
|
+
rule.walkDecls((decl) => {
|
|
171
|
+
if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
root.walkAtRules("font-face", (rule) => {
|
|
175
|
+
rule.walkDecls("font-family", (decl) => {
|
|
176
|
+
markers.add(`font-face:${decl.value.trim()}`);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
} catch {}
|
|
180
|
+
return markers;
|
|
143
181
|
}
|
|
144
182
|
//#endregion
|
|
145
|
-
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.ts
|
|
146
|
-
const
|
|
183
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.ts
|
|
184
|
+
const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = /* @__PURE__ */ new Set([
|
|
185
|
+
"theme",
|
|
186
|
+
"base",
|
|
187
|
+
"utilities"
|
|
188
|
+
]);
|
|
189
|
+
const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
|
|
190
|
+
const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
|
|
191
|
+
const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
|
|
192
|
+
const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
193
|
+
"*",
|
|
194
|
+
":after",
|
|
195
|
+
":before",
|
|
196
|
+
"::after",
|
|
197
|
+
"::before",
|
|
198
|
+
"::backdrop",
|
|
199
|
+
"view",
|
|
200
|
+
"text"
|
|
201
|
+
]);
|
|
202
|
+
const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
|
|
203
|
+
"box-sizing",
|
|
204
|
+
"border",
|
|
205
|
+
"border-width",
|
|
206
|
+
"border-style",
|
|
207
|
+
"border-color",
|
|
208
|
+
"margin",
|
|
209
|
+
"padding"
|
|
210
|
+
]);
|
|
211
|
+
const WEBPACK_TAILWIND_THEME_TOKEN_RE = /^--(?:tw-|color-|spacing|breakpoint-|container-|text-|font-|tracking-|leading-|radius-|shadow-|inset-shadow-|drop-shadow-|ease-|animate-|blur-|perspective-|aspect-|default-)/;
|
|
212
|
+
function parseWebpackCssLayerNames(params) {
|
|
213
|
+
return params.split(",").map((name) => name.trim()).filter(Boolean);
|
|
214
|
+
}
|
|
215
|
+
function removeWebpackTailwindGeneratedAssetCss(source) {
|
|
216
|
+
const cleaned = removeTailwindV4GeneratedUserCssArtifacts(source);
|
|
217
|
+
try {
|
|
218
|
+
const root = postcss.parse(cleaned);
|
|
219
|
+
let changed = false;
|
|
220
|
+
let removingBannerPrefix = false;
|
|
221
|
+
for (const node of [...root.nodes]) {
|
|
222
|
+
if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
|
|
223
|
+
node.remove();
|
|
224
|
+
changed = true;
|
|
225
|
+
removingBannerPrefix = true;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!removingBannerPrefix) continue;
|
|
229
|
+
if (isWebpackTailwindGeneratedPrefixNode(node)) {
|
|
230
|
+
node.remove();
|
|
231
|
+
changed = true;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
removingBannerPrefix = false;
|
|
235
|
+
}
|
|
236
|
+
root.walkAtRules("layer", (rule) => {
|
|
237
|
+
const names = parseWebpackCssLayerNames(rule.params);
|
|
238
|
+
const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
|
|
239
|
+
const isLayerDeclaration = rule.nodes === void 0;
|
|
240
|
+
const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
|
|
241
|
+
if (shouldRemoveLayer && isLayerDeclaration) {
|
|
242
|
+
rule.remove();
|
|
243
|
+
changed = true;
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (shouldRemoveLayer && !names.includes("utilities")) {
|
|
247
|
+
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
|
|
248
|
+
child.remove();
|
|
249
|
+
changed = true;
|
|
250
|
+
}
|
|
251
|
+
if (rule.nodes?.length === 0) {
|
|
252
|
+
rule.remove();
|
|
253
|
+
changed = true;
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (shouldRemoveLayer) {
|
|
258
|
+
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
|
|
259
|
+
child.remove();
|
|
260
|
+
changed = true;
|
|
261
|
+
}
|
|
262
|
+
if (rule.nodes?.length === 0) {
|
|
263
|
+
rule.remove();
|
|
264
|
+
changed = true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
root.walkRules((rule) => {
|
|
269
|
+
if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
|
|
270
|
+
const selector = rule.selector.trim();
|
|
271
|
+
if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
|
|
272
|
+
rule.remove();
|
|
273
|
+
changed = true;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
root.walkComments((comment) => {
|
|
277
|
+
if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
|
|
278
|
+
comment.remove();
|
|
279
|
+
changed = true;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
root.walkAtRules((rule) => {
|
|
283
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
|
|
284
|
+
rule.remove();
|
|
285
|
+
changed = true;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
return changed ? root.toString() : cleaned;
|
|
289
|
+
} catch {
|
|
290
|
+
return cleaned;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function isWebpackTailwindGeneratedPrefixNode(node) {
|
|
294
|
+
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
|
|
295
|
+
"theme",
|
|
296
|
+
"base",
|
|
297
|
+
"utilities"
|
|
298
|
+
], true);
|
|
299
|
+
if (node.type !== "atrule") return false;
|
|
300
|
+
const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
|
|
301
|
+
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
|
|
302
|
+
if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
|
|
303
|
+
if (node.nodes === void 0) return true;
|
|
304
|
+
return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
|
|
305
|
+
}
|
|
306
|
+
if (node.nodes === void 0 || node.nodes.length === 0) return false;
|
|
307
|
+
return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
|
|
308
|
+
}
|
|
309
|
+
function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
|
|
310
|
+
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
|
|
311
|
+
if (node.type !== "atrule") return false;
|
|
312
|
+
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
|
|
313
|
+
if (node.nodes === void 0 || node.nodes.length === 0) return false;
|
|
314
|
+
return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
|
|
315
|
+
}
|
|
316
|
+
function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
|
|
317
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
318
|
+
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
|
|
319
|
+
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
|
|
320
|
+
if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
|
|
321
|
+
if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
function isWebpackTailwindGeneratedThemeRule(rule) {
|
|
325
|
+
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
326
|
+
return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
|
|
327
|
+
}
|
|
328
|
+
function isWebpackTailwindGeneratedPreflightRule(rule) {
|
|
329
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
330
|
+
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
331
|
+
return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
|
|
332
|
+
const normalized = selector.trim().replace(/\s+/g, " ");
|
|
333
|
+
return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
|
|
334
|
+
}) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
|
|
335
|
+
}
|
|
336
|
+
function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
|
|
337
|
+
try {
|
|
338
|
+
const nodes = postcss.parse(source).nodes ?? [];
|
|
339
|
+
return nodes.length > 0 && nodes.every((node) => {
|
|
340
|
+
if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
|
|
341
|
+
return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
|
|
342
|
+
});
|
|
343
|
+
} catch {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
|
|
348
|
+
return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
|
|
349
|
+
}
|
|
350
|
+
function collectWebpackCssRuleIdentityMarkers(source) {
|
|
351
|
+
const markers = /* @__PURE__ */ new Set();
|
|
352
|
+
try {
|
|
353
|
+
const root = postcss.parse(source);
|
|
354
|
+
root.walkRules((rule) => {
|
|
355
|
+
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
356
|
+
});
|
|
357
|
+
root.walkAtRules("keyframes", (rule) => {
|
|
358
|
+
if (rule.params) markers.add(`keyframes:${rule.params}`);
|
|
359
|
+
});
|
|
360
|
+
} catch {}
|
|
361
|
+
return markers;
|
|
362
|
+
}
|
|
363
|
+
function unescapeCssIdentifier(value) {
|
|
364
|
+
return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
|
|
365
|
+
const hex = escaped.trim();
|
|
366
|
+
if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
|
|
367
|
+
return escaped;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function collectGeneratedCssRuntimeCandidates(source) {
|
|
371
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
372
|
+
if (hasBundlerGeneratedCssMarker(source) || !hasTailwindGeneratedCss(source) && !hasTailwindGeneratedCssMarkers(source)) return candidates;
|
|
373
|
+
try {
|
|
374
|
+
postcss.parse(source).walkRules((rule) => {
|
|
375
|
+
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
|
|
376
|
+
const candidate = unescapeCssIdentifier(match[1]);
|
|
377
|
+
if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
} catch {}
|
|
381
|
+
return candidates;
|
|
382
|
+
}
|
|
383
|
+
function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
|
|
384
|
+
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
|
|
385
|
+
if (rawMarkers.size === 0) return false;
|
|
386
|
+
const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
|
|
387
|
+
for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
function hasWebpackTailwindSourceDirectives(source) {
|
|
391
|
+
return Boolean(source) && (hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source) || hasTailwindGeneratedCss(source) || hasTailwindGeneratedCssMarkers(source));
|
|
392
|
+
}
|
|
147
393
|
function resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) {
|
|
148
394
|
return styleOptions.cssPreflight ?? compilerOptions.cssPreflight ?? getDefaultCssPreflight();
|
|
149
395
|
}
|
|
@@ -253,9 +499,6 @@ function removeTailwindV4StandaloneHostPreflightRule(source) {
|
|
|
253
499
|
return source;
|
|
254
500
|
}
|
|
255
501
|
}
|
|
256
|
-
function isRuntimeTransformCandidate(candidate) {
|
|
257
|
-
return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
|
|
258
|
-
}
|
|
259
502
|
function collectRuntimeTokenSignatureParts(source) {
|
|
260
503
|
return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
|
|
261
504
|
}
|
|
@@ -299,24 +542,246 @@ function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandl
|
|
|
299
542
|
const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
|
|
300
543
|
for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
|
|
301
544
|
for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
|
|
302
|
-
pruneMapToMaxSize(cssHandlerOptionsCache,
|
|
303
|
-
pruneMapToMaxSize(cssUserHandlerOptionsCache,
|
|
304
|
-
}
|
|
305
|
-
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
306
|
-
const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
|
|
307
|
-
if (sourceCss && (hasTailwindRootDirectives(sourceCss, { importFallback: true }) || hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || hasTailwindApplyDirective(sourceCss) || hasTailwindGeneratedCss(sourceCss) || hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
|
|
308
|
-
return rawSource;
|
|
545
|
+
pruneMapToMaxSize(cssHandlerOptionsCache, 128);
|
|
546
|
+
pruneMapToMaxSize(cssUserHandlerOptionsCache, 128);
|
|
309
547
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.ts
|
|
550
|
+
function resolveWebpackMemoryDebugStats(context) {
|
|
551
|
+
if (process.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
552
|
+
const memory = process.memoryUsage();
|
|
553
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
554
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
555
|
+
return {
|
|
556
|
+
phase: context.phase,
|
|
557
|
+
process: {
|
|
558
|
+
rssMb: toMb(memory.rss),
|
|
559
|
+
heapTotalMb: toMb(memory.heapTotal),
|
|
560
|
+
heapUsedMb: toMb(memory.heapUsed),
|
|
561
|
+
externalMb: toMb(memory.external),
|
|
562
|
+
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
563
|
+
},
|
|
564
|
+
assets: {
|
|
565
|
+
active: context.activeAssetFiles,
|
|
566
|
+
activeCss: context.activeCssFiles
|
|
567
|
+
},
|
|
568
|
+
processCache: {
|
|
569
|
+
instance: processCacheInstanceSize,
|
|
570
|
+
hashMap: processCacheHashMapSize,
|
|
571
|
+
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
572
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
573
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
574
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
575
|
+
pruned: true,
|
|
576
|
+
pruneSkipped: false
|
|
577
|
+
},
|
|
578
|
+
webpackCss: {
|
|
579
|
+
handlerOptions: context.cssHandlerOptionsCache.size,
|
|
580
|
+
userHandlerOptions: context.cssUserHandlerOptionsCache.size,
|
|
581
|
+
maxHandlerOptions: 128
|
|
582
|
+
},
|
|
583
|
+
sourceCandidateScan: context.sourceCandidateScan,
|
|
584
|
+
tailwind: { v4: getTailwindV4IncrementalGenerateCacheStats() }
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
|
|
588
|
+
if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
|
|
589
|
+
return cssHandlerOptions.isMainChunk !== false;
|
|
590
|
+
}
|
|
591
|
+
function includesTailwindPreflightImport(source) {
|
|
592
|
+
if (!source) return false;
|
|
593
|
+
try {
|
|
594
|
+
let includesPreflight = false;
|
|
595
|
+
postcss.parse(source).walkAtRules((rule) => {
|
|
596
|
+
if (rule.name === "tailwind") {
|
|
597
|
+
includesPreflight || (includesPreflight = rule.params.trim() === "base");
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (rule.name !== "import") return;
|
|
601
|
+
const request = parseImportRequest(rule.params)?.replaceAll("\\", "/");
|
|
602
|
+
includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
|
|
603
|
+
});
|
|
604
|
+
return includesPreflight;
|
|
605
|
+
} catch {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
|
|
610
|
+
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
611
|
+
if (isWebGeneratorTarget) return source;
|
|
612
|
+
return stripMiniProgramCssSpecificityPlaceholders(removeTailwindV4StandaloneHostPreflightRule(finalizeMiniProgramCss(removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
|
|
613
|
+
cssPreflight: options.cssPreflight === false ? false : !hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
|
|
614
|
+
isTailwindcssV4: true,
|
|
615
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
616
|
+
})));
|
|
617
|
+
}
|
|
618
|
+
function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
|
|
619
|
+
return !hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.ts
|
|
623
|
+
function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
|
|
624
|
+
if (options.finalized === true) return options.annotateCss(css);
|
|
625
|
+
if (options.isWebGeneratorTarget || !isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
|
|
626
|
+
const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
|
|
627
|
+
return options.annotateCss(finalized);
|
|
628
|
+
}
|
|
629
|
+
function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
|
|
630
|
+
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
631
|
+
if (isWebGeneratorTarget) {
|
|
632
|
+
if (options.generatedCss === true) return stripTrailingLineWhitespace(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(stripBundlerGeneratedCssMarkers(source))));
|
|
633
|
+
return stripTrailingLineWhitespace(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
|
|
634
|
+
}
|
|
635
|
+
let finalized = removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
636
|
+
if (options.generatedCss !== true) {
|
|
637
|
+
finalized = finalizeMiniProgramCss(finalized, {
|
|
638
|
+
cssPreflight: false,
|
|
639
|
+
isTailwindcssV4: true,
|
|
640
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
641
|
+
});
|
|
642
|
+
finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
643
|
+
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
finalized = pruneMiniProgramGeneratedCss(finalized, { preservePreflight: options.cssPreflight !== false });
|
|
647
|
+
} catch {}
|
|
648
|
+
const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
|
|
649
|
+
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
650
|
+
const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
|
|
651
|
+
finalized = finalizeMiniProgramCss(finalized, {
|
|
652
|
+
cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
|
|
653
|
+
isTailwindcssV4: true,
|
|
654
|
+
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
655
|
+
});
|
|
656
|
+
finalized = ensureWebpackMiniProgramTwContentInit(finalized);
|
|
657
|
+
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
658
|
+
else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
659
|
+
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
660
|
+
}
|
|
661
|
+
function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
|
|
662
|
+
if (isWebGeneratorTarget) return source;
|
|
663
|
+
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
664
|
+
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(dedupeCoveredCssRules(dedupeMiniProgramPreflightSelectorRules(source)), styleOptions.cssRemoveHoverPseudoClass));
|
|
665
|
+
}
|
|
666
|
+
function collectWebpackJsRuntimeCandidatesFromAssets(options) {
|
|
667
|
+
if (options.isWebGeneratorTarget) return;
|
|
668
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
669
|
+
for (const file of options.jsAssets) {
|
|
670
|
+
const sourceLike = options.getAssetSource(file);
|
|
671
|
+
if (sourceLike === void 0) continue;
|
|
672
|
+
const source = stringifyWebpackSourceLike(sourceLike);
|
|
673
|
+
for (const candidate of collectStrictEscapedRuntimeCandidates(source, MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
|
|
674
|
+
}
|
|
675
|
+
return candidates;
|
|
676
|
+
}
|
|
677
|
+
function collectWebpackJsRuntimeTokenSignature(options) {
|
|
678
|
+
if (options.isWebGeneratorTarget) return "";
|
|
679
|
+
const tokens = [];
|
|
680
|
+
for (const file of options.jsAssets) {
|
|
681
|
+
const sourceLike = options.getAssetSource(file);
|
|
682
|
+
if (sourceLike === void 0) continue;
|
|
683
|
+
tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
|
|
684
|
+
}
|
|
685
|
+
return tokens.sort().join("\n");
|
|
686
|
+
}
|
|
687
|
+
function addRuntimeTransformCandidates(target, candidates) {
|
|
688
|
+
if (!candidates?.size) return;
|
|
689
|
+
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
|
|
690
|
+
}
|
|
691
|
+
function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
|
|
692
|
+
if (!isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
|
|
693
|
+
return createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
|
|
694
|
+
}
|
|
695
|
+
function stringifyOptionalWebpackSourceValue(value) {
|
|
696
|
+
return typeof value === "string" ? value : value?.toString() ?? "";
|
|
697
|
+
}
|
|
698
|
+
function stringifyWebpackSourceLike(source) {
|
|
699
|
+
if (typeof source === "string") return source;
|
|
700
|
+
const value = source.source();
|
|
701
|
+
return typeof value === "string" ? value : value.toString();
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.ts
|
|
705
|
+
function isWindowsAbsoluteResourcePath(file) {
|
|
706
|
+
return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
|
|
707
|
+
}
|
|
708
|
+
function isPosixAbsoluteResourcePath(file) {
|
|
709
|
+
return file.startsWith("/");
|
|
710
|
+
}
|
|
711
|
+
function resolveWebpackResourcePath(file, base) {
|
|
712
|
+
if (isWindowsAbsoluteResourcePath(file)) return path.win32.resolve(file);
|
|
713
|
+
if (isPosixAbsoluteResourcePath(file)) return path.posix.resolve(file);
|
|
714
|
+
if (base) {
|
|
715
|
+
if (isWindowsAbsoluteResourcePath(base)) return path.win32.resolve(base, file);
|
|
716
|
+
if (isPosixAbsoluteResourcePath(base)) return path.posix.resolve(base, file);
|
|
717
|
+
return path.resolve(base, file);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function dirnameWebpackResourcePath(file) {
|
|
721
|
+
if (isWindowsAbsoluteResourcePath(file)) return path.win32.dirname(file);
|
|
722
|
+
if (isPosixAbsoluteResourcePath(file)) return path.posix.dirname(file);
|
|
723
|
+
return path.dirname(file);
|
|
724
|
+
}
|
|
725
|
+
function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
|
|
726
|
+
if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
|
|
727
|
+
const normalized = stripResourceQuery(resource);
|
|
728
|
+
if (!normalized) return;
|
|
729
|
+
const absoluteResource = resolveWebpackResourcePath(normalized);
|
|
730
|
+
if (absoluteResource) return absoluteResource;
|
|
731
|
+
const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
|
|
732
|
+
const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
|
|
733
|
+
return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
|
|
734
|
+
}
|
|
735
|
+
function isSameWebpackCssSourceScope(options) {
|
|
736
|
+
if (!options.currentSourceFile) return false;
|
|
737
|
+
const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? path.resolve(options.candidateSourceFile);
|
|
738
|
+
if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? path.resolve(options.currentSourceFile))) return true;
|
|
739
|
+
const outputResources = options.resourcesByAsset.get(options.outputFile);
|
|
740
|
+
if (!outputResources) return false;
|
|
741
|
+
return [...outputResources].some((resource) => {
|
|
742
|
+
return (resolveWebpackResourcePath(resource) ?? path.resolve(resource)) === candidateKey;
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function shouldAppendCurrentWebpackAssetUserCss(options) {
|
|
746
|
+
const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
|
|
747
|
+
return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
|
|
748
|
+
}
|
|
749
|
+
function createWebpackCurrentAssetUserRawSource(options) {
|
|
750
|
+
if (!options.shouldAppendCurrentAssetUserCss) return;
|
|
751
|
+
if (options.sourceCssProcessed) return {
|
|
752
|
+
css: options.currentAssetUserCssSource,
|
|
753
|
+
processed: true
|
|
754
|
+
};
|
|
755
|
+
if (!options.currentAssetHasUserCss) return;
|
|
756
|
+
return {
|
|
757
|
+
css: options.currentAssetUserCssSource,
|
|
758
|
+
processed: options.currentAssetLooksGenerated
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.ts
|
|
763
|
+
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
764
|
+
const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
|
|
765
|
+
if (sourceCss && (hasTailwindRootDirectives(sourceCss, { importFallback: true }) || hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || hasTailwindApplyDirective(sourceCss) || hasTailwindGeneratedCss(sourceCss) || hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
|
|
766
|
+
return rawSource;
|
|
767
|
+
}
|
|
768
|
+
function shouldConsumeWebpackLoaderGeneratedCss(options) {
|
|
769
|
+
if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
|
|
770
|
+
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
|
|
771
|
+
if (options.hasBundlerGeneratedCssMarker) return true;
|
|
772
|
+
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
|
|
773
|
+
return Boolean(options.allowMarkerlessRegistryMatch && options.loaderGeneratedClassSet && options.sourceCandidates && !hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) && !hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates));
|
|
774
|
+
}
|
|
775
|
+
function hasDeferredWebpackGeneratedCss(source, generatedClassSets) {
|
|
776
|
+
const selectors = collectRawSourceClassSelectors(source);
|
|
777
|
+
for (const classSet of generatedClassSets) for (const candidate of classSet) if (selectors.has(candidate)) return true;
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
function hasUsableWebpackGeneratorCssSources(cssSources) {
|
|
781
|
+
return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
|
|
782
|
+
}
|
|
783
|
+
function normalizeWebpackGeneratorCssSources(cssSources) {
|
|
784
|
+
if (!Array.isArray(cssSources)) return;
|
|
320
785
|
const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
|
|
321
786
|
return normalized.length > 0 ? normalized : void 0;
|
|
322
787
|
}
|
|
@@ -366,26 +831,6 @@ function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource,
|
|
|
366
831
|
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
|
|
367
832
|
return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !hasTailwindRootDirectives(rawSource, { importFallback: true }) && !hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !hasTailwindApplyDirective(rawSource) && rawMarkers.size > 0 && !isOnlyWebpackTailwindGeneratedPreflightCss(rawSource) && (!hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
|
|
368
833
|
}
|
|
369
|
-
function collectWebpackAssetUserCssMarkers(source) {
|
|
370
|
-
const markers = /* @__PURE__ */ new Set();
|
|
371
|
-
for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
372
|
-
for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
|
|
373
|
-
try {
|
|
374
|
-
const root = postcss.parse(source);
|
|
375
|
-
root.walkRules((rule) => {
|
|
376
|
-
for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
|
|
377
|
-
rule.walkDecls((decl) => {
|
|
378
|
-
if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
root.walkAtRules("font-face", (rule) => {
|
|
382
|
-
rule.walkDecls("font-family", (decl) => {
|
|
383
|
-
markers.add(`font-face:${decl.value.trim()}`);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
} catch {}
|
|
387
|
-
return markers;
|
|
388
|
-
}
|
|
389
834
|
function hasWebpackClassSelector(selector) {
|
|
390
835
|
return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
|
|
391
836
|
}
|
|
@@ -399,7 +844,8 @@ function isWebpackKeyframesRule(rule) {
|
|
|
399
844
|
}
|
|
400
845
|
function collectWebpackBareSelectorUserCss(source) {
|
|
401
846
|
try {
|
|
402
|
-
const
|
|
847
|
+
const normalizedSource = removeTailwindSourceDirectives(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(source)), { importFallback: true });
|
|
848
|
+
const root = postcss.parse(normalizedSource);
|
|
403
849
|
let changed = false;
|
|
404
850
|
root.walkAtRules((rule) => {
|
|
405
851
|
if (rule.name === "import" || rule.name === "font-face" || rule.name.endsWith("keyframes")) {
|
|
@@ -419,220 +865,13 @@ function collectWebpackBareSelectorUserCss(source) {
|
|
|
419
865
|
changed = true;
|
|
420
866
|
}
|
|
421
867
|
});
|
|
422
|
-
return changed ? root.toString() :
|
|
868
|
+
return changed ? root.toString() : normalizedSource;
|
|
423
869
|
} catch {
|
|
424
870
|
return "";
|
|
425
871
|
}
|
|
426
872
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
"base",
|
|
430
|
-
"utilities"
|
|
431
|
-
]);
|
|
432
|
-
const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
|
|
433
|
-
const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
|
|
434
|
-
const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
|
|
435
|
-
const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
|
|
436
|
-
"*",
|
|
437
|
-
":after",
|
|
438
|
-
":before",
|
|
439
|
-
"::after",
|
|
440
|
-
"::before",
|
|
441
|
-
"::backdrop",
|
|
442
|
-
"view",
|
|
443
|
-
"text"
|
|
444
|
-
]);
|
|
445
|
-
const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
|
|
446
|
-
"box-sizing",
|
|
447
|
-
"border",
|
|
448
|
-
"border-width",
|
|
449
|
-
"border-style",
|
|
450
|
-
"border-color",
|
|
451
|
-
"margin",
|
|
452
|
-
"padding"
|
|
453
|
-
]);
|
|
454
|
-
const WEBPACK_TAILWIND_THEME_TOKEN_RE = /^--(?:tw-|color-|spacing|breakpoint-|container-|text-|font-|tracking-|leading-|radius-|shadow-|inset-shadow-|drop-shadow-|ease-|animate-|blur-|perspective-|aspect-|default-)/;
|
|
455
|
-
function parseWebpackCssLayerNames(params) {
|
|
456
|
-
return params.split(",").map((name) => name.trim()).filter(Boolean);
|
|
457
|
-
}
|
|
458
|
-
function removeWebpackTailwindGeneratedAssetCss(source) {
|
|
459
|
-
const cleaned = removeTailwindV4GeneratedUserCssArtifacts(source);
|
|
460
|
-
try {
|
|
461
|
-
const root = postcss.parse(cleaned);
|
|
462
|
-
let changed = false;
|
|
463
|
-
let removingBannerPrefix = false;
|
|
464
|
-
for (const node of [...root.nodes]) {
|
|
465
|
-
if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
|
|
466
|
-
node.remove();
|
|
467
|
-
changed = true;
|
|
468
|
-
removingBannerPrefix = true;
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
if (!removingBannerPrefix) continue;
|
|
472
|
-
if (isWebpackTailwindGeneratedPrefixNode(node)) {
|
|
473
|
-
node.remove();
|
|
474
|
-
changed = true;
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
477
|
-
removingBannerPrefix = false;
|
|
478
|
-
}
|
|
479
|
-
root.walkAtRules("layer", (rule) => {
|
|
480
|
-
const names = parseWebpackCssLayerNames(rule.params);
|
|
481
|
-
const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
|
|
482
|
-
const isLayerDeclaration = rule.nodes === void 0;
|
|
483
|
-
const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
|
|
484
|
-
if (shouldRemoveLayer && isLayerDeclaration) {
|
|
485
|
-
rule.remove();
|
|
486
|
-
changed = true;
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (shouldRemoveLayer && !names.includes("utilities")) {
|
|
490
|
-
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
|
|
491
|
-
child.remove();
|
|
492
|
-
changed = true;
|
|
493
|
-
}
|
|
494
|
-
if (rule.nodes?.length === 0) {
|
|
495
|
-
rule.remove();
|
|
496
|
-
changed = true;
|
|
497
|
-
}
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
if (shouldRemoveLayer) {
|
|
501
|
-
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
|
|
502
|
-
child.remove();
|
|
503
|
-
changed = true;
|
|
504
|
-
}
|
|
505
|
-
if (rule.nodes?.length === 0) {
|
|
506
|
-
rule.remove();
|
|
507
|
-
changed = true;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
root.walkRules((rule) => {
|
|
512
|
-
if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
|
|
513
|
-
const selector = rule.selector.trim();
|
|
514
|
-
if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
|
|
515
|
-
rule.remove();
|
|
516
|
-
changed = true;
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
root.walkComments((comment) => {
|
|
520
|
-
if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
|
|
521
|
-
comment.remove();
|
|
522
|
-
changed = true;
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
root.walkAtRules((rule) => {
|
|
526
|
-
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
|
|
527
|
-
rule.remove();
|
|
528
|
-
changed = true;
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
return changed ? root.toString() : cleaned;
|
|
532
|
-
} catch {
|
|
533
|
-
return cleaned;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
function isWebpackTailwindGeneratedPrefixNode(node) {
|
|
537
|
-
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
|
|
538
|
-
"theme",
|
|
539
|
-
"base",
|
|
540
|
-
"utilities"
|
|
541
|
-
], true);
|
|
542
|
-
if (node.type !== "atrule") return false;
|
|
543
|
-
const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
|
|
544
|
-
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
|
|
545
|
-
if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
|
|
546
|
-
if (node.nodes === void 0) return true;
|
|
547
|
-
return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
|
|
548
|
-
}
|
|
549
|
-
if (node.nodes === void 0 || node.nodes.length === 0) return false;
|
|
550
|
-
return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
|
|
551
|
-
}
|
|
552
|
-
function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
|
|
553
|
-
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
|
|
554
|
-
if (node.type !== "atrule") return false;
|
|
555
|
-
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
|
|
556
|
-
if (node.nodes === void 0 || node.nodes.length === 0) return false;
|
|
557
|
-
return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
|
|
558
|
-
}
|
|
559
|
-
function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
|
|
560
|
-
const selectors = rule.selectors ?? [rule.selector];
|
|
561
|
-
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
|
|
562
|
-
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
|
|
563
|
-
if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
|
|
564
|
-
if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
|
|
565
|
-
return false;
|
|
566
|
-
}
|
|
567
|
-
function isWebpackTailwindGeneratedThemeRule(rule) {
|
|
568
|
-
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
569
|
-
return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
|
|
570
|
-
}
|
|
571
|
-
function isWebpackTailwindGeneratedPreflightRule(rule) {
|
|
572
|
-
const selectors = rule.selectors ?? [rule.selector];
|
|
573
|
-
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
574
|
-
return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
|
|
575
|
-
const normalized = selector.trim().replace(/\s+/g, " ");
|
|
576
|
-
return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
|
|
577
|
-
}) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
|
|
578
|
-
}
|
|
579
|
-
function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
|
|
580
|
-
try {
|
|
581
|
-
const nodes = postcss.parse(source).nodes ?? [];
|
|
582
|
-
return nodes.length > 0 && nodes.every((node) => {
|
|
583
|
-
if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
|
|
584
|
-
return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
|
|
585
|
-
});
|
|
586
|
-
} catch {
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
|
|
591
|
-
return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
|
|
592
|
-
}
|
|
593
|
-
function collectWebpackCssRuleIdentityMarkers(source) {
|
|
594
|
-
const markers = /* @__PURE__ */ new Set();
|
|
595
|
-
try {
|
|
596
|
-
const root = postcss.parse(source);
|
|
597
|
-
root.walkRules((rule) => {
|
|
598
|
-
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
|
|
599
|
-
});
|
|
600
|
-
root.walkAtRules("keyframes", (rule) => {
|
|
601
|
-
if (rule.params) markers.add(`keyframes:${rule.params}`);
|
|
602
|
-
});
|
|
603
|
-
} catch {}
|
|
604
|
-
return markers;
|
|
605
|
-
}
|
|
606
|
-
function unescapeCssIdentifier(value) {
|
|
607
|
-
return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
|
|
608
|
-
const hex = escaped.trim();
|
|
609
|
-
if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
|
|
610
|
-
return escaped;
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
function collectGeneratedCssRuntimeCandidates(source) {
|
|
614
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
615
|
-
if (hasBundlerGeneratedCssMarker(source) || !hasTailwindGeneratedCss(source) && !hasTailwindGeneratedCssMarkers(source)) return candidates;
|
|
616
|
-
try {
|
|
617
|
-
postcss.parse(source).walkRules((rule) => {
|
|
618
|
-
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
|
|
619
|
-
const candidate = unescapeCssIdentifier(match[1]);
|
|
620
|
-
if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
} catch {}
|
|
624
|
-
return candidates;
|
|
625
|
-
}
|
|
626
|
-
function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
|
|
627
|
-
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
|
|
628
|
-
if (rawMarkers.size === 0) return false;
|
|
629
|
-
const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
|
|
630
|
-
for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
|
|
631
|
-
return false;
|
|
632
|
-
}
|
|
633
|
-
function hasWebpackTailwindSourceDirectives(source) {
|
|
634
|
-
return Boolean(source) && (hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source) || hasTailwindGeneratedCss(source) || hasTailwindGeneratedCssMarkers(source));
|
|
635
|
-
}
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.ts
|
|
636
875
|
function isWebpackTailwindImportRequest(request) {
|
|
637
876
|
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
638
877
|
}
|
|
@@ -677,244 +916,39 @@ function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSo
|
|
|
677
916
|
if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
|
|
678
917
|
seen.add(css);
|
|
679
918
|
if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
|
|
680
|
-
css,
|
|
681
|
-
file: source.file,
|
|
682
|
-
processed: source.processed === true
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
const currentFile = currentSourceFile ? path.resolve(currentSourceFile) : void 0;
|
|
686
|
-
const parts = matchedSources.sort((a, b) => {
|
|
687
|
-
const aCurrent = currentFile !== void 0 && path.resolve(a.file) === currentFile;
|
|
688
|
-
if (aCurrent !== (currentFile !== void 0 && path.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
|
|
689
|
-
return a.file.localeCompare(b.file);
|
|
690
|
-
}).map((source) => source.css);
|
|
691
|
-
return parts.length > 0 ? {
|
|
692
|
-
css: parts.join("\n"),
|
|
693
|
-
processed: matchedSources.every((source) => source.processed)
|
|
694
|
-
} : void 0;
|
|
695
|
-
}
|
|
696
|
-
function createWebpackGeneratorUserCssSourceAppend(...sources) {
|
|
697
|
-
const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
|
|
698
|
-
if (parts.length === 0) return;
|
|
699
|
-
let css = "";
|
|
700
|
-
const usedParts = [];
|
|
701
|
-
for (const source of parts) {
|
|
702
|
-
const nextCss = css.trim().length > 0 ? filterExistingCssRules(css, source.css) : source.css;
|
|
703
|
-
if (!(nextCss.trim().length > 0)) continue;
|
|
704
|
-
css = createCssSourceOrderAppend(css, nextCss);
|
|
705
|
-
usedParts.push(source);
|
|
706
|
-
}
|
|
707
|
-
return {
|
|
708
|
-
css,
|
|
709
|
-
processed: usedParts.every((source) => source.processed)
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
function resolveWebpackMemoryDebugStats(context) {
|
|
713
|
-
if (process.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
714
|
-
const memory = process.memoryUsage();
|
|
715
|
-
const processCacheInstanceSize = context.cache.instance.size;
|
|
716
|
-
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
717
|
-
return {
|
|
718
|
-
phase: context.phase,
|
|
719
|
-
process: {
|
|
720
|
-
rssMb: toMb(memory.rss),
|
|
721
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
722
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
723
|
-
externalMb: toMb(memory.external),
|
|
724
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
725
|
-
},
|
|
726
|
-
assets: {
|
|
727
|
-
active: context.activeAssetFiles,
|
|
728
|
-
activeCss: context.activeCssFiles
|
|
729
|
-
},
|
|
730
|
-
processCache: {
|
|
731
|
-
instance: processCacheInstanceSize,
|
|
732
|
-
hashMap: processCacheHashMapSize,
|
|
733
|
-
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
734
|
-
activeHashKeys: context.activeProcessHashKeys.size,
|
|
735
|
-
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
736
|
-
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
737
|
-
pruned: true,
|
|
738
|
-
pruneSkipped: false
|
|
739
|
-
},
|
|
740
|
-
webpackCss: {
|
|
741
|
-
handlerOptions: context.cssHandlerOptionsCache.size,
|
|
742
|
-
userHandlerOptions: context.cssUserHandlerOptionsCache.size,
|
|
743
|
-
maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
|
|
744
|
-
},
|
|
745
|
-
sourceCandidateScan: context.sourceCandidateScan,
|
|
746
|
-
tailwind: { v4: getTailwindV4IncrementalGenerateCacheStats() }
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
|
|
750
|
-
if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
|
|
751
|
-
return cssHandlerOptions.isMainChunk !== false;
|
|
752
|
-
}
|
|
753
|
-
function includesTailwindPreflightImport(source) {
|
|
754
|
-
if (!source) return false;
|
|
755
|
-
try {
|
|
756
|
-
let includesPreflight = false;
|
|
757
|
-
postcss.parse(source).walkAtRules((rule) => {
|
|
758
|
-
if (rule.name === "tailwind") {
|
|
759
|
-
includesPreflight || (includesPreflight = rule.params.trim() === "base");
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
if (rule.name !== "import") return;
|
|
763
|
-
const request = parseImportRequest(rule.params)?.replaceAll("\\", "/");
|
|
764
|
-
includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
|
|
765
|
-
});
|
|
766
|
-
return includesPreflight;
|
|
767
|
-
} catch {
|
|
768
|
-
return false;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
|
|
772
|
-
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
773
|
-
if (isWebGeneratorTarget) return source;
|
|
774
|
-
return stripMiniProgramCssSpecificityPlaceholders(removeTailwindV4StandaloneHostPreflightRule(finalizeMiniProgramCss(removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
|
|
775
|
-
cssPreflight: options.cssPreflight === false ? false : !hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
|
|
776
|
-
isTailwindcssV4: true,
|
|
777
|
-
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
778
|
-
})));
|
|
779
|
-
}
|
|
780
|
-
function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
|
|
781
|
-
return !hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
|
|
782
|
-
}
|
|
783
|
-
function isWindowsAbsoluteResourcePath(file) {
|
|
784
|
-
return /^[a-z]:[\\/]/i.test(file) || /^[/\\]{2}[^/\\]/.test(file);
|
|
785
|
-
}
|
|
786
|
-
function isPosixAbsoluteResourcePath(file) {
|
|
787
|
-
return file.startsWith("/");
|
|
788
|
-
}
|
|
789
|
-
function resolveWebpackResourcePath(file, base) {
|
|
790
|
-
if (isWindowsAbsoluteResourcePath(file)) return path.win32.resolve(file);
|
|
791
|
-
if (isPosixAbsoluteResourcePath(file)) return path.posix.resolve(file);
|
|
792
|
-
if (base) {
|
|
793
|
-
if (isWindowsAbsoluteResourcePath(base)) return path.win32.resolve(base, file);
|
|
794
|
-
if (isPosixAbsoluteResourcePath(base)) return path.posix.resolve(base, file);
|
|
795
|
-
return path.resolve(base, file);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
function dirnameWebpackResourcePath(file) {
|
|
799
|
-
if (isWindowsAbsoluteResourcePath(file)) return path.win32.dirname(file);
|
|
800
|
-
if (isPosixAbsoluteResourcePath(file)) return path.posix.dirname(file);
|
|
801
|
-
return path.dirname(file);
|
|
802
|
-
}
|
|
803
|
-
function resolveWebpackCssAssetModuleResource(resource, issuer, options) {
|
|
804
|
-
if (!isCssLikeModuleResource(resource, options.cssMatcher, options.appType)) return;
|
|
805
|
-
const normalized = stripResourceQuery(resource);
|
|
806
|
-
if (!normalized) return;
|
|
807
|
-
const absoluteResource = resolveWebpackResourcePath(normalized);
|
|
808
|
-
if (absoluteResource) return absoluteResource;
|
|
809
|
-
const issuerResource = issuer?.resource ? stripResourceQuery(issuer.resource) : void 0;
|
|
810
|
-
const issuerResourcePath = issuerResource ? resolveWebpackResourcePath(issuerResource) : void 0;
|
|
811
|
-
return resolveWebpackResourcePath(normalized, issuerResourcePath ? dirnameWebpackResourcePath(issuerResourcePath) : issuer?.context);
|
|
812
|
-
}
|
|
813
|
-
function isSameWebpackCssSourceScope(options) {
|
|
814
|
-
if (!options.currentSourceFile) return false;
|
|
815
|
-
const candidateKey = resolveWebpackResourcePath(options.candidateSourceFile) ?? path.resolve(options.candidateSourceFile);
|
|
816
|
-
if (candidateKey === (resolveWebpackResourcePath(options.currentSourceFile) ?? path.resolve(options.currentSourceFile))) return true;
|
|
817
|
-
const outputResources = options.resourcesByAsset.get(options.outputFile);
|
|
818
|
-
if (!outputResources) return false;
|
|
819
|
-
return [...outputResources].some((resource) => {
|
|
820
|
-
return (resolveWebpackResourcePath(resource) ?? path.resolve(resource)) === candidateKey;
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
function shouldAppendCurrentWebpackAssetUserCss(options) {
|
|
824
|
-
const hasGeneratedAssetUserCss = options.currentAssetLooksGenerated && options.currentAssetHasUserCss;
|
|
825
|
-
return !options.currentAssetHasBundlerGeneratedMarker && !options.shouldPreserveGeneratedWebAssetUserCss && (hasGeneratedAssetUserCss || !options.sourceCssProcessed || options.registeredUserRawSource === void 0 || options.currentAssetHasUserCss) && !(options.sourceCssProcessed && options.currentAssetLooksGenerated && !options.currentAssetHasUserCss);
|
|
826
|
-
}
|
|
827
|
-
function createWebpackCurrentAssetUserRawSource(options) {
|
|
828
|
-
if (!options.shouldAppendCurrentAssetUserCss) return;
|
|
829
|
-
if (options.sourceCssProcessed) return {
|
|
830
|
-
css: options.currentAssetUserCssSource,
|
|
831
|
-
processed: true
|
|
832
|
-
};
|
|
833
|
-
if (!options.currentAssetHasUserCss) return;
|
|
834
|
-
return {
|
|
835
|
-
css: options.currentAssetUserCssSource,
|
|
836
|
-
processed: options.currentAssetLooksGenerated
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
|
|
840
|
-
if (options.finalized === true) return options.annotateCss(css);
|
|
841
|
-
if (options.isWebGeneratorTarget || !isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
|
|
842
|
-
const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
|
|
843
|
-
return options.annotateCss(finalized);
|
|
844
|
-
}
|
|
845
|
-
function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
|
|
846
|
-
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
847
|
-
if (isWebGeneratorTarget) {
|
|
848
|
-
if (options.generatedCss === true) return stripTrailingLineWhitespace(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(stripBundlerGeneratedCssMarkers(source))));
|
|
849
|
-
return stripTrailingLineWhitespace(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
|
|
850
|
-
}
|
|
851
|
-
let finalized = removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
|
|
852
|
-
if (options.generatedCss !== true) {
|
|
853
|
-
finalized = finalizeMiniProgramCss(finalized, {
|
|
854
|
-
cssPreflight: false,
|
|
855
|
-
isTailwindcssV4: true,
|
|
856
|
-
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
857
|
-
});
|
|
858
|
-
finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
859
|
-
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
860
|
-
}
|
|
861
|
-
try {
|
|
862
|
-
finalized = pruneMiniProgramGeneratedCss(finalized, { preservePreflight: options.cssPreflight !== false });
|
|
863
|
-
} catch {}
|
|
864
|
-
const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
|
|
865
|
-
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
866
|
-
const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
|
|
867
|
-
finalized = finalizeMiniProgramCss(finalized, {
|
|
868
|
-
cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
|
|
869
|
-
isTailwindcssV4: true,
|
|
870
|
-
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
|
|
871
|
-
});
|
|
872
|
-
finalized = ensureWebpackMiniProgramTwContentInit(finalized);
|
|
873
|
-
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
|
|
874
|
-
else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
|
|
875
|
-
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
|
|
876
|
-
}
|
|
877
|
-
function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
|
|
878
|
-
if (isWebGeneratorTarget) return source;
|
|
879
|
-
const styleOptions = resolveStyleOptionsFromContext(compilerOptions);
|
|
880
|
-
return stripMiniProgramCssSpecificityPlaceholders(removeMiniProgramHoverSelectors(dedupeMiniProgramPreflightSelectorRules(source), styleOptions.cssRemoveHoverPseudoClass));
|
|
881
|
-
}
|
|
882
|
-
function collectWebpackJsRuntimeCandidatesFromAssets(options) {
|
|
883
|
-
if (options.isWebGeneratorTarget) return;
|
|
884
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
885
|
-
for (const file of options.jsAssets) {
|
|
886
|
-
const sourceLike = options.getAssetSource(file);
|
|
887
|
-
if (sourceLike === void 0) continue;
|
|
888
|
-
const source = stringifyWebpackSourceLike(sourceLike);
|
|
889
|
-
for (const candidate of collectStrictEscapedRuntimeCandidates(source, MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
|
|
890
|
-
}
|
|
891
|
-
return candidates;
|
|
892
|
-
}
|
|
893
|
-
function collectWebpackJsRuntimeTokenSignature(options) {
|
|
894
|
-
if (options.isWebGeneratorTarget) return "";
|
|
895
|
-
const tokens = [];
|
|
896
|
-
for (const file of options.jsAssets) {
|
|
897
|
-
const sourceLike = options.getAssetSource(file);
|
|
898
|
-
if (sourceLike === void 0) continue;
|
|
899
|
-
tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
|
|
900
|
-
}
|
|
901
|
-
return tokens.sort().join("\n");
|
|
902
|
-
}
|
|
903
|
-
function addRuntimeTransformCandidates(target, candidates) {
|
|
904
|
-
if (!candidates?.size) return;
|
|
905
|
-
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
|
|
906
|
-
}
|
|
907
|
-
function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
|
|
908
|
-
if (!isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
|
|
909
|
-
return createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
|
|
910
|
-
}
|
|
911
|
-
function stringifyOptionalWebpackSourceValue(value) {
|
|
912
|
-
return typeof value === "string" ? value : value?.toString() ?? "";
|
|
919
|
+
css,
|
|
920
|
+
file: source.file,
|
|
921
|
+
processed: source.processed === true
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
const currentFile = currentSourceFile ? path.resolve(currentSourceFile) : void 0;
|
|
925
|
+
const parts = matchedSources.sort((a, b) => {
|
|
926
|
+
const aCurrent = currentFile !== void 0 && path.resolve(a.file) === currentFile;
|
|
927
|
+
if (aCurrent !== (currentFile !== void 0 && path.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
|
|
928
|
+
return a.file.localeCompare(b.file);
|
|
929
|
+
}).map((source) => source.css);
|
|
930
|
+
return parts.length > 0 ? {
|
|
931
|
+
css: parts.join("\n"),
|
|
932
|
+
processed: matchedSources.every((source) => source.processed)
|
|
933
|
+
} : void 0;
|
|
913
934
|
}
|
|
914
|
-
function
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
935
|
+
function createWebpackGeneratorUserCssSourceAppend(...sources) {
|
|
936
|
+
const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
|
|
937
|
+
if (parts.length === 0) return;
|
|
938
|
+
let css = "";
|
|
939
|
+
const usedParts = [];
|
|
940
|
+
for (const source of parts) {
|
|
941
|
+
const merged = css.trim().length > 0 ? mergeCoveredCssRuleDeclarations(css, source.css) : void 0;
|
|
942
|
+
if (merged?.changed) css = merged.baseCss;
|
|
943
|
+
const nextCss = css.trim().length > 0 ? filterExistingCssRules(css, merged?.css ?? source.css) : source.css;
|
|
944
|
+
if (!(nextCss.trim().length > 0)) continue;
|
|
945
|
+
css = createCssSourceOrderAppend(css, nextCss);
|
|
946
|
+
usedParts.push(source);
|
|
947
|
+
}
|
|
948
|
+
return {
|
|
949
|
+
css,
|
|
950
|
+
processed: usedParts.every((source) => source.processed)
|
|
951
|
+
};
|
|
918
952
|
}
|
|
919
953
|
//#endregion
|
|
920
954
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.ts
|
|
@@ -968,7 +1002,7 @@ function collectMainImportedCssFiles(compilation, cssAssetFiles, cssMatcher, isM
|
|
|
968
1002
|
return files;
|
|
969
1003
|
}
|
|
970
1004
|
function createWebpackCssSourceResolvers(options) {
|
|
971
|
-
const { activeWebpackAssetResourceFiles, appType, compilerOptions, compilation, cssAssetFiles, cssAssetResources, cssHandlerOptionsCache, cssSources, cssUserHandlerOptionsCache, groupedCssEntriesLength, singleCssAssetFile, isWebGeneratorTarget, outputDir, runtimeState } = options;
|
|
1005
|
+
const { activeWebpackAssetResourceFiles, appType, compilerOptions, compilation, cssAssetFiles, cssAssetResources, directCssAssetResources, cssHandlerOptionsCache, cssSources, cssUserHandlerOptionsCache, groupedCssEntriesLength, singleCssAssetFile, isWebGeneratorTarget, outputDir, runtimeState } = options;
|
|
972
1006
|
const hasConfiguredTailwindV4SourceRoots = () => {
|
|
973
1007
|
const tailwindOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
974
1008
|
return (tailwindOptions?.v4?.cssEntries?.length ?? 0) > 0 || (tailwindOptions?.v4?.cssSources?.length ?? 0) > 0;
|
|
@@ -985,7 +1019,7 @@ function createWebpackCssSourceResolvers(options) {
|
|
|
985
1019
|
cwd: compilerOptions.tailwindcssBasedir
|
|
986
1020
|
});
|
|
987
1021
|
const isConfiguredMainCssEntryFile = (sourceFile) => configuredMainCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile));
|
|
988
|
-
const isCssSourceAllowedForOutput = (file, sourceFile) => !isConfiguredMainCssEntryFile(sourceFile) || scoreCssSourceOutputMatch(file, sourceFile) > 0;
|
|
1022
|
+
const isCssSourceAllowedForOutput = (file, sourceFile) => !isConfiguredMainCssEntryFile(sourceFile) || directCssAssetResources.get(file)?.has(sourceFile) === true || scoreCssSourceOutputMatch(file, sourceFile) > 0;
|
|
989
1023
|
const inferredMainCssFiles = new Set([...inferWebpackMainCssFiles(compilation.chunks, compilerOptions.cssMatcher, {
|
|
990
1024
|
mainSourceFiles: new Set(configuredMainCssEntryFiles),
|
|
991
1025
|
resourcesByAsset: cssAssetResources
|
|
@@ -1026,6 +1060,12 @@ function createWebpackCssSourceResolvers(options) {
|
|
|
1026
1060
|
return resolveConfiguredMainCssSourceFile(file);
|
|
1027
1061
|
}
|
|
1028
1062
|
const resourceMatches = [...assetResources ?? []].filter((sourceFile) => cssSources.has(sourceFile)).filter((sourceFile) => isCssSourceAllowedForOutput(file, sourceFile)).sort();
|
|
1063
|
+
const configuredResourceMatches = resourceMatches.filter((sourceFile) => configuredCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile)));
|
|
1064
|
+
if (configuredResourceMatches.length === 1) {
|
|
1065
|
+
const sourceFile = configuredResourceMatches[0];
|
|
1066
|
+
activeWebpackCssSourceFiles.add(sourceFile);
|
|
1067
|
+
return sourceFile;
|
|
1068
|
+
}
|
|
1029
1069
|
if (resourceMatches.length === 1) {
|
|
1030
1070
|
const sourceFile = resourceMatches[0];
|
|
1031
1071
|
activeWebpackCssSourceFiles.add(sourceFile);
|
|
@@ -1164,6 +1204,343 @@ function createWebpackCssSourceResolvers(options) {
|
|
|
1164
1204
|
};
|
|
1165
1205
|
}
|
|
1166
1206
|
//#endregion
|
|
1207
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.ts
|
|
1208
|
+
async function finalizeWebpackProcessAssets(context) {
|
|
1209
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeWebpackCssSourceFiles, compilerOptions, cssAssetResources, cssHandlerOptionsCache, cssTaskFactories, cssUserHandlerOptionsCache, debug, entries, groupedEntries, hmrTimingStartedAt, htmlTaskFactories, jsTaskFactories, pruneWebpackCssSources, recordTimingDetail, registeredWebpackCssSourceFiles, taskConcurrency, tasks, timingDetails, watchMode, webpackSourceCandidateScanCache } = context;
|
|
1210
|
+
if (!watchMode) {
|
|
1211
|
+
pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
|
|
1212
|
+
await Promise.all(tasks);
|
|
1213
|
+
tasks.length = 0;
|
|
1214
|
+
pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
|
|
1215
|
+
await Promise.all(tasks);
|
|
1216
|
+
tasks.length = 0;
|
|
1217
|
+
pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
|
|
1218
|
+
}
|
|
1219
|
+
const taskWaitStartedAt = performance.now();
|
|
1220
|
+
await Promise.all(tasks);
|
|
1221
|
+
recordTimingDetail("tasks.wait", taskWaitStartedAt);
|
|
1222
|
+
const pruneStartedAt = performance.now();
|
|
1223
|
+
compilerOptions.cache.prune?.({
|
|
1224
|
+
cacheKeys: activeProcessCacheKeys,
|
|
1225
|
+
hashKeys: activeProcessHashKeys
|
|
1226
|
+
});
|
|
1227
|
+
const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
|
|
1228
|
+
pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
|
|
1229
|
+
if (activeCssFiles.size > 0) pruneWebpackCssSources?.(/* @__PURE__ */ new Set([
|
|
1230
|
+
...registeredWebpackCssSourceFiles,
|
|
1231
|
+
...activeWebpackCssSourceFiles,
|
|
1232
|
+
...[...cssAssetResources.values()].flatMap((resources) => [...resources])
|
|
1233
|
+
]), { watchMode });
|
|
1234
|
+
recordTimingDetail("cache.prune", pruneStartedAt);
|
|
1235
|
+
debug("end");
|
|
1236
|
+
emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, {
|
|
1237
|
+
...timingDetails,
|
|
1238
|
+
memoryDebug: resolveWebpackMemoryDebugStats({
|
|
1239
|
+
activeAssetFiles: entries.length,
|
|
1240
|
+
activeCssFiles: activeCssFiles.size,
|
|
1241
|
+
activeProcessCacheKeys,
|
|
1242
|
+
activeProcessHashKeys,
|
|
1243
|
+
cache: compilerOptions.cache,
|
|
1244
|
+
cssHandlerOptionsCache,
|
|
1245
|
+
cssUserHandlerOptionsCache,
|
|
1246
|
+
phase: "processAssets",
|
|
1247
|
+
sourceCandidateScan: webpackSourceCandidateScanCache.getMemoryStats()
|
|
1248
|
+
})
|
|
1249
|
+
});
|
|
1250
|
+
compilerOptions.onEnd();
|
|
1251
|
+
}
|
|
1252
|
+
//#endregion
|
|
1253
|
+
//#region src/bundlers/webpack/shared/css-loader-runtime.ts
|
|
1254
|
+
function isWebpackCssLoaderRuntimeSource(source) {
|
|
1255
|
+
return source.includes("___CSS_LOADER_EXPORT___") && source.includes("___CSS_LOADER_API_IMPORT___") && source.includes("module.exports = ___CSS_LOADER_EXPORT___");
|
|
1256
|
+
}
|
|
1257
|
+
//#endregion
|
|
1258
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.ts
|
|
1259
|
+
async function finalizeWebpackGeneratedCssResult(context) {
|
|
1260
|
+
const { ConcatSource, compilerOptions, cssHandlerOptions, currentRawSource, debug, file, finalizeCssAssetSource, finalizeTracedCss, generated, generatorRawSource, generatorRuntimeSet, isWebGeneratorTarget, runtimeState, shouldPreserveExistingPreflight, sourceCss, sourceCssProcessed, userRawSource } = context;
|
|
1261
|
+
const finalizedGeneratedCss = generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
|
|
1262
|
+
css: generated.css,
|
|
1263
|
+
processed: true
|
|
1264
|
+
}, {
|
|
1265
|
+
css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
|
|
1266
|
+
processed: true
|
|
1267
|
+
})?.css ?? generated.css : generated.css, {
|
|
1268
|
+
cssPreflight: cssHandlerOptions.isMainChunk,
|
|
1269
|
+
generatedCss: true,
|
|
1270
|
+
preserveExistingPreflight: shouldPreserveExistingPreflight
|
|
1271
|
+
}) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false });
|
|
1272
|
+
const sourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[
|
|
1273
|
+
userRawSource,
|
|
1274
|
+
sourceCss === void 0 ? void 0 : {
|
|
1275
|
+
css: sourceCss,
|
|
1276
|
+
processed: sourceCssProcessed
|
|
1277
|
+
},
|
|
1278
|
+
{
|
|
1279
|
+
css: generatorRawSource,
|
|
1280
|
+
processed: false
|
|
1281
|
+
}
|
|
1282
|
+
].map((source) => {
|
|
1283
|
+
if (source === void 0) return;
|
|
1284
|
+
return {
|
|
1285
|
+
css: collectWebpackBareSelectorUserCss(source.css),
|
|
1286
|
+
processed: source.processed
|
|
1287
|
+
};
|
|
1288
|
+
}));
|
|
1289
|
+
const handledSourceBareUserCss = sourceBareUserCss === void 0 ? "" : sourceBareUserCss.processed ? sourceBareUserCss.css : (await compilerOptions.styleHandler(sourceBareUserCss.css, cssHandlerOptions)).css;
|
|
1290
|
+
const finalizedSourceBareUserCss = handledSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledSourceBareUserCss, {
|
|
1291
|
+
cssPreflight: false,
|
|
1292
|
+
generatedCss: false
|
|
1293
|
+
});
|
|
1294
|
+
const missingSourceBareUserCss = finalizedSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(finalizedGeneratedCss, finalizedSourceBareUserCss);
|
|
1295
|
+
const source = new ConcatSource(finalizeTracedCss(missingSourceBareUserCss.trim().length === 0 ? finalizedGeneratedCss : createWebpackGeneratorUserCssSourceAppend({
|
|
1296
|
+
css: finalizedGeneratedCss,
|
|
1297
|
+
processed: true
|
|
1298
|
+
}, {
|
|
1299
|
+
css: missingSourceBareUserCss,
|
|
1300
|
+
processed: true
|
|
1301
|
+
}).css, cssHandlerOptions, { finalized: true }));
|
|
1302
|
+
if (generated) {
|
|
1303
|
+
for (const className of generated.classSet) generatorRuntimeSet.add(className);
|
|
1304
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
|
|
1305
|
+
} else debug("css handle: %s", file);
|
|
1306
|
+
return { result: source };
|
|
1307
|
+
}
|
|
1308
|
+
//#endregion
|
|
1309
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.ts
|
|
1310
|
+
async function processWebpackGeneratedCssAsset(element, context) {
|
|
1311
|
+
const { ConcatSource, assetHashByChunk, compilation, compilerOptions, configuredCssEntryFiles, configuredMainCssEntryFiles, createRuntimeSetHash, cssSourceTraceSignature, cssSources, cssTaskFactories, debug, enqueueTask, finalizeCssAssetSource, finalizeTracedCss, generatedCssSources, generatorRuntimeSet, getCssHandlerOptions, getCssUserHandlerOptions, getGeneratorRuntimeSet, hasConfiguredTailwindV4SourceRoots, isSameWebpackSourceScope, isWebGeneratorTarget, rememberProcessCacheKey, resolveWebpackCssSourceFile, runtimeAffectingSourceHash, runtimeState, transformRuntimeSet, updateAssetIfChanged, watchMode, webpackSourceCandidateValueSignature, webpackSourceCandidates } = context;
|
|
1312
|
+
const [file, originalSource] = element;
|
|
1313
|
+
const currentRawSource = originalSource.source().toString();
|
|
1314
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1315
|
+
const cacheKey = file;
|
|
1316
|
+
const hashKey = `${file}:asset`;
|
|
1317
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1318
|
+
const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
|
|
1319
|
+
const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
|
|
1320
|
+
const cssSourceHash = (() => {
|
|
1321
|
+
const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
|
|
1322
|
+
const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
|
|
1323
|
+
const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
|
|
1324
|
+
if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
|
|
1325
|
+
return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
|
|
1326
|
+
})();
|
|
1327
|
+
const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
|
|
1328
|
+
await enqueueTask(async () => {
|
|
1329
|
+
await processCachedTask({
|
|
1330
|
+
cache: compilerOptions.cache,
|
|
1331
|
+
cacheKey,
|
|
1332
|
+
hashKey,
|
|
1333
|
+
rawSource: currentRawSource,
|
|
1334
|
+
hash: runtimeAwareHash,
|
|
1335
|
+
applyResult(source, { cacheHit }) {
|
|
1336
|
+
updateAssetIfChanged(file, source, {
|
|
1337
|
+
compare: !cacheHit,
|
|
1338
|
+
notifyUpdate: !cacheHit
|
|
1339
|
+
});
|
|
1340
|
+
},
|
|
1341
|
+
onCacheHit() {
|
|
1342
|
+
debug("css cache hit: %s", file);
|
|
1343
|
+
},
|
|
1344
|
+
transform: async () => {
|
|
1345
|
+
await runtimeState.readyPromise;
|
|
1346
|
+
const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
|
|
1347
|
+
const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
|
|
1348
|
+
if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
|
|
1349
|
+
const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
|
|
1350
|
+
const sourceCss = sourceFile ? cssSources.get(path.resolve(sourceFile))?.css : void 0;
|
|
1351
|
+
const isConfiguredCssSource = sourceFile !== void 0 && configuredCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile));
|
|
1352
|
+
const isConfiguredMainCssSource = sourceFile !== void 0 && configuredMainCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile));
|
|
1353
|
+
const sourceCssHasTailwindRoot = sourceCss !== void 0 && hasTailwindRootDirectives(sourceCss, { importFallback: true });
|
|
1354
|
+
const shouldPreserveExistingPreflight = cssHandlerOptions.isMainChunk || !isConfiguredMainCssSource && (isConfiguredCssSource || sourceCssHasTailwindRoot);
|
|
1355
|
+
const loaderGeneratedCss = sourceFile ? generatedCssSources.get(path.resolve(sourceFile)) : void 0;
|
|
1356
|
+
const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
1357
|
+
const explicitTailwindV4SourceCandidates = shouldRegenerateExplicitTailwindV4CssSource && sourceCss && sourceFile && webpackSourceCandidates?.getSourceCandidatesForEntries ? await resolveTailwindV4EntriesFromCssCached(sourceCss, path.dirname(sourceFile)).then((resolved) => resolved?.entries ? webpackSourceCandidates.getSourceCandidatesForEntries(resolved.entries) : void 0) : void 0;
|
|
1358
|
+
if (loaderGeneratedCss && shouldConsumeWebpackLoaderGeneratedCss({
|
|
1359
|
+
allowMarkerlessRegistryMatch: configuredCssEntryFiles.length === 1,
|
|
1360
|
+
hasBundlerGeneratedCssMarker: hasBundlerGeneratedCssMarker(currentRawSource),
|
|
1361
|
+
loaderGeneratedClassSet: loaderGeneratedCss.classSet,
|
|
1362
|
+
sourceCandidates: explicitTailwindV4SourceCandidates,
|
|
1363
|
+
shouldRegenerateExplicitTailwindV4CssSource,
|
|
1364
|
+
watchMode
|
|
1365
|
+
})) {
|
|
1366
|
+
for (const className of loaderGeneratedCss.classSet) {
|
|
1367
|
+
generatorRuntimeSet.add(className);
|
|
1368
|
+
transformRuntimeSet.add(className);
|
|
1369
|
+
}
|
|
1370
|
+
for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
|
|
1371
|
+
const currentRawSourceWithoutBundlerMarkers = stripBundlerGeneratedCssMarkers(currentRawSource);
|
|
1372
|
+
const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
|
|
1373
|
+
const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
|
|
1374
|
+
const loaderGeneratedCssWithoutMarkers = stripBundlerGeneratedCssMarkers(loaderGeneratedCss.css);
|
|
1375
|
+
const currentAssetUserCssWithoutMarkers = currentAssetUserCss === void 0 ? "" : stripBundlerGeneratedCssMarkers(currentAssetUserCss);
|
|
1376
|
+
const currentAssetMissingUserCss = !(currentAssetUserCssWithoutMarkers.trim().length > 0 && !isCommentOnlyCss(currentAssetUserCssWithoutMarkers)) ? "" : filterExistingCssRules(currentAssetUserCssWithoutMarkers, loaderGeneratedCssWithoutMarkers);
|
|
1377
|
+
if (isConfiguredMainCssSource && !cssHandlerOptions.isMainChunk) {
|
|
1378
|
+
debug("css skip duplicate webpack loader main generation: %s <- %s", file, sourceFile);
|
|
1379
|
+
const userCss = currentAssetMissingUserCss.trim().length === 0 || isCommentOnlyCss(currentAssetMissingUserCss) ? "" : finalizeCssAssetSource(currentAssetMissingUserCss, {
|
|
1380
|
+
cssPreflight: false,
|
|
1381
|
+
generatedCss: false
|
|
1382
|
+
});
|
|
1383
|
+
return { result: new ConcatSource(finalizeTracedCss(userCss, cssHandlerOptions)) };
|
|
1384
|
+
}
|
|
1385
|
+
const mergedLoaderCss = currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
|
|
1386
|
+
css: currentAssetUserCss === void 0 ? loaderGeneratedCss.css : currentAssetHasProcessedUrl ? removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : filterExistingCssRules(currentAssetUserCss, loaderGeneratedCss.css),
|
|
1387
|
+
processed: true
|
|
1388
|
+
}, currentAssetUserCss === void 0 ? void 0 : {
|
|
1389
|
+
css: currentAssetUserCss,
|
|
1390
|
+
processed: true
|
|
1391
|
+
}).css;
|
|
1392
|
+
const handledLoaderCss = isWebGeneratorTarget ? mergedLoaderCss : (await compilerOptions.styleHandler(mergedLoaderCss, cssHandlerOptions)).css;
|
|
1393
|
+
const finalizedLoaderCss = finalizeCssAssetSource(handledLoaderCss, {
|
|
1394
|
+
cssPreflight: cssHandlerOptions.isMainChunk,
|
|
1395
|
+
generatedCss: true,
|
|
1396
|
+
preserveExistingPreflight: shouldPreserveExistingPreflight
|
|
1397
|
+
});
|
|
1398
|
+
const loaderSourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[currentAssetUserCss === void 0 ? void 0 : {
|
|
1399
|
+
css: currentAssetUserCss,
|
|
1400
|
+
processed: true
|
|
1401
|
+
}, sourceCss === void 0 ? void 0 : {
|
|
1402
|
+
css: sourceCss,
|
|
1403
|
+
processed: false
|
|
1404
|
+
}].map((source) => {
|
|
1405
|
+
if (source === void 0) return;
|
|
1406
|
+
return {
|
|
1407
|
+
css: collectWebpackBareSelectorUserCss(source.css),
|
|
1408
|
+
processed: source.processed
|
|
1409
|
+
};
|
|
1410
|
+
}));
|
|
1411
|
+
const handledLoaderSourceBareUserCss = loaderSourceBareUserCss === void 0 ? "" : loaderSourceBareUserCss.processed ? loaderSourceBareUserCss.css : (await compilerOptions.styleHandler(loaderSourceBareUserCss.css, cssHandlerOptions)).css;
|
|
1412
|
+
const finalizedLoaderSourceBareUserCss = handledLoaderSourceBareUserCss.trim().length === 0 ? "" : finalizeCssAssetSource(handledLoaderSourceBareUserCss, {
|
|
1413
|
+
cssPreflight: false,
|
|
1414
|
+
generatedCss: false
|
|
1415
|
+
});
|
|
1416
|
+
const missingLoaderSourceBareUserCss = finalizedLoaderSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(finalizedLoaderCss, finalizedLoaderSourceBareUserCss);
|
|
1417
|
+
const css = finalizeTracedCss(missingLoaderSourceBareUserCss.trim().length === 0 ? finalizedLoaderCss : createWebpackGeneratorUserCssSourceAppend({
|
|
1418
|
+
css: finalizedLoaderCss,
|
|
1419
|
+
processed: true
|
|
1420
|
+
}, {
|
|
1421
|
+
css: missingLoaderSourceBareUserCss,
|
|
1422
|
+
processed: true
|
|
1423
|
+
}).css, cssHandlerOptions, { finalized: true });
|
|
1424
|
+
debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
|
|
1425
|
+
return { result: new ConcatSource(css) };
|
|
1426
|
+
}
|
|
1427
|
+
const sourceCssProcessed = sourceFile ? cssSources.get(path.resolve(sourceFile))?.processed === true : false;
|
|
1428
|
+
const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
|
|
1429
|
+
...source,
|
|
1430
|
+
file: registeredSourceFile
|
|
1431
|
+
})), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
|
|
1432
|
+
const currentAssetLooksGenerated = hasTailwindGeneratedCss(currentRawSource) || hasTailwindGeneratedCssMarkers(currentRawSource);
|
|
1433
|
+
const currentAssetHasBundlerGeneratedMarker = hasBundlerGeneratedCssMarker(currentRawSource);
|
|
1434
|
+
const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
|
|
1435
|
+
if (sourceFile === void 0 && currentAssetHasBundlerGeneratedMarker && (currentAssetUserCssSource.trim().length === 0 || isCommentOnlyCss(currentAssetUserCssSource))) return { result: new ConcatSource(finalizeTracedCss("", cssHandlerOptions)) };
|
|
1436
|
+
const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
|
|
1437
|
+
const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
|
|
1438
|
+
const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (hasTailwindRootDirectives(sourceCss, { importFallback: true }) || hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || hasTailwindApplyDirective(sourceCss));
|
|
1439
|
+
const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
|
|
1440
|
+
const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
|
|
1441
|
+
currentAssetHasUserCss,
|
|
1442
|
+
currentAssetLooksGenerated,
|
|
1443
|
+
currentAssetUserCssSource,
|
|
1444
|
+
shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
|
|
1445
|
+
currentAssetHasBundlerGeneratedMarker,
|
|
1446
|
+
currentAssetHasUserCss,
|
|
1447
|
+
currentAssetLooksGenerated,
|
|
1448
|
+
registeredUserRawSource,
|
|
1449
|
+
shouldPreserveGeneratedWebAssetUserCss,
|
|
1450
|
+
sourceCssProcessed
|
|
1451
|
+
}),
|
|
1452
|
+
sourceCssProcessed
|
|
1453
|
+
}), registeredUserRawSource);
|
|
1454
|
+
if (isPureLocalCssImportWrapper(currentRawSource)) return { result: new ConcatSource(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
|
|
1455
|
+
const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
|
|
1456
|
+
const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
1457
|
+
const currentAssetHasTailwindDirectives = hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || hasTailwindApplyDirective(generatorRawSource);
|
|
1458
|
+
const shouldForceTailwindV4Generation = hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 && sourceFile !== void 0 || currentAssetHasTailwindDirectives || hasExplicitTailwindV4SourceCss);
|
|
1459
|
+
const shouldSkipUnmatchedMainCssGeneration = !isWebGeneratorTarget && cssHandlerOptions.isMainChunk && sourceFile === void 0 && configuredMainCssEntryFiles.length > 0 && !currentAssetHasTailwindDirectives;
|
|
1460
|
+
const shouldSkipPlainNonMainCssGeneration = !cssHandlerOptions.isMainChunk && sourceCss !== void 0 && !hasExplicitSourceCssForCurrentAsset && !hasExplicitTailwindV4SourceCss && !currentAssetHasTailwindDirectives;
|
|
1461
|
+
const shouldMergeFallbackGeneratorRuntime = cssHandlerOptions.isMainChunk || currentAssetHasTailwindDirectives || hasExplicitSourceCssForCurrentAsset;
|
|
1462
|
+
const scopedFallbackGeneratorRuntimeSet = hasExplicitTailwindV4SourceCss || !shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet;
|
|
1463
|
+
const resolvedScopedGeneratorRuntimeSet = await createScopedGeneratorRuntime({
|
|
1464
|
+
cssHandlerOptions,
|
|
1465
|
+
fallbackRuntime: scopedFallbackGeneratorRuntimeSet,
|
|
1466
|
+
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
1467
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1468
|
+
outputFile: file,
|
|
1469
|
+
rawSource: sourceFile ? cssSources.get(path.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
|
|
1470
|
+
shouldExcludeSubpackageSourceCandidates: () => false,
|
|
1471
|
+
sourceFile: sourceFile ?? file,
|
|
1472
|
+
scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
|
|
1473
|
+
});
|
|
1474
|
+
const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== scopedFallbackGeneratorRuntimeSet && shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
|
|
1475
|
+
const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
|
|
1476
|
+
const scopedGeneratorCompilerOptions = scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, { disableUnmatchedCssEntries: !isWebGeneratorTarget && cssHandlerOptions.isMainChunk });
|
|
1477
|
+
const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
|
|
1478
|
+
...cssHandlerOptions,
|
|
1479
|
+
sourceOptions: {
|
|
1480
|
+
...cssHandlerOptions.sourceOptions,
|
|
1481
|
+
cssSources: generatorCssSources
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
const generatorOptions = {
|
|
1485
|
+
opts: scopedGeneratorCompilerOptions,
|
|
1486
|
+
runtimeState,
|
|
1487
|
+
runtime: scopedGeneratorRuntimeSet,
|
|
1488
|
+
rawSource: generatorRawSource,
|
|
1489
|
+
forceGenerator: shouldForceTailwindV4Generation,
|
|
1490
|
+
...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
|
|
1491
|
+
...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
|
|
1492
|
+
...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
|
|
1493
|
+
file,
|
|
1494
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
1495
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
1496
|
+
frameworkPostcssOwner: compilerOptions,
|
|
1497
|
+
frameworkPostcssStage: "complete",
|
|
1498
|
+
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
1499
|
+
sourceCandidates: scopedGeneratorRuntimeSet,
|
|
1500
|
+
restoreLocalCssImports: false,
|
|
1501
|
+
styleHandler: compilerOptions.styleHandler,
|
|
1502
|
+
debug
|
|
1503
|
+
};
|
|
1504
|
+
let generated;
|
|
1505
|
+
if (!shouldSkipUnmatchedMainCssGeneration && !shouldSkipPlainNonMainCssGeneration) try {
|
|
1506
|
+
generated = await generateTailwindV4Css({
|
|
1507
|
+
...generatorOptions,
|
|
1508
|
+
outputFile: file
|
|
1509
|
+
});
|
|
1510
|
+
} catch (error) {
|
|
1511
|
+
if (!shouldFallbackToWebpackUserCssOnGeneratorError({
|
|
1512
|
+
configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
|
|
1513
|
+
generatorRawSource,
|
|
1514
|
+
hasExplicitTailwindV4SourceCss
|
|
1515
|
+
})) throw error;
|
|
1516
|
+
debug("css generator skipped for plain webpack css asset: %s %O", file, error);
|
|
1517
|
+
generated = void 0;
|
|
1518
|
+
}
|
|
1519
|
+
else debug("css generator skipped for plain webpack css asset: %s", file);
|
|
1520
|
+
return finalizeWebpackGeneratedCssResult({
|
|
1521
|
+
ConcatSource,
|
|
1522
|
+
compilerOptions,
|
|
1523
|
+
cssHandlerOptions,
|
|
1524
|
+
currentRawSource,
|
|
1525
|
+
debug,
|
|
1526
|
+
file,
|
|
1527
|
+
finalizeCssAssetSource,
|
|
1528
|
+
finalizeTracedCss,
|
|
1529
|
+
generated,
|
|
1530
|
+
generatorRawSource,
|
|
1531
|
+
generatorRuntimeSet,
|
|
1532
|
+
isWebGeneratorTarget,
|
|
1533
|
+
runtimeState,
|
|
1534
|
+
shouldPreserveExistingPreflight,
|
|
1535
|
+
sourceCss,
|
|
1536
|
+
sourceCssProcessed,
|
|
1537
|
+
userRawSource
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
}, cssTaskFactories, "tasks.css");
|
|
1542
|
+
}
|
|
1543
|
+
//#endregion
|
|
1167
1544
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
|
|
1168
1545
|
function createChangedByType() {
|
|
1169
1546
|
return {
|
|
@@ -1279,6 +1656,112 @@ function createWebpackAssetUpdater(options) {
|
|
|
1279
1656
|
};
|
|
1280
1657
|
}
|
|
1281
1658
|
//#endregion
|
|
1659
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.ts
|
|
1660
|
+
async function enqueueWebpackHtmlAndJsTasks(context) {
|
|
1661
|
+
const { ConcatSource, applyWebpackLinkedJsResults, assetHashByChunk, compilation, compilerOptions, debug, defaultTemplateHandlerOptions, enqueueTask, groupedEntries, isWebGeneratorTarget, jsAssets, moduleGraphOptions, outputDir, rememberProcessCacheKey, rememberTransformedRuntimeCandidates, runtimeState, transformRuntimeSet, updateAssetIfChanged } = context;
|
|
1662
|
+
const htmlTaskFactories = [];
|
|
1663
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
|
|
1664
|
+
const [file, originalSource] = element;
|
|
1665
|
+
let rawSource;
|
|
1666
|
+
const readRawSource = () => {
|
|
1667
|
+
rawSource ?? (rawSource = originalSource.source().toString());
|
|
1668
|
+
return rawSource;
|
|
1669
|
+
};
|
|
1670
|
+
const cacheKey = file;
|
|
1671
|
+
const hashKey = `${file}:asset`;
|
|
1672
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1673
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1674
|
+
await enqueueTask(async () => {
|
|
1675
|
+
await processCachedTask({
|
|
1676
|
+
cache: compilerOptions.cache,
|
|
1677
|
+
cacheKey,
|
|
1678
|
+
hashKey,
|
|
1679
|
+
rawSource: chunkHash === void 0 ? readRawSource() : void 0,
|
|
1680
|
+
hash: chunkHash,
|
|
1681
|
+
applyResult(source, { cacheHit }) {
|
|
1682
|
+
updateAssetIfChanged(file, source, {
|
|
1683
|
+
compare: !cacheHit,
|
|
1684
|
+
notifyUpdate: !cacheHit
|
|
1685
|
+
});
|
|
1686
|
+
},
|
|
1687
|
+
onCacheHit() {
|
|
1688
|
+
debug("html cache hit: %s", file);
|
|
1689
|
+
},
|
|
1690
|
+
transform: async () => {
|
|
1691
|
+
const wxml = await compilerOptions.templateHandler(readRawSource(), defaultTemplateHandlerOptions);
|
|
1692
|
+
const source = new ConcatSource(wxml);
|
|
1693
|
+
debug("html handle: %s", file);
|
|
1694
|
+
return { result: source };
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
}, htmlTaskFactories, "tasks.html");
|
|
1698
|
+
}
|
|
1699
|
+
const jsTaskFactories = [];
|
|
1700
|
+
const enqueueJsTask = async (factory) => {
|
|
1701
|
+
await enqueueTask(factory, jsTaskFactories, "tasks.js");
|
|
1702
|
+
};
|
|
1703
|
+
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
1704
|
+
const cacheKey = getCacheKey(file);
|
|
1705
|
+
const asset = compilation.getAsset(file);
|
|
1706
|
+
if (!asset) continue;
|
|
1707
|
+
const hashKey = `${file}:asset`;
|
|
1708
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1709
|
+
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
1710
|
+
const initialSource = asset.source.source();
|
|
1711
|
+
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
1712
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1713
|
+
await enqueueJsTask(async () => {
|
|
1714
|
+
await processCachedTask({
|
|
1715
|
+
cache: compilerOptions.cache,
|
|
1716
|
+
cacheKey,
|
|
1717
|
+
hashKey,
|
|
1718
|
+
rawSource: chunkHash === void 0 ? initialRawSource : void 0,
|
|
1719
|
+
hash: chunkHash,
|
|
1720
|
+
applyResult(source, { cacheHit }) {
|
|
1721
|
+
if (updateAssetIfChanged(file, source, {
|
|
1722
|
+
compare: !cacheHit,
|
|
1723
|
+
notifyUpdate: !cacheHit
|
|
1724
|
+
})) rememberTransformedRuntimeCandidates(source);
|
|
1725
|
+
},
|
|
1726
|
+
onCacheHit() {
|
|
1727
|
+
debug("js cache hit: %s", file);
|
|
1728
|
+
},
|
|
1729
|
+
transform: async () => {
|
|
1730
|
+
const currentSourceValue = compilation.getAsset(file)?.source.source();
|
|
1731
|
+
const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
|
|
1732
|
+
const handlerOptions = {
|
|
1733
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1734
|
+
generateMap: false,
|
|
1735
|
+
filename: absoluteFile,
|
|
1736
|
+
moduleGraph: moduleGraphOptions,
|
|
1737
|
+
babelParserOptions: { sourceFilename: absoluteFile }
|
|
1738
|
+
};
|
|
1739
|
+
if (shouldSkipJsTransform(currentSource, {
|
|
1740
|
+
...handlerOptions,
|
|
1741
|
+
classNameSet: transformRuntimeSet
|
|
1742
|
+
})) return { result: new ConcatSource(currentSource) };
|
|
1743
|
+
const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
|
|
1744
|
+
const source = new ConcatSource(code);
|
|
1745
|
+
debug("js handle: %s", file);
|
|
1746
|
+
applyWebpackLinkedJsResults({
|
|
1747
|
+
ConcatSource,
|
|
1748
|
+
compilation,
|
|
1749
|
+
compilerOptions,
|
|
1750
|
+
debug,
|
|
1751
|
+
jsAssets,
|
|
1752
|
+
linked
|
|
1753
|
+
});
|
|
1754
|
+
return { result: source };
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
return {
|
|
1760
|
+
htmlTaskFactories,
|
|
1761
|
+
jsTaskFactories
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
//#endregion
|
|
1282
1765
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.ts
|
|
1283
1766
|
function createWebpackJsAssetModuleGraph(options) {
|
|
1284
1767
|
const jsAssets = /* @__PURE__ */ new Map();
|
|
@@ -1323,6 +1806,144 @@ function applyWebpackLinkedJsResults(options) {
|
|
|
1323
1806
|
}
|
|
1324
1807
|
}
|
|
1325
1808
|
//#endregion
|
|
1809
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.ts
|
|
1810
|
+
async function processWebpackProcessedCssAsset(element, context) {
|
|
1811
|
+
const { ConcatSource, assetHashByChunk, compilerOptions, configuredMainCssEntryFiles, createRuntimeSetHash, cssSourceTraceSignature, cssSources, cssTaskFactories, debug, enqueueTask, finalizeCssAssetSource, finalizeTracedCss, generatedCssSources, getCssHandlerOptions, getGeneratorRuntimeSet, hasConfiguredTailwindV4SourceRoots, isKnownWebpackProcessedCssAsset, isWebGeneratorTarget, isWebpackProcessedCssAsset, processedCssAssetSkipDecisionCache, rememberProcessCacheKey, runtimeAffectingSourceHash, updateAssetIfChanged, watchMode, webpackSourceCandidateSet, webpackSourceCandidateValueSignature, webpackSourceCandidates } = context;
|
|
1812
|
+
const [file, originalSource] = element;
|
|
1813
|
+
let rawSource;
|
|
1814
|
+
const readRawSource = () => {
|
|
1815
|
+
rawSource ?? (rawSource = originalSource.source().toString());
|
|
1816
|
+
return rawSource;
|
|
1817
|
+
};
|
|
1818
|
+
const chunkHash = assetHashByChunk.get(file);
|
|
1819
|
+
const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file, readRawSource());
|
|
1820
|
+
const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
|
|
1821
|
+
const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
|
|
1822
|
+
const processedSourceCss = processedSourceFile ? cssSources.get(path.resolve(processedSourceFile))?.css : void 0;
|
|
1823
|
+
const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
|
|
1824
|
+
const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
|
|
1825
|
+
const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(path.resolve(processedSourceFile)) : void 0;
|
|
1826
|
+
const processedAssetSourceHash = watchMode && isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk ? compilerOptions.cache.computeHash(readRawSource()) : chunkHash === void 0 ? processedCssAssetKnown ? "webpack-css-asset:known" : compilerOptions.cache.computeHash(readRawSource()) : "webpack-css-asset:chunk";
|
|
1827
|
+
const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
|
|
1828
|
+
let currentProcessedRawSource;
|
|
1829
|
+
let hasGeneratedCssMarker = false;
|
|
1830
|
+
let hasTailwindGeneratedAssetCss = false;
|
|
1831
|
+
const readCurrentProcessedRawSource = () => {
|
|
1832
|
+
currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
|
|
1833
|
+
return currentProcessedRawSource;
|
|
1834
|
+
};
|
|
1835
|
+
const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
|
|
1836
|
+
const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
|
|
1837
|
+
if (cachedSkipProcessedCssAsset !== void 0) {
|
|
1838
|
+
hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
|
|
1839
|
+
hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
|
|
1840
|
+
} else {
|
|
1841
|
+
const source = readCurrentProcessedRawSource();
|
|
1842
|
+
hasGeneratedCssMarker = hasBundlerGeneratedCssMarker(source);
|
|
1843
|
+
hasTailwindGeneratedAssetCss = hasTailwindGeneratedCss(source) || hasTailwindGeneratedCssMarkers(source);
|
|
1844
|
+
}
|
|
1845
|
+
const hasProcessedAssetTailwindDirectives = () => {
|
|
1846
|
+
const source = readCurrentProcessedRawSource();
|
|
1847
|
+
return hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1848
|
+
};
|
|
1849
|
+
const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
|
|
1850
|
+
const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
|
|
1851
|
+
...source,
|
|
1852
|
+
file: sourceFile
|
|
1853
|
+
})), readCurrentProcessedRawSource()) !== void 0;
|
|
1854
|
+
const hasProcessedLoaderGeneratedUserCss = cachedSkipProcessedCssAsset === void 0 && processedLoaderGeneratedCss !== void 0 && hasAdditionalWebpackAssetUserCssMarkers(processedLoaderGeneratedCss.css, readCurrentProcessedRawSource());
|
|
1855
|
+
const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
|
|
1856
|
+
const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1857
|
+
const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && !hasProcessedLoaderGeneratedUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1858
|
+
const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
|
|
1859
|
+
if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
|
|
1860
|
+
if (shouldSkipProcessedCssAsset) {
|
|
1861
|
+
const hashKey = `${file}:asset`;
|
|
1862
|
+
const sourceHash = processedAssetSourceHash;
|
|
1863
|
+
rememberProcessCacheKey(file, hashKey);
|
|
1864
|
+
await enqueueTask(async () => {
|
|
1865
|
+
await processCachedTask({
|
|
1866
|
+
cache: compilerOptions.cache,
|
|
1867
|
+
cacheKey: file,
|
|
1868
|
+
hashKey,
|
|
1869
|
+
rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
|
|
1870
|
+
hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
|
|
1871
|
+
applyResult(source, { cacheHit }) {
|
|
1872
|
+
updateAssetIfChanged(file, source, {
|
|
1873
|
+
compare: !cacheHit,
|
|
1874
|
+
notifyUpdate: !cacheHit
|
|
1875
|
+
});
|
|
1876
|
+
},
|
|
1877
|
+
onCacheHit() {
|
|
1878
|
+
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
1879
|
+
},
|
|
1880
|
+
transform: async () => {
|
|
1881
|
+
const source = readCurrentProcessedRawSource();
|
|
1882
|
+
const missingProcessedLoaderGeneratedCss = isWebGeneratorTarget && processedLoaderGeneratedCss ? filterExistingCssRules(source, stripBundlerGeneratedCssMarkers(processedLoaderGeneratedCss.css)) : "";
|
|
1883
|
+
const sourceWithLoaderGeneratedCss = missingProcessedLoaderGeneratedCss.trim().length === 0 ? source : createWebpackGeneratorUserCssSourceAppend({
|
|
1884
|
+
css: source,
|
|
1885
|
+
processed: true
|
|
1886
|
+
}, {
|
|
1887
|
+
css: missingProcessedLoaderGeneratedCss,
|
|
1888
|
+
processed: true
|
|
1889
|
+
}).css;
|
|
1890
|
+
const processedBareSelectorSourceCss = processedSourceCss ?? (hasTailwindGeneratedAssetCss ? removeWebpackTailwindGeneratedAssetCss(sourceWithLoaderGeneratedCss) : void 0);
|
|
1891
|
+
const handledCss = hasTailwindGeneratedAssetCss && (!hasGeneratedCssMarker || !isWebGeneratorTarget && hasDeferredWebpackGeneratedCss(source, [...generatedCssSources.values()].map((item) => item.classSet))) ? isWebGeneratorTarget ? sourceWithLoaderGeneratedCss : (await compilerOptions.styleHandler(sourceWithLoaderGeneratedCss, cssHandlerOptionsForProcessedAsset)).css : sourceWithLoaderGeneratedCss;
|
|
1892
|
+
const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(handledCss, {
|
|
1893
|
+
cssPreflight: cssHandlerOptionsForProcessedAsset.isMainChunk,
|
|
1894
|
+
generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss
|
|
1895
|
+
}));
|
|
1896
|
+
const processedSourceBareUserCss = isWebGeneratorTarget || processedBareSelectorSourceCss === void 0 ? void 0 : createWebpackGeneratorUserCssSourceAppend({
|
|
1897
|
+
css: collectWebpackBareSelectorUserCss(processedBareSelectorSourceCss),
|
|
1898
|
+
processed: false
|
|
1899
|
+
});
|
|
1900
|
+
const finalizedProcessedSourceBareUserCss = processedSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(processedSourceBareUserCss.css, {
|
|
1901
|
+
cssPreflight: false,
|
|
1902
|
+
generatedCss: false
|
|
1903
|
+
});
|
|
1904
|
+
const missingProcessedSourceBareUserCss = finalizedProcessedSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(nextCss, finalizedProcessedSourceBareUserCss);
|
|
1905
|
+
const css = missingProcessedSourceBareUserCss.trim().length === 0 ? nextCss : createWebpackGeneratorUserCssSourceAppend({
|
|
1906
|
+
css: nextCss,
|
|
1907
|
+
processed: true
|
|
1908
|
+
}, {
|
|
1909
|
+
css: missingProcessedSourceBareUserCss,
|
|
1910
|
+
processed: true
|
|
1911
|
+
}).css;
|
|
1912
|
+
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
1913
|
+
return { result: new ConcatSource(finalizeTracedCss(css, cssHandlerOptionsForProcessedAsset, { finalized: true })) };
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
}, cssTaskFactories, "tasks.css");
|
|
1917
|
+
return true;
|
|
1918
|
+
}
|
|
1919
|
+
const currentRawSource = readRawSource();
|
|
1920
|
+
if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
|
|
1921
|
+
const hashKey = `${file}:asset`;
|
|
1922
|
+
rememberProcessCacheKey(file, hashKey);
|
|
1923
|
+
await enqueueTask(async () => {
|
|
1924
|
+
await processCachedTask({
|
|
1925
|
+
cache: compilerOptions.cache,
|
|
1926
|
+
cacheKey: file,
|
|
1927
|
+
hashKey,
|
|
1928
|
+
rawSource: currentRawSource,
|
|
1929
|
+
hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
|
|
1930
|
+
applyResult(source, { cacheHit }) {
|
|
1931
|
+
updateAssetIfChanged(file, source, {
|
|
1932
|
+
compare: !cacheHit,
|
|
1933
|
+
notifyUpdate: !cacheHit
|
|
1934
|
+
});
|
|
1935
|
+
},
|
|
1936
|
+
onCacheHit() {
|
|
1937
|
+
debug("css-loader runtime cache hit: %s", file);
|
|
1938
|
+
},
|
|
1939
|
+
transform: async () => ({ result: new ConcatSource(currentRawSource) })
|
|
1940
|
+
});
|
|
1941
|
+
}, cssTaskFactories, "tasks.css");
|
|
1942
|
+
return true;
|
|
1943
|
+
}
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1946
|
+
//#endregion
|
|
1326
1947
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.ts
|
|
1327
1948
|
const WEBPACK_SOURCE_CANDIDATE_SCAN_CACHE_MAX = 2;
|
|
1328
1949
|
function trimScanCache(cache) {
|
|
@@ -1555,6 +2176,11 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1555
2176
|
debug("start");
|
|
1556
2177
|
await runtimeState.readyPromise;
|
|
1557
2178
|
const hmrTimingStartedAt = performance.now();
|
|
2179
|
+
const timingDetails = {};
|
|
2180
|
+
const recordTimingDetail = (name, startedAt) => {
|
|
2181
|
+
timingDetails[name] = (timingDetails[name] ?? 0) + Math.max(0, performance.now() - startedAt);
|
|
2182
|
+
};
|
|
2183
|
+
const setupStartedAt = performance.now();
|
|
1558
2184
|
for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
1559
2185
|
const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
|
|
1560
2186
|
const { updateAssetIfChanged } = createWebpackAssetUpdater({
|
|
@@ -1576,6 +2202,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1576
2202
|
appType,
|
|
1577
2203
|
cssMatcher: compilerOptions.cssMatcher
|
|
1578
2204
|
}));
|
|
2205
|
+
const directCssAssetResources = createWebpackDirectCssAssetResourceMap(compilation.chunks, compilation.chunkGraph, compilerOptions.cssMatcher, (resource, issuer) => resolveWebpackCssAssetModuleResource(resource, issuer, {
|
|
2206
|
+
appType,
|
|
2207
|
+
cssMatcher: compilerOptions.cssMatcher
|
|
2208
|
+
}));
|
|
1579
2209
|
const watchChangedFiles = new Set([...getWatchChangedFiles?.() ?? []].map((file) => path.resolve(file)));
|
|
1580
2210
|
const taskConcurrency = watchMode ? resolveTaskConcurrency(1) : void 0;
|
|
1581
2211
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -1596,6 +2226,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1596
2226
|
compilation,
|
|
1597
2227
|
cssAssetFiles: entries.map(([file]) => file),
|
|
1598
2228
|
cssAssetResources,
|
|
2229
|
+
directCssAssetResources,
|
|
1599
2230
|
cssHandlerOptionsCache,
|
|
1600
2231
|
cssSources,
|
|
1601
2232
|
cssUserHandlerOptionsCache,
|
|
@@ -1606,7 +2237,10 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1606
2237
|
runtimeState
|
|
1607
2238
|
});
|
|
1608
2239
|
const finalizeCssAssetSource = (source, options = {}) => finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options);
|
|
1609
|
-
const
|
|
2240
|
+
const shouldRefreshWebpackSourceCandidates = !isWebGeneratorTarget && groupedEntries.css.length > 0 || cssSources.size > 0 || generatedCssSources.size > 0 || isCssSourceTraceEnabled(compilerOptions);
|
|
2241
|
+
recordTimingDetail("setup", setupStartedAt);
|
|
2242
|
+
const sourceCandidatesStartedAt = performance.now();
|
|
2243
|
+
const webpackSourceCandidates = shouldRefreshWebpackSourceCandidates ? await refreshWebpackSourceCandidates({
|
|
1610
2244
|
compilerOptions,
|
|
1611
2245
|
debug,
|
|
1612
2246
|
outputDir,
|
|
@@ -1616,6 +2250,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1616
2250
|
watchMode
|
|
1617
2251
|
}) : void 0;
|
|
1618
2252
|
const webpackSourceCandidateValueSignature = webpackSourceCandidates ? createCandidateSignature(webpackSourceCandidates.getSourceCandidatesForEntries(void 0)) : "source-candidates:0";
|
|
2253
|
+
recordTimingDetail("sourceCandidates", sourceCandidatesStartedAt);
|
|
1619
2254
|
const cssSourceTraceTokenSources = createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates);
|
|
1620
2255
|
const cssSourceTraceSignature = createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
|
|
1621
2256
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
@@ -1629,6 +2264,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1629
2264
|
isWebGeneratorTarget
|
|
1630
2265
|
});
|
|
1631
2266
|
const hasRuntimeTransformAssets = Boolean(!isWebGeneratorTarget && ((groupedEntries.html?.length ?? 0) > 0 || (groupedEntries.js?.length ?? 0) > 0));
|
|
2267
|
+
const runtimeStartedAt = performance.now();
|
|
1632
2268
|
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
1633
2269
|
debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.tailwindRuntime.majorVersion ?? "unknown");
|
|
1634
2270
|
let runtimeSet;
|
|
@@ -1666,6 +2302,7 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1666
2302
|
}
|
|
1667
2303
|
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
1668
2304
|
consumeRuntimeRefreshRequirement();
|
|
2305
|
+
recordTimingDetail("runtime", runtimeStartedAt);
|
|
1669
2306
|
const webpackSourceCandidateSet = webpackSourceCandidates?.getSourceCandidatesForEntries(void 0);
|
|
1670
2307
|
const generatorRuntimeSet = new Set(runtimeSet);
|
|
1671
2308
|
addRuntimeTransformCandidates(generatorRuntimeSet, webpackSourceCandidateSet);
|
|
@@ -1720,520 +2357,107 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
1720
2357
|
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntimeSet };
|
|
1721
2358
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtimeSet.size, transformRuntimeSet.size);
|
|
1722
2359
|
const tasks = [];
|
|
1723
|
-
const htmlTaskFactories = [];
|
|
1724
2360
|
const cssTaskFactories = [];
|
|
1725
|
-
const enqueueTask = async (factory, target) => {
|
|
2361
|
+
const enqueueTask = async (factory, target, phase) => {
|
|
2362
|
+
const timedFactory = async () => {
|
|
2363
|
+
const startedAt = performance.now();
|
|
2364
|
+
try {
|
|
2365
|
+
await factory();
|
|
2366
|
+
} finally {
|
|
2367
|
+
recordTimingDetail(phase, startedAt);
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
1726
2370
|
if (watchMode) {
|
|
1727
|
-
await
|
|
2371
|
+
await timedFactory();
|
|
1728
2372
|
return;
|
|
1729
2373
|
}
|
|
1730
|
-
target.push(
|
|
2374
|
+
target.push(timedFactory);
|
|
1731
2375
|
};
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2376
|
+
const { htmlTaskFactories, jsTaskFactories } = await enqueueWebpackHtmlAndJsTasks({
|
|
2377
|
+
ConcatSource,
|
|
2378
|
+
applyWebpackLinkedJsResults,
|
|
2379
|
+
assetHashByChunk,
|
|
2380
|
+
compilation,
|
|
2381
|
+
compilerOptions,
|
|
2382
|
+
debug,
|
|
2383
|
+
defaultTemplateHandlerOptions,
|
|
2384
|
+
enqueueTask,
|
|
2385
|
+
groupedEntries,
|
|
2386
|
+
isWebGeneratorTarget,
|
|
2387
|
+
jsAssets,
|
|
2388
|
+
moduleGraphOptions,
|
|
2389
|
+
outputDir,
|
|
2390
|
+
rememberProcessCacheKey,
|
|
2391
|
+
rememberTransformedRuntimeCandidates,
|
|
2392
|
+
runtimeState,
|
|
2393
|
+
transformRuntimeSet,
|
|
2394
|
+
updateAssetIfChanged
|
|
2395
|
+
});
|
|
2396
|
+
const cssTaskContext = {
|
|
2397
|
+
ConcatSource,
|
|
2398
|
+
assetHashByChunk,
|
|
2399
|
+
compilation,
|
|
2400
|
+
compilerOptions,
|
|
2401
|
+
configuredCssEntryFiles,
|
|
2402
|
+
configuredMainCssEntryFiles,
|
|
2403
|
+
createRuntimeSetHash,
|
|
2404
|
+
cssSourceTraceSignature,
|
|
2405
|
+
cssSources,
|
|
2406
|
+
cssTaskFactories,
|
|
2407
|
+
debug,
|
|
2408
|
+
enqueueTask,
|
|
2409
|
+
finalizeCssAssetSource,
|
|
2410
|
+
finalizeTracedCss,
|
|
2411
|
+
generatedCssSources,
|
|
2412
|
+
generatorRuntimeSet,
|
|
2413
|
+
getCssHandlerOptions,
|
|
2414
|
+
getCssUserHandlerOptions,
|
|
2415
|
+
getGeneratorRuntimeSet,
|
|
2416
|
+
hasConfiguredTailwindV4SourceRoots,
|
|
2417
|
+
isKnownWebpackProcessedCssAsset,
|
|
2418
|
+
isSameWebpackSourceScope,
|
|
2419
|
+
isWebGeneratorTarget,
|
|
2420
|
+
isWebpackProcessedCssAsset,
|
|
2421
|
+
processedCssAssetSkipDecisionCache,
|
|
2422
|
+
rememberProcessCacheKey,
|
|
2423
|
+
resolveWebpackCssSourceFile,
|
|
2424
|
+
runtimeAffectingSourceHash,
|
|
2425
|
+
runtimeState,
|
|
2426
|
+
transformRuntimeSet,
|
|
2427
|
+
updateAssetIfChanged,
|
|
2428
|
+
watchMode,
|
|
2429
|
+
webpackSourceCandidateSet,
|
|
2430
|
+
webpackSourceCandidateValueSignature,
|
|
2431
|
+
webpackSourceCandidates
|
|
1771
2432
|
};
|
|
1772
|
-
if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
|
|
1773
|
-
const cacheKey = getCacheKey(file);
|
|
1774
|
-
const asset = compilation.getAsset(file);
|
|
1775
|
-
if (!asset) continue;
|
|
1776
|
-
const hashKey = `${file}:asset`;
|
|
1777
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1778
|
-
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
1779
|
-
const initialSource = asset.source.source();
|
|
1780
|
-
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
1781
|
-
const chunkHash = assetHashByChunk.get(file);
|
|
1782
|
-
await enqueueJsTask(async () => {
|
|
1783
|
-
await processCachedTask({
|
|
1784
|
-
cache: compilerOptions.cache,
|
|
1785
|
-
cacheKey,
|
|
1786
|
-
hashKey,
|
|
1787
|
-
rawSource: chunkHash === void 0 ? initialRawSource : void 0,
|
|
1788
|
-
hash: chunkHash,
|
|
1789
|
-
applyResult(source, { cacheHit }) {
|
|
1790
|
-
if (updateAssetIfChanged(file, source, {
|
|
1791
|
-
compare: !cacheHit,
|
|
1792
|
-
notifyUpdate: !cacheHit
|
|
1793
|
-
})) rememberTransformedRuntimeCandidates(source);
|
|
1794
|
-
},
|
|
1795
|
-
onCacheHit() {
|
|
1796
|
-
debug("js cache hit: %s", file);
|
|
1797
|
-
},
|
|
1798
|
-
transform: async () => {
|
|
1799
|
-
const currentSourceValue = compilation.getAsset(file)?.source.source();
|
|
1800
|
-
const currentSource = stringifyOptionalWebpackSourceValue(currentSourceValue);
|
|
1801
|
-
const handlerOptions = {
|
|
1802
|
-
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
1803
|
-
generateMap: false,
|
|
1804
|
-
filename: absoluteFile,
|
|
1805
|
-
moduleGraph: moduleGraphOptions,
|
|
1806
|
-
babelParserOptions: { sourceFilename: absoluteFile }
|
|
1807
|
-
};
|
|
1808
|
-
if (shouldSkipJsTransform(currentSource, {
|
|
1809
|
-
...handlerOptions,
|
|
1810
|
-
classNameSet: transformRuntimeSet
|
|
1811
|
-
})) return { result: new ConcatSource(currentSource) };
|
|
1812
|
-
const { code, linked } = await compilerOptions.jsHandler(currentSource, transformRuntimeSet, handlerOptions);
|
|
1813
|
-
const source = new ConcatSource(code);
|
|
1814
|
-
debug("js handle: %s", file);
|
|
1815
|
-
applyWebpackLinkedJsResults({
|
|
1816
|
-
ConcatSource,
|
|
1817
|
-
compilation,
|
|
1818
|
-
compilerOptions,
|
|
1819
|
-
debug,
|
|
1820
|
-
jsAssets,
|
|
1821
|
-
linked
|
|
1822
|
-
});
|
|
1823
|
-
return { result: source };
|
|
1824
|
-
}
|
|
1825
|
-
});
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
2433
|
for (const element of groupedEntries.css) {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const readRawSource = () => {
|
|
1832
|
-
rawSource ?? (rawSource = originalSource.source().toString());
|
|
1833
|
-
return rawSource;
|
|
1834
|
-
};
|
|
1835
|
-
const chunkHash = assetHashByChunk.get(file);
|
|
1836
|
-
const cssHandlerOptionsForProcessedAsset = getCssHandlerOptions(file, readRawSource());
|
|
1837
|
-
const processedCssAssetMetadata = { isMainCssChunk: cssHandlerOptionsForProcessedAsset.isMainChunk };
|
|
1838
|
-
const processedSourceFile = cssHandlerOptionsForProcessedAsset.sourceOptions?.sourceFile;
|
|
1839
|
-
const processedSourceCss = processedSourceFile ? cssSources.get(path.resolve(processedSourceFile))?.css : void 0;
|
|
1840
|
-
const shouldRegenerateProcessedTailwindV4SourceCss = processedSourceCss !== void 0 && (hasTailwindSourceDirectives(processedSourceCss, { importFallback: true }) || processedSourceCss.includes("@config"));
|
|
1841
|
-
const processedCssAssetKnown = isKnownWebpackProcessedCssAsset?.(file, processedCssAssetMetadata) === true;
|
|
1842
|
-
const processedLoaderGeneratedCss = processedSourceFile ? generatedCssSources.get(path.resolve(processedSourceFile)) : void 0;
|
|
1843
|
-
const processedAssetSourceHash = watchMode && isWebGeneratorTarget && cssHandlerOptionsForProcessedAsset.isMainChunk ? compilerOptions.cache.computeHash(readRawSource()) : chunkHash === void 0 ? processedCssAssetKnown ? "webpack-css-asset:known" : compilerOptions.cache.computeHash(readRawSource()) : "webpack-css-asset:chunk";
|
|
1844
|
-
const processedCssDecisionCacheKey = `${file}:${createRuntimeAwareCssHash(chunkHash, processedAssetSourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`)}`;
|
|
1845
|
-
let currentProcessedRawSource;
|
|
1846
|
-
let hasGeneratedCssMarker = false;
|
|
1847
|
-
let hasTailwindGeneratedAssetCss = false;
|
|
1848
|
-
const readCurrentProcessedRawSource = () => {
|
|
1849
|
-
currentProcessedRawSource ?? (currentProcessedRawSource = readRawSource());
|
|
1850
|
-
return currentProcessedRawSource;
|
|
1851
|
-
};
|
|
1852
|
-
const cachedSkipProcessedCssAsset = processedCssAssetKnown ? processedCssAssetSkipDecisionCache.get(processedCssDecisionCacheKey) : void 0;
|
|
1853
|
-
const shouldRegenerateStaleProcessedWebCssAsset = isWebGeneratorTarget && !processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && webpackSourceCandidateSet !== void 0 && (hasMissingRuntimeCandidates(processedLoaderGeneratedCss?.classSet, webpackSourceCandidateSet) || hasMissingRuntimeCandidates(resolveGeneratedCssRuntimeCandidates(readCurrentProcessedRawSource(), processedLoaderGeneratedCss?.classSet), webpackSourceCandidateSet));
|
|
1854
|
-
if (cachedSkipProcessedCssAsset !== void 0) {
|
|
1855
|
-
hasGeneratedCssMarker = cachedSkipProcessedCssAsset && cssHandlerOptionsForProcessedAsset.isMainChunk;
|
|
1856
|
-
hasTailwindGeneratedAssetCss = hasGeneratedCssMarker;
|
|
1857
|
-
} else {
|
|
1858
|
-
const source = readCurrentProcessedRawSource();
|
|
1859
|
-
hasGeneratedCssMarker = hasBundlerGeneratedCssMarker(source);
|
|
1860
|
-
hasTailwindGeneratedAssetCss = hasTailwindGeneratedCss(source) || hasTailwindGeneratedCssMarkers(source);
|
|
1861
|
-
}
|
|
1862
|
-
const hasProcessedAssetTailwindDirectives = () => {
|
|
1863
|
-
const source = readCurrentProcessedRawSource();
|
|
1864
|
-
return hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1865
|
-
};
|
|
1866
|
-
const shouldForceConfiguredMainCssGeneration = cssHandlerOptionsForProcessedAsset.isMainChunk && hasConfiguredTailwindV4SourceRoots() && !hasGeneratedCssMarker && (configuredMainCssEntryFiles.length > 0 || shouldRegenerateProcessedTailwindV4SourceCss || hasProcessedAssetTailwindDirectives());
|
|
1867
|
-
const hasProcessedMainAssetUserCss = cachedSkipProcessedCssAsset === void 0 && cssHandlerOptionsForProcessedAsset.isMainChunk && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss) && createWebpackUserCssSourceAppend([...cssSources.entries()].map(([sourceFile, source]) => ({
|
|
1868
|
-
...source,
|
|
1869
|
-
file: sourceFile
|
|
1870
|
-
})), readCurrentProcessedRawSource()) !== void 0;
|
|
1871
|
-
const hasProcessedLoaderGeneratedUserCss = cachedSkipProcessedCssAsset === void 0 && processedLoaderGeneratedCss !== void 0 && hasAdditionalWebpackAssetUserCssMarkers(processedLoaderGeneratedCss.css, readCurrentProcessedRawSource());
|
|
1872
|
-
const shouldFinalizeProcessedWebCssAsset = isWebGeneratorTarget && !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && hasTailwindSourceDirectives(readCurrentProcessedRawSource(), { importFallback: true });
|
|
1873
|
-
const shouldPreserveFinalWebCssAsset = isWebGeneratorTarget && processedSourceFile === void 0 && !shouldForceConfiguredMainCssGeneration && (hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1874
|
-
const shouldSkipKnownProcessedCssAsset = !shouldForceConfiguredMainCssGeneration && !shouldRegenerateProcessedTailwindV4SourceCss && !shouldRegenerateStaleProcessedWebCssAsset && (processedCssAssetKnown || isWebpackProcessedCssAsset?.(file, readCurrentProcessedRawSource(), processedCssAssetMetadata)) && !hasProcessedMainAssetUserCss && !hasProcessedLoaderGeneratedUserCss && (!cssHandlerOptionsForProcessedAsset.isMainChunk || hasGeneratedCssMarker || hasTailwindGeneratedAssetCss);
|
|
1875
|
-
const shouldSkipProcessedCssAsset = cachedSkipProcessedCssAsset ?? (shouldFinalizeProcessedWebCssAsset || shouldPreserveFinalWebCssAsset || shouldSkipKnownProcessedCssAsset);
|
|
1876
|
-
if (processedCssAssetKnown && cachedSkipProcessedCssAsset === void 0 && !shouldFinalizeProcessedWebCssAsset && !shouldPreserveFinalWebCssAsset) processedCssAssetSkipDecisionCache.set(processedCssDecisionCacheKey, shouldSkipProcessedCssAsset === true);
|
|
1877
|
-
if (shouldSkipProcessedCssAsset) {
|
|
1878
|
-
const hashKey = `${file}:asset`;
|
|
1879
|
-
const sourceHash = processedAssetSourceHash;
|
|
1880
|
-
rememberProcessCacheKey(file, hashKey);
|
|
1881
|
-
await enqueueTask(async () => {
|
|
1882
|
-
await processCachedTask({
|
|
1883
|
-
cache: compilerOptions.cache,
|
|
1884
|
-
cacheKey: file,
|
|
1885
|
-
hashKey,
|
|
1886
|
-
rawSource: chunkHash === void 0 && !processedCssAssetKnown ? readCurrentProcessedRawSource() : void 0,
|
|
1887
|
-
hash: createRuntimeAwareCssHash(chunkHash, sourceHash, `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}`),
|
|
1888
|
-
applyResult(source, { cacheHit }) {
|
|
1889
|
-
updateAssetIfChanged(file, source, {
|
|
1890
|
-
compare: !cacheHit,
|
|
1891
|
-
notifyUpdate: !cacheHit
|
|
1892
|
-
});
|
|
1893
|
-
},
|
|
1894
|
-
onCacheHit() {
|
|
1895
|
-
debug("css webpack-loader-pipeline cache hit: %s", file);
|
|
1896
|
-
},
|
|
1897
|
-
transform: async () => {
|
|
1898
|
-
const source = readCurrentProcessedRawSource();
|
|
1899
|
-
const processedBareSelectorSourceCss = processedSourceCss ?? (hasTailwindGeneratedAssetCss ? removeWebpackTailwindGeneratedAssetCss(source) : void 0);
|
|
1900
|
-
const handledCss = hasTailwindGeneratedAssetCss && !hasGeneratedCssMarker ? isWebGeneratorTarget ? source : (await compilerOptions.styleHandler(source, cssHandlerOptionsForProcessedAsset)).css : source;
|
|
1901
|
-
const nextCss = stripTrailingLineWhitespace(finalizeCssAssetSource(handledCss, {
|
|
1902
|
-
cssPreflight: cssHandlerOptionsForProcessedAsset.isMainChunk,
|
|
1903
|
-
generatedCss: hasGeneratedCssMarker || hasTailwindGeneratedAssetCss
|
|
1904
|
-
}));
|
|
1905
|
-
const processedSourceBareUserCss = isWebGeneratorTarget || processedBareSelectorSourceCss === void 0 ? void 0 : createWebpackGeneratorUserCssSourceAppend({
|
|
1906
|
-
css: collectWebpackBareSelectorUserCss(processedBareSelectorSourceCss),
|
|
1907
|
-
processed: false
|
|
1908
|
-
});
|
|
1909
|
-
const finalizedProcessedSourceBareUserCss = processedSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(processedSourceBareUserCss.css, {
|
|
1910
|
-
cssPreflight: false,
|
|
1911
|
-
generatedCss: false
|
|
1912
|
-
});
|
|
1913
|
-
const missingProcessedSourceBareUserCss = finalizedProcessedSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(nextCss, finalizedProcessedSourceBareUserCss);
|
|
1914
|
-
const css = missingProcessedSourceBareUserCss.trim().length === 0 ? nextCss : createWebpackGeneratorUserCssSourceAppend({
|
|
1915
|
-
css: nextCss,
|
|
1916
|
-
processed: true
|
|
1917
|
-
}, {
|
|
1918
|
-
css: missingProcessedSourceBareUserCss,
|
|
1919
|
-
processed: true
|
|
1920
|
-
}).css;
|
|
1921
|
-
debug("css skip webpack-loader-pipeline asset: %s", file);
|
|
1922
|
-
return { result: new ConcatSource(finalizeTracedCss(css, cssHandlerOptionsForProcessedAsset, { finalized: true })) };
|
|
1923
|
-
}
|
|
1924
|
-
});
|
|
1925
|
-
}, cssTaskFactories);
|
|
1926
|
-
continue;
|
|
1927
|
-
}
|
|
1928
|
-
const currentRawSource = readRawSource();
|
|
1929
|
-
if (isWebpackCssLoaderRuntimeSource(currentRawSource)) {
|
|
1930
|
-
const hashKey = `${file}:asset`;
|
|
1931
|
-
rememberProcessCacheKey(file, hashKey);
|
|
1932
|
-
await enqueueTask(async () => {
|
|
1933
|
-
await processCachedTask({
|
|
1934
|
-
cache: compilerOptions.cache,
|
|
1935
|
-
cacheKey: file,
|
|
1936
|
-
hashKey,
|
|
1937
|
-
rawSource: currentRawSource,
|
|
1938
|
-
hash: createRuntimeAwareCssHash(chunkHash, compilerOptions.cache.computeHash(currentRawSource), "webpack-css-loader-runtime"),
|
|
1939
|
-
applyResult(source, { cacheHit }) {
|
|
1940
|
-
updateAssetIfChanged(file, source, {
|
|
1941
|
-
compare: !cacheHit,
|
|
1942
|
-
notifyUpdate: !cacheHit
|
|
1943
|
-
});
|
|
1944
|
-
},
|
|
1945
|
-
onCacheHit() {
|
|
1946
|
-
debug("css-loader runtime cache hit: %s", file);
|
|
1947
|
-
},
|
|
1948
|
-
transform: async () => ({ result: new ConcatSource(currentRawSource) })
|
|
1949
|
-
});
|
|
1950
|
-
}, cssTaskFactories);
|
|
1951
|
-
continue;
|
|
1952
|
-
}
|
|
1953
|
-
const cacheKey = file;
|
|
1954
|
-
const hashKey = `${file}:asset`;
|
|
1955
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
1956
|
-
const cssHandlerOptionsForHash = getCssHandlerOptions(file, currentRawSource);
|
|
1957
|
-
const cssChunkHash = watchMode && cssHandlerOptionsForHash.isMainChunk ? void 0 : chunkHash;
|
|
1958
|
-
const cssSourceHash = (() => {
|
|
1959
|
-
const sourceFile = resolveWebpackCssSourceFile(file, currentRawSource);
|
|
1960
|
-
const sourceCss = sourceFile ? cssSources.get(sourceFile)?.css : void 0;
|
|
1961
|
-
const generatorSourceCss = removeWebpackGeneratorNonTailwindImports(sourceCss);
|
|
1962
|
-
if (sourceCss === void 0) return sourceFile === void 0 ? "webpack-css-source:0" : `webpack-css-source:0:${sourceFile}`;
|
|
1963
|
-
return `webpack-css-source:1:${compilerOptions.cache.computeHash(sourceCss)}:${generatorSourceCss === sourceCss || generatorSourceCss === void 0 ? "generator-source:0" : compilerOptions.cache.computeHash(generatorSourceCss)}`;
|
|
1964
|
-
})();
|
|
1965
|
-
const runtimeAwareHash = createRuntimeAwareCssHash(cssChunkHash, compilerOptions.cache.computeHash(currentRawSource), `${createRuntimeSetHash(getGeneratorRuntimeSet())}:${runtimeAffectingSourceHash}:${webpackSourceCandidates?.signatureHash ?? "source-candidates:0"}:${webpackSourceCandidateValueSignature}:${cssSourceTraceSignature}:${cssSourceHash}`);
|
|
1966
|
-
await enqueueTask(async () => {
|
|
1967
|
-
await processCachedTask({
|
|
1968
|
-
cache: compilerOptions.cache,
|
|
1969
|
-
cacheKey,
|
|
1970
|
-
hashKey,
|
|
1971
|
-
rawSource: currentRawSource,
|
|
1972
|
-
hash: runtimeAwareHash,
|
|
1973
|
-
applyResult(source, { cacheHit }) {
|
|
1974
|
-
updateAssetIfChanged(file, source, {
|
|
1975
|
-
compare: !cacheHit,
|
|
1976
|
-
notifyUpdate: !cacheHit
|
|
1977
|
-
});
|
|
1978
|
-
},
|
|
1979
|
-
onCacheHit() {
|
|
1980
|
-
debug("css cache hit: %s", file);
|
|
1981
|
-
},
|
|
1982
|
-
transform: async () => {
|
|
1983
|
-
await runtimeState.readyPromise;
|
|
1984
|
-
const cssHandlerOptions = getCssHandlerOptions(file, currentRawSource);
|
|
1985
|
-
const generatorRawSource = resolveWebpackGeneratorRawSource(currentRawSource, cssHandlerOptions);
|
|
1986
|
-
if (isWebpackCssLoaderRuntimeSource(generatorRawSource)) return { result: new ConcatSource(currentRawSource) };
|
|
1987
|
-
const sourceFile = cssHandlerOptions.sourceOptions?.sourceFile;
|
|
1988
|
-
const sourceCss = sourceFile ? cssSources.get(path.resolve(sourceFile))?.css : void 0;
|
|
1989
|
-
const isConfiguredCssSource = sourceFile !== void 0 && configuredCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile));
|
|
1990
|
-
const isConfiguredMainCssSource = sourceFile !== void 0 && configuredMainCssEntryFiles.some((entry) => path.resolve(entry) === path.resolve(sourceFile));
|
|
1991
|
-
const sourceCssHasTailwindRoot = sourceCss !== void 0 && hasTailwindRootDirectives(sourceCss, { importFallback: true });
|
|
1992
|
-
const shouldPreserveExistingPreflight = cssHandlerOptions.isMainChunk || !isConfiguredMainCssSource && (isConfiguredCssSource || sourceCssHasTailwindRoot);
|
|
1993
|
-
const loaderGeneratedCss = sourceFile && !isWebGeneratorTarget ? generatedCssSources.get(path.resolve(sourceFile)) : void 0;
|
|
1994
|
-
const shouldRegenerateExplicitTailwindV4CssSource = sourceCss !== void 0 && (hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
1995
|
-
const explicitTailwindV4SourceCandidates = shouldRegenerateExplicitTailwindV4CssSource && sourceCss && sourceFile && webpackSourceCandidates?.getSourceCandidatesForEntries ? await resolveTailwindV4EntriesFromCssCached(sourceCss, path.dirname(sourceFile)).then((resolved) => resolved?.entries ? webpackSourceCandidates.getSourceCandidatesForEntries(resolved.entries) : void 0) : void 0;
|
|
1996
|
-
if (loaderGeneratedCss && shouldConsumeWebpackLoaderGeneratedCss({
|
|
1997
|
-
hasBundlerGeneratedCssMarker: hasBundlerGeneratedCssMarker(currentRawSource),
|
|
1998
|
-
loaderGeneratedClassSet: loaderGeneratedCss.classSet,
|
|
1999
|
-
sourceCandidates: explicitTailwindV4SourceCandidates,
|
|
2000
|
-
shouldRegenerateExplicitTailwindV4CssSource,
|
|
2001
|
-
watchMode
|
|
2002
|
-
})) {
|
|
2003
|
-
for (const className of loaderGeneratedCss.classSet) {
|
|
2004
|
-
generatorRuntimeSet.add(className);
|
|
2005
|
-
transformRuntimeSet.add(className);
|
|
2006
|
-
}
|
|
2007
|
-
for (const dependency of loaderGeneratedCss.dependencies) compilation.fileDependencies?.add?.(dependency);
|
|
2008
|
-
const currentRawSourceWithoutBundlerMarkers = stripBundlerGeneratedCssMarkers(currentRawSource);
|
|
2009
|
-
const currentAssetHasProcessedUrl = hasProcessedCssAssetUrl(currentRawSourceWithoutBundlerMarkers) && currentRawSourceWithoutBundlerMarkers !== loaderGeneratedCss.css;
|
|
2010
|
-
const currentAssetUserCss = currentAssetHasProcessedUrl ? currentRawSourceWithoutBundlerMarkers : shouldUseWebpackAssetAsGeneratorUserCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css, { processed: true }) ? removeGeneratedSelectorCompatCss(currentRawSourceWithoutBundlerMarkers, loaderGeneratedCss.css) : void 0;
|
|
2011
|
-
const loaderGeneratedCssWithoutMarkers = stripBundlerGeneratedCssMarkers(loaderGeneratedCss.css);
|
|
2012
|
-
const currentAssetUserCssWithoutMarkers = currentAssetUserCss === void 0 ? "" : stripBundlerGeneratedCssMarkers(currentAssetUserCss);
|
|
2013
|
-
const currentAssetMissingUserCss = !(currentAssetUserCssWithoutMarkers.trim().length > 0 && !isCommentOnlyCss(currentAssetUserCssWithoutMarkers)) ? "" : filterExistingCssRules(currentAssetUserCssWithoutMarkers, loaderGeneratedCssWithoutMarkers);
|
|
2014
|
-
if (isConfiguredMainCssSource && !cssHandlerOptions.isMainChunk) {
|
|
2015
|
-
debug("css skip duplicate webpack loader main generation: %s <- %s", file, sourceFile);
|
|
2016
|
-
const userCss = currentAssetMissingUserCss.trim().length === 0 || isCommentOnlyCss(currentAssetMissingUserCss) ? "" : finalizeCssAssetSource(currentAssetMissingUserCss, {
|
|
2017
|
-
cssPreflight: false,
|
|
2018
|
-
generatedCss: false
|
|
2019
|
-
});
|
|
2020
|
-
return { result: new ConcatSource(finalizeTracedCss(userCss, cssHandlerOptions)) };
|
|
2021
|
-
}
|
|
2022
|
-
const mergedLoaderCss = currentAssetUserCss === void 0 ? loaderGeneratedCss.css : createWebpackGeneratorUserCssSourceAppend({
|
|
2023
|
-
css: currentAssetUserCss === void 0 ? loaderGeneratedCss.css : currentAssetHasProcessedUrl ? removeGeneratedSelectorCompatCss(loaderGeneratedCss.css, currentAssetUserCss) : filterExistingCssRules(currentAssetUserCss, loaderGeneratedCss.css),
|
|
2024
|
-
processed: true
|
|
2025
|
-
}, currentAssetUserCss === void 0 ? void 0 : {
|
|
2026
|
-
css: currentAssetUserCss,
|
|
2027
|
-
processed: true
|
|
2028
|
-
}).css;
|
|
2029
|
-
const finalizedLoaderCss = finalizeCssAssetSource(mergedLoaderCss, {
|
|
2030
|
-
cssPreflight: cssHandlerOptions.isMainChunk,
|
|
2031
|
-
generatedCss: true,
|
|
2032
|
-
preserveExistingPreflight: shouldPreserveExistingPreflight
|
|
2033
|
-
});
|
|
2034
|
-
const loaderSourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[currentAssetUserCss === void 0 ? void 0 : {
|
|
2035
|
-
css: currentAssetUserCss,
|
|
2036
|
-
processed: true
|
|
2037
|
-
}, sourceCss === void 0 ? void 0 : {
|
|
2038
|
-
css: sourceCss,
|
|
2039
|
-
processed: false
|
|
2040
|
-
}].map((source) => {
|
|
2041
|
-
if (source === void 0) return;
|
|
2042
|
-
return {
|
|
2043
|
-
css: collectWebpackBareSelectorUserCss(source.css),
|
|
2044
|
-
processed: source.processed
|
|
2045
|
-
};
|
|
2046
|
-
}));
|
|
2047
|
-
const finalizedLoaderSourceBareUserCss = loaderSourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(loaderSourceBareUserCss.css, {
|
|
2048
|
-
cssPreflight: false,
|
|
2049
|
-
generatedCss: false
|
|
2050
|
-
});
|
|
2051
|
-
const missingLoaderSourceBareUserCss = finalizedLoaderSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(finalizedLoaderCss, finalizedLoaderSourceBareUserCss);
|
|
2052
|
-
const css = finalizeTracedCss(missingLoaderSourceBareUserCss.trim().length === 0 ? finalizedLoaderCss : createWebpackGeneratorUserCssSourceAppend({
|
|
2053
|
-
css: finalizedLoaderCss,
|
|
2054
|
-
processed: true
|
|
2055
|
-
}, {
|
|
2056
|
-
css: missingLoaderSourceBareUserCss,
|
|
2057
|
-
processed: true
|
|
2058
|
-
}).css, cssHandlerOptions, { finalized: true });
|
|
2059
|
-
debug("css consume webpack loader generation: %s <- %s", file, sourceFile);
|
|
2060
|
-
return { result: new ConcatSource(css) };
|
|
2061
|
-
}
|
|
2062
|
-
const sourceCssProcessed = sourceFile ? cssSources.get(path.resolve(sourceFile))?.processed === true : false;
|
|
2063
|
-
const registeredUserRawSource = createWebpackUserCssSourceAppend([...cssSources.entries()].map(([registeredSourceFile, source]) => ({
|
|
2064
|
-
...source,
|
|
2065
|
-
file: registeredSourceFile
|
|
2066
|
-
})), generatorRawSource, sourceFile, (registeredSourceFile) => isSameWebpackSourceScope(file, registeredSourceFile, sourceFile));
|
|
2067
|
-
const currentAssetLooksGenerated = hasTailwindGeneratedCss(currentRawSource) || hasTailwindGeneratedCssMarkers(currentRawSource);
|
|
2068
|
-
const currentAssetHasBundlerGeneratedMarker = hasBundlerGeneratedCssMarker(currentRawSource);
|
|
2069
|
-
const currentAssetUserCssSource = currentAssetLooksGenerated ? removeWebpackTailwindGeneratedAssetCss(currentRawSource) : currentRawSource;
|
|
2070
|
-
if (sourceFile === void 0 && currentAssetHasBundlerGeneratedMarker && (currentAssetUserCssSource.trim().length === 0 || isCommentOnlyCss(currentAssetUserCssSource))) return { result: new ConcatSource(finalizeTracedCss("", cssHandlerOptions)) };
|
|
2071
|
-
const currentAssetHasAdditionalUserCss = currentAssetLooksGenerated && (hasAdditionalWebpackAssetUserCssMarkers(currentAssetUserCssSource, generatorRawSource) || currentAssetUserCssSource.trim().length > 0);
|
|
2072
|
-
const shouldPreserveGeneratedWebAssetUserCss = isWebGeneratorTarget && currentAssetLooksGenerated && !currentAssetHasBundlerGeneratedMarker && !currentAssetHasAdditionalUserCss;
|
|
2073
|
-
const hasExplicitSourceCssForCurrentAsset = sourceCss !== void 0 && (hasTailwindRootDirectives(sourceCss, { importFallback: true }) || hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || hasTailwindApplyDirective(sourceCss));
|
|
2074
|
-
const currentAssetHasUserCss = (sourceCssProcessed || hasExplicitSourceCssForCurrentAsset) && currentAssetLooksGenerated && !shouldPreserveGeneratedWebAssetUserCss ? currentAssetHasAdditionalUserCss : shouldUseWebpackAssetAsGeneratorUserCss(currentAssetUserCssSource, generatorRawSource, { processed: sourceCssProcessed || shouldPreserveGeneratedWebAssetUserCss });
|
|
2075
|
-
const userRawSource = createWebpackGeneratorUserCssSourceAppend(createWebpackCurrentAssetUserRawSource({
|
|
2076
|
-
currentAssetHasUserCss,
|
|
2077
|
-
currentAssetLooksGenerated,
|
|
2078
|
-
currentAssetUserCssSource,
|
|
2079
|
-
shouldAppendCurrentAssetUserCss: shouldAppendCurrentWebpackAssetUserCss({
|
|
2080
|
-
currentAssetHasBundlerGeneratedMarker,
|
|
2081
|
-
currentAssetHasUserCss,
|
|
2082
|
-
currentAssetLooksGenerated,
|
|
2083
|
-
registeredUserRawSource,
|
|
2084
|
-
shouldPreserveGeneratedWebAssetUserCss,
|
|
2085
|
-
sourceCssProcessed
|
|
2086
|
-
}),
|
|
2087
|
-
sourceCssProcessed
|
|
2088
|
-
}), registeredUserRawSource);
|
|
2089
|
-
if (isPureLocalCssImportWrapper(currentRawSource)) return { result: new ConcatSource(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(currentRawSource), { importFallback: true })) };
|
|
2090
|
-
const fallbackGeneratorRuntimeSet = getGeneratorRuntimeSet();
|
|
2091
|
-
const hasExplicitTailwindV4SourceCss = sourceCss !== void 0 && (hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || sourceCss.includes("@config"));
|
|
2092
|
-
const currentAssetHasTailwindDirectives = hasTailwindRootDirectives(generatorRawSource, { importFallback: true }) || hasTailwindSourceDirectives(generatorRawSource, { importFallback: true }) || hasTailwindApplyDirective(generatorRawSource);
|
|
2093
|
-
const shouldForceTailwindV4Generation = hasConfiguredTailwindV4SourceRoots() && (configuredMainCssEntryFiles.length > 0 && sourceFile !== void 0 || currentAssetHasTailwindDirectives || hasExplicitTailwindV4SourceCss);
|
|
2094
|
-
const shouldSkipUnmatchedMainCssGeneration = !isWebGeneratorTarget && cssHandlerOptions.isMainChunk && sourceFile === void 0 && configuredMainCssEntryFiles.length > 0 && !currentAssetHasTailwindDirectives;
|
|
2095
|
-
const shouldSkipPlainNonMainCssGeneration = !cssHandlerOptions.isMainChunk && sourceCss !== void 0 && !hasExplicitSourceCssForCurrentAsset && !hasExplicitTailwindV4SourceCss && !currentAssetHasTailwindDirectives;
|
|
2096
|
-
const shouldMergeFallbackGeneratorRuntime = cssHandlerOptions.isMainChunk || currentAssetHasTailwindDirectives || hasExplicitSourceCssForCurrentAsset;
|
|
2097
|
-
const scopedFallbackGeneratorRuntimeSet = hasExplicitTailwindV4SourceCss || !shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set() : fallbackGeneratorRuntimeSet;
|
|
2098
|
-
const resolvedScopedGeneratorRuntimeSet = await createScopedGeneratorRuntime({
|
|
2099
|
-
cssHandlerOptions,
|
|
2100
|
-
fallbackRuntime: scopedFallbackGeneratorRuntimeSet,
|
|
2101
|
-
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
2102
|
-
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2103
|
-
outputFile: file,
|
|
2104
|
-
rawSource: sourceFile ? cssSources.get(path.resolve(sourceFile))?.css ?? generatorRawSource : generatorRawSource,
|
|
2105
|
-
shouldExcludeSubpackageSourceCandidates: () => false,
|
|
2106
|
-
sourceFile: sourceFile ?? file,
|
|
2107
|
-
scopedSourceCandidateGetter: webpackSourceCandidates?.getSourceCandidatesForEntries
|
|
2108
|
-
});
|
|
2109
|
-
const scopedGeneratorRuntimeSet = !hasExplicitTailwindV4SourceCss && resolvedScopedGeneratorRuntimeSet !== scopedFallbackGeneratorRuntimeSet && shouldMergeFallbackGeneratorRuntime ? /* @__PURE__ */ new Set([...fallbackGeneratorRuntimeSet, ...resolvedScopedGeneratorRuntimeSet]) : resolvedScopedGeneratorRuntimeSet;
|
|
2110
|
-
const generatorCssSources = normalizeWebpackGeneratorCssSources(cssHandlerOptions.sourceOptions?.cssSources);
|
|
2111
|
-
const scopedGeneratorCompilerOptions = scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, { disableUnmatchedCssEntries: !isWebGeneratorTarget && cssHandlerOptions.isMainChunk });
|
|
2112
|
-
const generatorCssHandlerOptions = generatorCssSources === void 0 ? cssHandlerOptions : {
|
|
2113
|
-
...cssHandlerOptions,
|
|
2114
|
-
sourceOptions: {
|
|
2115
|
-
...cssHandlerOptions.sourceOptions,
|
|
2116
|
-
cssSources: generatorCssSources
|
|
2117
|
-
}
|
|
2118
|
-
};
|
|
2119
|
-
const generatorOptions = {
|
|
2120
|
-
opts: scopedGeneratorCompilerOptions,
|
|
2121
|
-
runtimeState,
|
|
2122
|
-
runtime: scopedGeneratorRuntimeSet,
|
|
2123
|
-
rawSource: generatorRawSource,
|
|
2124
|
-
forceGenerator: shouldForceTailwindV4Generation,
|
|
2125
|
-
...hasUsableWebpackGeneratorCssSources(generatorCssSources) ? { cssSources: generatorCssSources } : {},
|
|
2126
|
-
...userRawSource === void 0 ? {} : { userRawSource: userRawSource.css },
|
|
2127
|
-
...userRawSource?.processed === true ? { userRawSourceProcessed: true } : {},
|
|
2128
|
-
file,
|
|
2129
|
-
cssHandlerOptions: generatorCssHandlerOptions,
|
|
2130
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
2131
|
-
getSourceCandidatesForEntries: webpackSourceCandidates?.getSourceCandidatesForEntries,
|
|
2132
|
-
sourceCandidates: scopedGeneratorRuntimeSet,
|
|
2133
|
-
restoreLocalCssImports: false,
|
|
2134
|
-
styleHandler: compilerOptions.styleHandler,
|
|
2135
|
-
debug
|
|
2136
|
-
};
|
|
2137
|
-
let generated;
|
|
2138
|
-
if (!shouldSkipUnmatchedMainCssGeneration && !shouldSkipPlainNonMainCssGeneration) try {
|
|
2139
|
-
generated = await generateTailwindV4Css({
|
|
2140
|
-
...generatorOptions,
|
|
2141
|
-
outputFile: file
|
|
2142
|
-
});
|
|
2143
|
-
} catch (error) {
|
|
2144
|
-
if (!shouldFallbackToWebpackUserCssOnGeneratorError({
|
|
2145
|
-
configuredMainCssEntryFilesLength: configuredMainCssEntryFiles.length,
|
|
2146
|
-
generatorRawSource,
|
|
2147
|
-
hasExplicitTailwindV4SourceCss
|
|
2148
|
-
})) throw error;
|
|
2149
|
-
debug("css generator skipped for plain webpack css asset: %s %O", file, error);
|
|
2150
|
-
generated = void 0;
|
|
2151
|
-
}
|
|
2152
|
-
else debug("css generator skipped for plain webpack css asset: %s", file);
|
|
2153
|
-
const finalizedGeneratedCss = generated ? finalizeCssAssetSource(isWebGeneratorTarget && currentRawSource.includes("tailwindcss v4.") ? createWebpackGeneratorUserCssSourceAppend({
|
|
2154
|
-
css: generated.css,
|
|
2155
|
-
processed: true
|
|
2156
|
-
}, {
|
|
2157
|
-
css: removeWebpackTailwindGeneratedAssetCss(currentRawSource),
|
|
2158
|
-
processed: true
|
|
2159
|
-
})?.css ?? generated.css : generated.css, {
|
|
2160
|
-
cssPreflight: cssHandlerOptions.isMainChunk,
|
|
2161
|
-
generatedCss: true,
|
|
2162
|
-
preserveExistingPreflight: shouldPreserveExistingPreflight
|
|
2163
|
-
}) : isWebGeneratorTarget ? finalizeCssAssetSource(generatorRawSource, { generatedCss: false }) : finalizeCssAssetSource((await compilerOptions.styleHandler(generatorRawSource, cssHandlerOptions)).css, { generatedCss: false });
|
|
2164
|
-
const sourceBareUserCss = isWebGeneratorTarget ? void 0 : createWebpackGeneratorUserCssSourceAppend(...[
|
|
2165
|
-
userRawSource,
|
|
2166
|
-
sourceCss === void 0 ? void 0 : {
|
|
2167
|
-
css: sourceCss,
|
|
2168
|
-
processed: sourceCssProcessed
|
|
2169
|
-
},
|
|
2170
|
-
{
|
|
2171
|
-
css: generatorRawSource,
|
|
2172
|
-
processed: false
|
|
2173
|
-
}
|
|
2174
|
-
].map((source) => {
|
|
2175
|
-
if (source === void 0) return;
|
|
2176
|
-
return {
|
|
2177
|
-
css: collectWebpackBareSelectorUserCss(source.css),
|
|
2178
|
-
processed: source.processed
|
|
2179
|
-
};
|
|
2180
|
-
}));
|
|
2181
|
-
const finalizedSourceBareUserCss = sourceBareUserCss === void 0 ? "" : finalizeCssAssetSource(sourceBareUserCss.css, {
|
|
2182
|
-
cssPreflight: false,
|
|
2183
|
-
generatedCss: false
|
|
2184
|
-
});
|
|
2185
|
-
const missingSourceBareUserCss = finalizedSourceBareUserCss.trim().length === 0 ? "" : filterExistingCssRules(finalizedGeneratedCss, finalizedSourceBareUserCss);
|
|
2186
|
-
const css = finalizeTracedCss(missingSourceBareUserCss.trim().length === 0 ? finalizedGeneratedCss : createWebpackGeneratorUserCssSourceAppend({
|
|
2187
|
-
css: finalizedGeneratedCss,
|
|
2188
|
-
processed: true
|
|
2189
|
-
}, {
|
|
2190
|
-
css: missingSourceBareUserCss,
|
|
2191
|
-
processed: true
|
|
2192
|
-
}).css, cssHandlerOptions, { finalized: true });
|
|
2193
|
-
const source = new ConcatSource(css);
|
|
2194
|
-
if (generated) {
|
|
2195
|
-
for (const className of generated.classSet) generatorRuntimeSet.add(className);
|
|
2196
|
-
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, file);
|
|
2197
|
-
} else debug("css handle: %s", file);
|
|
2198
|
-
return { result: source };
|
|
2199
|
-
}
|
|
2200
|
-
});
|
|
2201
|
-
}, cssTaskFactories);
|
|
2434
|
+
if (await processWebpackProcessedCssAsset(element, cssTaskContext)) continue;
|
|
2435
|
+
await processWebpackGeneratedCssAsset(element, cssTaskContext);
|
|
2202
2436
|
}
|
|
2203
|
-
|
|
2204
|
-
pushConcurrentTaskFactories(tasks, htmlTaskFactories, taskConcurrency);
|
|
2205
|
-
await Promise.all(tasks);
|
|
2206
|
-
tasks.length = 0;
|
|
2207
|
-
pushConcurrentTaskFactories(tasks, jsTaskFactories, taskConcurrency);
|
|
2208
|
-
await Promise.all(tasks);
|
|
2209
|
-
tasks.length = 0;
|
|
2210
|
-
pushConcurrentTaskFactories(tasks, cssTaskFactories, taskConcurrency);
|
|
2211
|
-
}
|
|
2212
|
-
await Promise.all(tasks);
|
|
2213
|
-
compilerOptions.cache.prune?.({
|
|
2214
|
-
cacheKeys: activeProcessCacheKeys,
|
|
2215
|
-
hashKeys: activeProcessHashKeys
|
|
2216
|
-
});
|
|
2217
|
-
const activeCssFiles = new Set(groupedEntries.css.map(([file]) => file));
|
|
2218
|
-
pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
|
|
2219
|
-
if (activeCssFiles.size > 0) pruneWebpackCssSources?.(/* @__PURE__ */ new Set([
|
|
2220
|
-
...registeredWebpackCssSourceFiles,
|
|
2221
|
-
...activeWebpackCssSourceFiles,
|
|
2222
|
-
...[...cssAssetResources.values()].flatMap((resources) => [...resources])
|
|
2223
|
-
]), { watchMode });
|
|
2224
|
-
debug("end");
|
|
2225
|
-
emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
|
|
2226
|
-
activeAssetFiles: entries.length,
|
|
2227
|
-
activeCssFiles: activeCssFiles.size,
|
|
2437
|
+
await finalizeWebpackProcessAssets({
|
|
2228
2438
|
activeProcessCacheKeys,
|
|
2229
2439
|
activeProcessHashKeys,
|
|
2230
|
-
|
|
2440
|
+
activeWebpackCssSourceFiles,
|
|
2441
|
+
compilerOptions,
|
|
2442
|
+
cssAssetResources,
|
|
2231
2443
|
cssHandlerOptionsCache,
|
|
2444
|
+
cssTaskFactories,
|
|
2232
2445
|
cssUserHandlerOptionsCache,
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2446
|
+
debug,
|
|
2447
|
+
entries,
|
|
2448
|
+
groupedEntries,
|
|
2449
|
+
hmrTimingStartedAt,
|
|
2450
|
+
htmlTaskFactories,
|
|
2451
|
+
jsTaskFactories,
|
|
2452
|
+
pruneWebpackCssSources,
|
|
2453
|
+
recordTimingDetail,
|
|
2454
|
+
registeredWebpackCssSourceFiles,
|
|
2455
|
+
taskConcurrency,
|
|
2456
|
+
tasks,
|
|
2457
|
+
timingDetails,
|
|
2458
|
+
watchMode,
|
|
2459
|
+
webpackSourceCandidateScanCache
|
|
2460
|
+
});
|
|
2237
2461
|
});
|
|
2238
2462
|
if (!isWebGeneratorTarget) compilation.hooks.processAssets.tapPromise({
|
|
2239
2463
|
name: `${pluginName}:finalize-css-assets`,
|
|
@@ -2254,11 +2478,106 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
2254
2478
|
});
|
|
2255
2479
|
}
|
|
2256
2480
|
//#endregion
|
|
2257
|
-
//#region ../../node_modules/.pnpm/tsdown@0.22.
|
|
2481
|
+
//#region ../../node_modules/.pnpm/tsdown@0.22.8_oxc-resolver@11.20.0_tsx@4.23.1_typescript@6.0.3_unrun@0.2.37_synckit@0.1_6382f73c03b72307015b1b16541a6d64/node_modules/tsdown/esm-shims.js
|
|
2258
2482
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
2259
2483
|
const getDirname = () => path.dirname(getFilename());
|
|
2260
2484
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
2261
2485
|
//#endregion
|
|
2486
|
+
//#region src/shared/mpx-plugin-owner.ts
|
|
2487
|
+
const localRequire = createRequire(import.meta.url);
|
|
2488
|
+
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
2489
|
+
const MPX_WEBPACK_PLUGIN_LIB_RE = /^(.*[\\/]@mpxjs[\\/]webpack-plugin)[\\/]lib[\\/]/;
|
|
2490
|
+
const MPX_RECORD_RESOURCE_MAP_DEPENDENCY_RE = /@mpxjs[\\/]webpack-plugin[\\/]lib[\\/]dependencies[\\/]RecordResourceMapDependency(?:\.js)?$/;
|
|
2491
|
+
const compilationOwnerDirs = /* @__PURE__ */ new WeakMap();
|
|
2492
|
+
function findMpxWebpackPluginDir(value) {
|
|
2493
|
+
if (typeof value === "string") return value.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1];
|
|
2494
|
+
if (Array.isArray(value)) {
|
|
2495
|
+
for (const item of value) {
|
|
2496
|
+
const result = findMpxWebpackPluginDir(item);
|
|
2497
|
+
if (result) return result;
|
|
2498
|
+
}
|
|
2499
|
+
return;
|
|
2500
|
+
}
|
|
2501
|
+
if (value && typeof value === "object") for (const key of [
|
|
2502
|
+
"loader",
|
|
2503
|
+
"use",
|
|
2504
|
+
"rules",
|
|
2505
|
+
"oneOf"
|
|
2506
|
+
]) {
|
|
2507
|
+
const result = findMpxWebpackPluginDir(value[key]);
|
|
2508
|
+
if (result) return result;
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
function resolveContextPluginDir(context) {
|
|
2512
|
+
if (typeof context !== "string" || context.length === 0) return;
|
|
2513
|
+
try {
|
|
2514
|
+
const projectRequire = createRequire(path.join(context, "package.json"));
|
|
2515
|
+
return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
2516
|
+
} catch {
|
|
2517
|
+
return;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
function resolveCompilationPluginDir(compilation, candidates) {
|
|
2521
|
+
const getTemplate = compilation?.dependencyTemplates?.get;
|
|
2522
|
+
if (typeof getTemplate !== "function") return;
|
|
2523
|
+
if (compilation && typeof compilation === "object") {
|
|
2524
|
+
const cached = compilationOwnerDirs.get(compilation);
|
|
2525
|
+
if (cached) return cached;
|
|
2526
|
+
}
|
|
2527
|
+
const rememberOwner = (pluginDir) => {
|
|
2528
|
+
if (pluginDir && compilation && typeof compilation === "object") compilationOwnerDirs.set(compilation, pluginDir);
|
|
2529
|
+
return pluginDir;
|
|
2530
|
+
};
|
|
2531
|
+
for (const [file, module] of Object.entries(localRequire.cache)) {
|
|
2532
|
+
if (!MPX_RECORD_RESOURCE_MAP_DEPENDENCY_RE.test(file)) continue;
|
|
2533
|
+
if (getTemplate.call(compilation.dependencyTemplates, module?.exports)) return rememberOwner(file.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1]);
|
|
2534
|
+
}
|
|
2535
|
+
for (const pluginDir of candidates) try {
|
|
2536
|
+
const dependency = createRequire(path.join(pluginDir, "package.json"))(path.join(pluginDir, "lib/dependencies/RecordResourceMapDependency"));
|
|
2537
|
+
if (getTemplate.call(compilation.dependencyTemplates, dependency)) return rememberOwner(pluginDir);
|
|
2538
|
+
} catch {}
|
|
2539
|
+
}
|
|
2540
|
+
function collectMpxWebpackPluginDirs(owner, fallback) {
|
|
2541
|
+
const activeLoaderPluginDir = findMpxWebpackPluginDir([owner?._module?.loaders, owner?.loaders]);
|
|
2542
|
+
const contextPluginDirs = [
|
|
2543
|
+
owner?.rootContext,
|
|
2544
|
+
owner?.context,
|
|
2545
|
+
owner?.options?.context,
|
|
2546
|
+
process.cwd()
|
|
2547
|
+
].map(resolveContextPluginDir).filter((item) => Boolean(item));
|
|
2548
|
+
const configuredRulePluginDir = findMpxWebpackPluginDir(owner?.options?.module?.rules);
|
|
2549
|
+
const cachedPluginDirs = Object.keys(localRequire.cache).map((file) => file.match(MPX_WEBPACK_PLUGIN_LIB_RE)?.[1] ?? (MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file) ? path.dirname(file) : void 0)).filter((item) => Boolean(item));
|
|
2550
|
+
const localPluginDir = (() => {
|
|
2551
|
+
try {
|
|
2552
|
+
return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
2553
|
+
} catch {
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
})();
|
|
2557
|
+
return {
|
|
2558
|
+
activeLoaderPluginDir,
|
|
2559
|
+
candidates: new Set([
|
|
2560
|
+
activeLoaderPluginDir,
|
|
2561
|
+
...contextPluginDirs,
|
|
2562
|
+
configuredRulePluginDir,
|
|
2563
|
+
fallback,
|
|
2564
|
+
...cachedPluginDirs,
|
|
2565
|
+
localPluginDir
|
|
2566
|
+
].filter((item) => Boolean(item))),
|
|
2567
|
+
configuredRulePluginDir,
|
|
2568
|
+
contextPluginDirs,
|
|
2569
|
+
cachedPluginDirs,
|
|
2570
|
+
localPluginDir
|
|
2571
|
+
};
|
|
2572
|
+
}
|
|
2573
|
+
function resolveMpxWebpackPluginCompilationOwnerDir(owner, compilation, fallback) {
|
|
2574
|
+
return resolveCompilationPluginDir(compilation, collectMpxWebpackPluginDirs(owner, fallback).candidates);
|
|
2575
|
+
}
|
|
2576
|
+
function resolveMpxWebpackPluginDir(owner, fallback, compilation = owner?._compilation ?? owner?.compilation) {
|
|
2577
|
+
const { activeLoaderPluginDir, candidates, configuredRulePluginDir, contextPluginDirs, cachedPluginDirs, localPluginDir } = collectMpxWebpackPluginDirs(owner, fallback);
|
|
2578
|
+
return resolveCompilationPluginDir(compilation, candidates) ?? activeLoaderPluginDir ?? contextPluginDirs[0] ?? configuredRulePluginDir ?? fallback ?? cachedPluginDirs[0] ?? localPluginDir;
|
|
2579
|
+
}
|
|
2580
|
+
//#endregion
|
|
2262
2581
|
//#region src/shared/tailwindcss-css-redirect.ts
|
|
2263
2582
|
const moduleWithMutableResolve = Module;
|
|
2264
2583
|
const patched = /* @__PURE__ */ new WeakSet();
|
|
@@ -2277,9 +2596,8 @@ function installTailwindcssCssRedirect(pkgDir) {
|
|
|
2277
2596
|
}
|
|
2278
2597
|
//#endregion
|
|
2279
2598
|
//#region src/shared/mpx.ts
|
|
2280
|
-
const localRequire = createRequire(import.meta.url);
|
|
2281
2599
|
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:^|[?&])type=styles(?:&|$)/;
|
|
2282
|
-
const
|
|
2600
|
+
const MPX_WEBPACK_PLUGIN_REQUEST_PATH_RE = /(?:^|[\\/])@mpxjs[\\/]webpack-plugin(?:[\\/](.+))?$/;
|
|
2283
2601
|
function isMpxStyleResourceQuery(query) {
|
|
2284
2602
|
if (typeof query !== "string") return false;
|
|
2285
2603
|
return MPX_STYLE_RESOURCE_QUERY_RE.test(query);
|
|
@@ -2287,23 +2605,61 @@ function isMpxStyleResourceQuery(query) {
|
|
|
2287
2605
|
function getTailwindcssCssEntry(pkgDir) {
|
|
2288
2606
|
return path.join(pkgDir, "index.css");
|
|
2289
2607
|
}
|
|
2290
|
-
function
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
const
|
|
2298
|
-
return
|
|
2299
|
-
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2608
|
+
function rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir, pathImpl = path) {
|
|
2609
|
+
return request.split("!").map((segment) => {
|
|
2610
|
+
const queryIndex = segment.indexOf("?");
|
|
2611
|
+
const requestPath = queryIndex === -1 ? segment : segment.slice(0, queryIndex);
|
|
2612
|
+
const query = queryIndex === -1 ? "" : segment.slice(queryIndex);
|
|
2613
|
+
const match = requestPath.match(MPX_WEBPACK_PLUGIN_REQUEST_PATH_RE);
|
|
2614
|
+
if (!match) return segment;
|
|
2615
|
+
const subpath = match[1];
|
|
2616
|
+
return `${subpath ? pathImpl.join(mpxWebpackPluginDir, ...subpath.split(/[\\/]/)) : mpxWebpackPluginDir}${query}`;
|
|
2617
|
+
}).join("!");
|
|
2618
|
+
}
|
|
2619
|
+
function patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir) {
|
|
2620
|
+
if (!mpxWebpackPluginDir || !compiler) return false;
|
|
2621
|
+
const pluginName = "weapp-tailwindcss-mpx-loader-resolve";
|
|
2622
|
+
const patchedCompilers = /* @__PURE__ */ new WeakSet();
|
|
2623
|
+
const patchedLoaderResolvers = /* @__PURE__ */ new WeakSet();
|
|
2624
|
+
const patchedResolverFactories = /* @__PURE__ */ new WeakSet();
|
|
2625
|
+
let activePluginDir = mpxWebpackPluginDir;
|
|
2626
|
+
const getActivePluginDir = () => activePluginDir;
|
|
2627
|
+
const install = (targetCompiler) => {
|
|
2628
|
+
if (!targetCompiler || typeof targetCompiler !== "object" || patchedCompilers.has(targetCompiler)) return;
|
|
2629
|
+
patchedCompilers.add(targetCompiler);
|
|
2630
|
+
ensureResolveLoaderAlias(targetCompiler, activePluginDir);
|
|
2631
|
+
const resolverFactory = targetCompiler.resolverFactory;
|
|
2632
|
+
if (resolverFactory && typeof resolverFactory === "object" && !patchedResolverFactories.has(resolverFactory)) {
|
|
2633
|
+
patchedResolverFactories.add(resolverFactory);
|
|
2634
|
+
installMpxResolveLoaderAlias(targetCompiler, getActivePluginDir);
|
|
2635
|
+
}
|
|
2636
|
+
targetCompiler.hooks?.normalModuleFactory?.tap?.(pluginName, (normalModuleFactory) => {
|
|
2637
|
+
const loaderResolver = normalModuleFactory.getResolver?.("loader");
|
|
2638
|
+
if (loaderResolver && typeof loaderResolver === "object" && !patchedLoaderResolvers.has(loaderResolver)) {
|
|
2639
|
+
patchedLoaderResolvers.add(loaderResolver);
|
|
2640
|
+
patchMpxLoaderResolver(loaderResolver, getActivePluginDir);
|
|
2641
|
+
}
|
|
2642
|
+
normalModuleFactory.hooks.beforeResolve.tap(pluginName, (resolveData) => {
|
|
2643
|
+
const pluginDir = getActivePluginDir();
|
|
2644
|
+
if (pluginDir && typeof resolveData?.request === "string") resolveData.request = rewriteMpxWebpackPluginRequests(resolveData.request, pluginDir);
|
|
2645
|
+
});
|
|
2646
|
+
});
|
|
2647
|
+
targetCompiler.hooks?.compilation?.tap?.(pluginName, (compilation) => {
|
|
2648
|
+
const compilationPluginDir = resolveMpxWebpackPluginCompilationOwnerDir(targetCompiler, compilation, activePluginDir);
|
|
2649
|
+
if (compilationPluginDir) {
|
|
2650
|
+
activePluginDir = compilationPluginDir;
|
|
2651
|
+
patchMpxWebpackPluginNormalizeLib(targetCompiler, compilationPluginDir);
|
|
2652
|
+
ensureResolveLoaderAlias(targetCompiler, compilationPluginDir);
|
|
2653
|
+
const alias = targetCompiler.options?.resolve?.alias;
|
|
2654
|
+
if (alias) addMpxWebpackPluginAlias(alias, compilationPluginDir);
|
|
2655
|
+
}
|
|
2656
|
+
compilation.hooks?.childCompiler?.tap?.(pluginName, (childCompiler) => {
|
|
2657
|
+
install(childCompiler);
|
|
2658
|
+
});
|
|
2659
|
+
});
|
|
2660
|
+
};
|
|
2661
|
+
install(compiler);
|
|
2662
|
+
return true;
|
|
2307
2663
|
}
|
|
2308
2664
|
function isMpxWebpackPluginRequest(request) {
|
|
2309
2665
|
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
@@ -2316,20 +2672,33 @@ function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
|
2316
2672
|
const recordLoader = path.join(pkgDir, "lib/record-loader");
|
|
2317
2673
|
const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
|
|
2318
2674
|
const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
2319
|
-
if (Array.isArray(alias))
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2675
|
+
if (Array.isArray(alias)) {
|
|
2676
|
+
const entries = [
|
|
2677
|
+
{
|
|
2678
|
+
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
2679
|
+
alias: recordLoader
|
|
2680
|
+
},
|
|
2681
|
+
{
|
|
2682
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
2683
|
+
alias: styleCompiler
|
|
2684
|
+
},
|
|
2685
|
+
{
|
|
2686
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
2687
|
+
alias: stripConditionalLoader
|
|
2688
|
+
},
|
|
2689
|
+
{
|
|
2690
|
+
name: /^@mpxjs\/webpack-plugin\//,
|
|
2691
|
+
alias: pkgDir
|
|
2692
|
+
}
|
|
2693
|
+
];
|
|
2694
|
+
const managedNames = new Set(entries.filter((entry) => typeof entry.name === "string").map((entry) => entry.name));
|
|
2695
|
+
const managedPatterns = new Set(entries.filter((entry) => entry.name instanceof RegExp).map((entry) => `${entry.name.source}/${entry.name.flags}`));
|
|
2696
|
+
for (let index = alias.length - 1; index >= 0; index--) {
|
|
2697
|
+
const name = alias[index]?.name;
|
|
2698
|
+
if (managedNames.has(name) || name instanceof RegExp && managedPatterns.has(`${name.source}/${name.flags}`)) alias.splice(index, 1);
|
|
2699
|
+
}
|
|
2700
|
+
alias.unshift(...entries);
|
|
2701
|
+
} else {
|
|
2333
2702
|
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
2334
2703
|
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
2335
2704
|
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
@@ -2343,27 +2712,42 @@ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
|
2343
2712
|
compiler.options.resolveLoader.alias = alias;
|
|
2344
2713
|
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
2345
2714
|
}
|
|
2346
|
-
function
|
|
2347
|
-
const
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
const
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2715
|
+
function installMpxResolveLoaderAlias(compiler, getMpxWebpackPluginDir) {
|
|
2716
|
+
const resolveOptionsHook = compiler?.resolverFactory?.hooks?.resolveOptions?.for?.("loader");
|
|
2717
|
+
if (!resolveOptionsHook?.tap) return;
|
|
2718
|
+
resolveOptionsHook.tap({
|
|
2719
|
+
name: "weapp-tailwindcss-mpx-loader-resolve",
|
|
2720
|
+
stage: 100
|
|
2721
|
+
}, (resolveOptions) => {
|
|
2722
|
+
const mpxWebpackPluginDir = getMpxWebpackPluginDir();
|
|
2723
|
+
if (!mpxWebpackPluginDir) return resolveOptions;
|
|
2724
|
+
const alias = Array.isArray(resolveOptions.alias) ? [...resolveOptions.alias] : { ...resolveOptions.alias };
|
|
2725
|
+
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
2726
|
+
return {
|
|
2727
|
+
...resolveOptions,
|
|
2728
|
+
alias
|
|
2729
|
+
};
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
function patchMpxLoaderResolver(resolver, getMpxWebpackPluginDir) {
|
|
2733
|
+
const originalResolve = resolver?.resolve;
|
|
2734
|
+
if (typeof originalResolve !== "function" || originalResolve.__weappTwPatched) return;
|
|
2735
|
+
const wrappedResolve = function(...args) {
|
|
2736
|
+
const requestIndex = typeof args[0] === "string" ? 1 : 2;
|
|
2737
|
+
const request = args[requestIndex];
|
|
2738
|
+
const mpxWebpackPluginDir = getMpxWebpackPluginDir();
|
|
2739
|
+
if (mpxWebpackPluginDir && typeof request === "string" && isMpxWebpackPluginRequest(request)) args[requestIndex] = resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir);
|
|
2740
|
+
return originalResolve.apply(this, args);
|
|
2741
|
+
};
|
|
2742
|
+
wrappedResolve.__weappTwPatched = true;
|
|
2743
|
+
wrappedResolve.__weappTwOriginal = originalResolve;
|
|
2744
|
+
resolver.resolve = wrappedResolve;
|
|
2360
2745
|
}
|
|
2361
|
-
function patchMpxWebpackPluginNormalizeLib(
|
|
2746
|
+
function patchMpxWebpackPluginNormalizeLib(_compiler, mpxWebpackPluginDir) {
|
|
2362
2747
|
if (!mpxWebpackPluginDir) return false;
|
|
2363
|
-
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
2364
2748
|
let normalize;
|
|
2365
2749
|
try {
|
|
2366
|
-
normalize =
|
|
2750
|
+
normalize = createRequire(path.join(mpxWebpackPluginDir, "package.json"))(path.join(mpxWebpackPluginDir, "lib/utils/normalize"));
|
|
2367
2751
|
} catch {
|
|
2368
2752
|
return false;
|
|
2369
2753
|
}
|
|
@@ -2381,6 +2765,7 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
|
2381
2765
|
compiler.options.resolve = compiler.options.resolve || {};
|
|
2382
2766
|
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
2383
2767
|
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
2768
|
+
patchMpxWebpackPluginRequests(compiler, mpxWebpackPluginDir);
|
|
2384
2769
|
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
2385
2770
|
const alias = compiler.options.resolve.alias ?? {};
|
|
2386
2771
|
compiler.options.resolve.alias = alias;
|
|
@@ -2399,19 +2784,31 @@ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
|
2399
2784
|
return tailwindcssCssEntry;
|
|
2400
2785
|
}
|
|
2401
2786
|
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
2402
|
-
if (!enabled
|
|
2403
|
-
const originalResolve = loaderContext.resolve;
|
|
2404
|
-
if (originalResolve.__weappTwPatched) return;
|
|
2787
|
+
if (!enabled) return;
|
|
2405
2788
|
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
2406
|
-
const
|
|
2407
|
-
const
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2789
|
+
const getMpxWebpackPluginDir = () => resolveMpxWebpackPluginDir(loaderContext);
|
|
2790
|
+
const originalResolve = loaderContext.resolve;
|
|
2791
|
+
if (typeof originalResolve === "function" && !originalResolve.__weappTwPatched) {
|
|
2792
|
+
const wrappedResolve = function(context, request, callback) {
|
|
2793
|
+
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
2794
|
+
if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
|
|
2795
|
+
const mpxWebpackPluginDir = getMpxWebpackPluginDir();
|
|
2796
|
+
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
2797
|
+
return originalResolve.call(this, context, request, callback);
|
|
2798
|
+
};
|
|
2799
|
+
wrappedResolve.__weappTwPatched = true;
|
|
2800
|
+
loaderContext.resolve = wrappedResolve;
|
|
2801
|
+
}
|
|
2802
|
+
const originalImportModule = loaderContext.importModule;
|
|
2803
|
+
if (typeof originalImportModule === "function" && !originalImportModule.__weappTwPatched) {
|
|
2804
|
+
const wrappedImportModule = function(request, ...args) {
|
|
2805
|
+
const mpxWebpackPluginDir = getMpxWebpackPluginDir();
|
|
2806
|
+
const resolvedRequest = mpxWebpackPluginDir && typeof request === "string" ? rewriteMpxWebpackPluginRequests(request, mpxWebpackPluginDir) : request;
|
|
2807
|
+
return originalImportModule.call(this, resolvedRequest, ...args);
|
|
2808
|
+
};
|
|
2809
|
+
wrappedImportModule.__weappTwPatched = true;
|
|
2810
|
+
loaderContext.importModule = wrappedImportModule;
|
|
2811
|
+
}
|
|
2415
2812
|
}
|
|
2416
2813
|
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
2417
2814
|
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
@@ -2478,7 +2875,7 @@ function createDefaultLoaderAnchorFinders() {
|
|
|
2478
2875
|
//#endregion
|
|
2479
2876
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
2480
2877
|
function setupWebpackV5Loaders(options) {
|
|
2481
|
-
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, loaderAnchorFinders = createDefaultLoaderAnchorFinders(), mpxCssImportRewrite = false, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
2878
|
+
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, updateWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, loaderAnchorFinders = createDefaultLoaderAnchorFinders(), mpxCssImportRewrite = false, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
2482
2879
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(compilerOptions.generator, {
|
|
2483
2880
|
appType: compilerOptions.appType,
|
|
2484
2881
|
platform: compilerOptions.cssOptions?.platform ?? compilerOptions.platform,
|
|
@@ -2496,11 +2893,14 @@ function setupWebpackV5Loaders(options) {
|
|
|
2496
2893
|
if (shouldRewriteCssImports && mpxCssImportRewrite) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
2497
2894
|
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
2498
2895
|
const shouldInjectRuntimeClassSetLoader = !generatorBranch.isWeb;
|
|
2499
|
-
const
|
|
2896
|
+
const shouldInjectCssGenerationLoader = generatorOptions.enabled && runtimeState.tailwindRuntime.majorVersion === 4 && (generatorTarget === "web" || generatorTarget === "weapp");
|
|
2897
|
+
const shouldInjectCssImportRewriteLoader = shouldRewriteCssImports || shouldInjectCssGenerationLoader;
|
|
2898
|
+
const runtimeCssGenerationLoader = shouldInjectCssGenerationLoader ? path.resolve(__dirname, "./weapp-tw-css-generation-loader.js") : void 0;
|
|
2500
2899
|
const runtimeCssImportRewriteLoader = shouldInjectCssImportRewriteLoader ? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
2501
2900
|
const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
|
|
2901
|
+
const runtimeCssGenerationLoaderExists = runtimeCssGenerationLoader ? fs.existsSync(runtimeCssGenerationLoader) : false;
|
|
2502
2902
|
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
2503
|
-
const runtimeLoaderRewriteOptions = shouldInjectCssImportRewriteLoader ? {
|
|
2903
|
+
const runtimeLoaderRewriteOptions = shouldInjectCssImportRewriteLoader || shouldInjectCssGenerationLoader ? {
|
|
2504
2904
|
pkgDir: weappTailwindcssPackageDir,
|
|
2505
2905
|
compilerOptions,
|
|
2506
2906
|
runtimeState,
|
|
@@ -2515,7 +2915,8 @@ function setupWebpackV5Loaders(options) {
|
|
|
2515
2915
|
classSet: {
|
|
2516
2916
|
getClassSet: getClassSetInLoader,
|
|
2517
2917
|
getWatchDependencies: getRuntimeWatchDependencies,
|
|
2518
|
-
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile }
|
|
2918
|
+
...registerWebpackCssSourceFile === void 0 ? {} : { registerCssSourceFile: registerWebpackCssSourceFile },
|
|
2919
|
+
...updateWebpackGeneratedCss === void 0 ? {} : { updateGeneratedCss: updateWebpackGeneratedCss }
|
|
2519
2920
|
},
|
|
2520
2921
|
...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
|
|
2521
2922
|
});
|
|
@@ -2525,7 +2926,11 @@ function setupWebpackV5Loaders(options) {
|
|
|
2525
2926
|
compiler.hooks.watchClose?.tap?.(pluginName, cleanupWebpackLoaderRuntime);
|
|
2526
2927
|
compiler.hooks.shutdown?.tap?.(pluginName, cleanupWebpackLoaderRuntime);
|
|
2527
2928
|
const { findRewriteAnchor, findClassSetAnchor } = loaderAnchorFinders;
|
|
2528
|
-
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
2929
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions && shouldInjectCssImportRewriteLoader ? {
|
|
2930
|
+
generateCss: false,
|
|
2931
|
+
tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey
|
|
2932
|
+
} : void 0;
|
|
2933
|
+
const cssGenerationLoaderOptions = runtimeLoaderRewriteOptions && shouldInjectCssGenerationLoader ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
2529
2934
|
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && mpxCssImportRewrite) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
2530
2935
|
const createRuntimeClassSetLoaderEntry = () => ({
|
|
2531
2936
|
loader: runtimeClassSetLoader,
|
|
@@ -2542,15 +2947,31 @@ function setupWebpackV5Loaders(options) {
|
|
|
2542
2947
|
type: null
|
|
2543
2948
|
};
|
|
2544
2949
|
};
|
|
2950
|
+
const createCssGenerationLoaderEntry = () => {
|
|
2951
|
+
if (!runtimeCssGenerationLoader || !cssGenerationLoaderOptions) return null;
|
|
2952
|
+
return {
|
|
2953
|
+
loader: runtimeCssGenerationLoader,
|
|
2954
|
+
options: cssGenerationLoaderOptions,
|
|
2955
|
+
ident: null,
|
|
2956
|
+
type: null
|
|
2957
|
+
};
|
|
2958
|
+
};
|
|
2545
2959
|
const { NormalModule } = compiler.webpack;
|
|
2546
2960
|
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
2547
|
-
NormalModule.getCompilationHooks(compilation).loader.tap(
|
|
2548
|
-
|
|
2961
|
+
NormalModule.getCompilationHooks(compilation).loader.tap({
|
|
2962
|
+
name: pluginName,
|
|
2963
|
+
stage: 100
|
|
2964
|
+
}, (_loaderContext, module) => {
|
|
2965
|
+
if (!(runtimeClassSetLoaderExists || runtimeCssGenerationLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
|
|
2549
2966
|
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && mpxCssImportRewrite);
|
|
2550
2967
|
const loaderEntries = module.loaders || [];
|
|
2551
2968
|
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
2552
2969
|
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
2553
2970
|
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
2971
|
+
if (isCssModule) {
|
|
2972
|
+
const frameworkPostcssOptions = collectFrameworkPostcssOptionsFromLoaderEntries(loaderEntries, _loaderContext);
|
|
2973
|
+
if (frameworkPostcssOptions) captureResolvedFrameworkPostcssOptions(compilerOptions, frameworkPostcssOptions);
|
|
2974
|
+
}
|
|
2554
2975
|
if (isCssModule && typeof module.resource === "string") markWebpackCssSourceModule?.(module.resource);
|
|
2555
2976
|
if (process.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
|
|
2556
2977
|
rewriteAnchorIdx,
|
|
@@ -2565,6 +2986,12 @@ function setupWebpackV5Loaders(options) {
|
|
|
2565
2986
|
if (position === "after") loaderEntries.push(entry);
|
|
2566
2987
|
else loaderEntries.unshift(entry);
|
|
2567
2988
|
};
|
|
2989
|
+
if (cssGenerationLoaderOptions && runtimeCssGenerationLoaderExists && runtimeCssGenerationLoader && isCssModule && !hasLoaderEntry(loaderEntries, runtimeCssGenerationLoader)) {
|
|
2990
|
+
const generationLoaderEntry = createCssGenerationLoaderEntry();
|
|
2991
|
+
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
2992
|
+
if (generationLoaderEntry) if (anchorIndex === -1) anchorlessInsert(generationLoaderEntry, "after");
|
|
2993
|
+
else loaderEntries.splice(anchorIndex + 1, 0, generationLoaderEntry);
|
|
2994
|
+
}
|
|
2568
2995
|
if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader && isCssModule) {
|
|
2569
2996
|
const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
|
|
2570
2997
|
const rewriteLoaderEntry = existingIndex !== -1 ? {
|
|
@@ -2592,7 +3019,7 @@ function setupWebpackV5Loaders(options) {
|
|
|
2592
3019
|
});
|
|
2593
3020
|
}
|
|
2594
3021
|
//#endregion
|
|
2595
|
-
//#region src/bundlers/webpack/shared/create-framework-plugin.ts
|
|
3022
|
+
//#region src/bundlers/webpack/shared/create-framework-plugin/watch-output.ts
|
|
2596
3023
|
const debug = createDebug();
|
|
2597
3024
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
2598
3025
|
const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
|
|
@@ -2658,6 +3085,8 @@ function setupWebpackWatchOutputIgnore(compiler) {
|
|
|
2658
3085
|
}
|
|
2659
3086
|
});
|
|
2660
3087
|
}
|
|
3088
|
+
//#endregion
|
|
3089
|
+
//#region src/bundlers/webpack/shared/create-framework-plugin/plugin.ts
|
|
2661
3090
|
function isInternalUserDefinedOptions(options) {
|
|
2662
3091
|
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
2663
3092
|
}
|
|
@@ -2803,6 +3232,15 @@ var WebpackFrameworkPlugin = class {
|
|
|
2803
3232
|
});
|
|
2804
3233
|
currentWebpackCssSourceFiles.add(file);
|
|
2805
3234
|
};
|
|
3235
|
+
const updateWebpackGeneratedCss = (source) => {
|
|
3236
|
+
const file = path.resolve(source.file);
|
|
3237
|
+
const previous = webpackGeneratedCssSources.get(file);
|
|
3238
|
+
if (!previous) return;
|
|
3239
|
+
webpackGeneratedCssSources.set(file, {
|
|
3240
|
+
...previous,
|
|
3241
|
+
css: source.css
|
|
3242
|
+
});
|
|
3243
|
+
};
|
|
2806
3244
|
const pruneWebpackCssSources = (activeSourceFiles, _options = {}) => {
|
|
2807
3245
|
const tailwindOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
2808
3246
|
const configuredSourceFiles = /* @__PURE__ */ new Set();
|
|
@@ -2880,6 +3318,7 @@ var WebpackFrameworkPlugin = class {
|
|
|
2880
3318
|
markWebpackCssSourceModule,
|
|
2881
3319
|
registerWebpackCssSourceFile,
|
|
2882
3320
|
registerWebpackGeneratedCss,
|
|
3321
|
+
updateWebpackGeneratedCss,
|
|
2883
3322
|
getRuntimeWatchDependencies() {
|
|
2884
3323
|
return {
|
|
2885
3324
|
files: runtimeWatchDependencyFiles,
|