weapp-tailwindcss 5.1.7 → 5.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundlers/framework-selector.d.ts +26 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +6 -0
- package/dist/bundlers/gulp/index.d.ts +4 -4
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +6 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/generic/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/taro/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/uni-app-x/index.d.ts +2 -0
- package/dist/bundlers/vite/frameworks/weapp-vite/index.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +2 -2
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
- package/dist/bundlers/vite/index.d.ts +2 -4
- package/dist/bundlers/vite/processed-css-assets.d.ts +5 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +35 -0
- package/dist/bundlers/vite/shared/framework-strategy.d.ts +88 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -2
- package/dist/bundlers/webpack/frameworks/generic/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/index.d.ts +8 -0
- package/dist/bundlers/webpack/frameworks/mpx/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/taro/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/uni-app/index.d.ts +5 -0
- package/dist/bundlers/webpack/frameworks/weapp-vite/index.d.ts +5 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +21 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +4 -3
- package/dist/cli.js +8 -0
- package/dist/cli.mjs +8 -0
- package/dist/{context-C7KTDlrG.js → context-CRhUs_5e.js} +11 -3
- package/dist/{context-BqeDu1Ha.mjs → context-CfXr3hWz.mjs} +11 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-DASZwC6t.js → generator-DaaFxR5V.js} +1 -1
- package/dist/{generator-BOt2Tvx3.mjs → generator-DugIHBgl.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-alDZryyB.mjs → gulp-CRjkPsbX.mjs} +22 -7
- package/dist/{gulp-D6hsaTLM.js → gulp-JUfnhOOo.js} +22 -7
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-CYwVMRol.mjs → hmr-timing-BecOXMd8.mjs} +5 -5
- package/dist/{hmr-timing-BIr_CiPW.js → hmr-timing-DcIEXnf8.js} +5 -5
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-Djr2Hw8y.js → source-candidate-scan-signature-10tvdJVC.js} +185 -98
- package/dist/{source-candidate-scan-signature-D97ZEXcj.mjs → source-candidate-scan-signature-DAg8QSgh.mjs} +162 -99
- package/dist/style-injector/internal.d.ts +18 -4
- package/dist/{tailwindcss-DPxJpRVP.js → tailwindcss-BZjZZi60.js} +1 -1
- package/dist/{tailwindcss-DDGD90w7.mjs → tailwindcss-PA2jHHpx.mjs} +1 -1
- package/dist/{transform-CvqqZBuq.js → transform-B0BxX3XB.js} +1 -1
- package/dist/{transform-DPPr79r2.mjs → transform-wNEbcZeQ.mjs} +1 -1
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v4-engine-3UmJkAY7.js → v4-engine-BZP2462H.js} +12 -0
- package/dist/{v4-engine-CYSrDVNp.mjs → v4-engine-CjjWONB0.mjs} +12 -0
- package/dist/{vite-BJRlG835.js → vite-GdzlG_lx.js} +1286 -818
- package/dist/{vite-XxJh7Xtu.mjs → vite-vf2-cDdk.mjs} +1284 -816
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +21 -1
- package/dist/{webpack-eN8WzIT-.mjs → webpack-2s-TFhgm.mjs} +321 -216
- package/dist/{webpack-BxBOMUtY.js → webpack-BhM4Hqla.js} +320 -215
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as hasTailwindGeneratedCssMarkers, A as stripTailwindSourceMediaFragments, C as isCommentOnlyCss, D as removeTailwindV4GeneratorAtRules, Dt as inferGeneratorTargetFromEnv, E as removeTailwindV4GeneratedUserCssArtifacts, F as pruneMiniProgramGeneratedCss, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, N as finalizeMiniProgramCss, Q as hasTailwindGeneratedCss, T as removeMiniProgramHoverSelectors, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, bt as resolveSourceScanPath, j as stripUnmatchedTailwindSourceMediaCloseFragments, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, s as upsertTailwindV4CssSource, z as hasTailwindApplyDirective } from "./v4-engine-
|
|
2
|
-
import { o as resolveRuntimeBranch } from "./generator-
|
|
1
|
+
import { $ as hasTailwindGeneratedCssMarkers, A as stripTailwindSourceMediaFragments, C as isCommentOnlyCss, D as removeTailwindV4GeneratorAtRules, Dt as inferGeneratorTargetFromEnv, E as removeTailwindV4GeneratedUserCssArtifacts, F as pruneMiniProgramGeneratedCss, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, N as finalizeMiniProgramCss, Q as hasTailwindGeneratedCss, T as removeMiniProgramHoverSelectors, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, bt as resolveSourceScanPath, j as stripUnmatchedTailwindSourceMediaCloseFragments, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, s as upsertTailwindV4CssSource, z as hasTailwindApplyDirective } from "./v4-engine-CjjWONB0.mjs";
|
|
2
|
+
import { o as resolveRuntimeBranch } from "./generator-DugIHBgl.mjs";
|
|
3
3
|
import { r as getGroupedEntries } from "./utils-DodxWHGz.mjs";
|
|
4
|
-
import { S as createDebug, b as ensureRuntimeClassSet, f as _defineProperty, i as pluginName, l as shouldSkipJsTransform, n as normalizeStyleHandlerMajorVersion, r as resolveStyleOptionsFromContext, t as getCompilerContext, w as md5Hash, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-
|
|
5
|
-
import { g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-
|
|
6
|
-
import { C as hasMiniProgramTailwindV4PreflightReset, D as isCssSourceTraceEnabled, E as createCssTokenSourceMap, O as processCachedTask, S as createCssSourceOrderAppend, T as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, b as scoreTailwindV4CssSourceFileMatch, c as collectStrictEscapedRuntimeCandidates, f as pushConcurrentTaskFactories, i as createSourceCandidateStore, l as createEscapeFragments, n as emitHmrTiming, o as resolveSourceCandidateScanFiles, p as resolveTaskConcurrency, s as createBundleRuntimeClassSetManager, w as annotateCssSourceTrace, x as removeGeneratedSelectorCompatCss } from "./hmr-timing-
|
|
7
|
-
import { A as
|
|
4
|
+
import { S as createDebug, b as ensureRuntimeClassSet, f as _defineProperty, i as pluginName, l as shouldSkipJsTransform, n as normalizeStyleHandlerMajorVersion, r as resolveStyleOptionsFromContext, t as getCompilerContext, w as md5Hash, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-CfXr3hWz.mjs";
|
|
5
|
+
import { g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-PA2jHHpx.mjs";
|
|
6
|
+
import { C as hasMiniProgramTailwindV4PreflightReset, D as isCssSourceTraceEnabled, E as createCssTokenSourceMap, O as processCachedTask, S as createCssSourceOrderAppend, T as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, b as scoreTailwindV4CssSourceFileMatch, c as collectStrictEscapedRuntimeCandidates, f as pushConcurrentTaskFactories, i as createSourceCandidateStore, l as createEscapeFragments, n as emitHmrTiming, o as resolveSourceCandidateScanFiles, p as resolveTaskConcurrency, s as createBundleRuntimeClassSetManager, w as annotateCssSourceTrace, x as removeGeneratedSelectorCompatCss } from "./hmr-timing-BecOXMd8.mjs";
|
|
7
|
+
import { A as hasBundlerGeneratedCssMarker, B as resolveWebpackFrameworkProfile, C as generateTailwindV4Css, D as resolveOutputSpecifier, I as createBuiltinWebpackStyleInjectorPlugin, M as stripBundlerGeneratedCssMarkers, N as resolvePackageDir, O as toAbsoluteOutputPath, P as resolvePluginDisabledState, R as webpackStyleInjectorDelegates, T as stripRequestQuery, b as createRuntimeAffectingSourceSignature, d as classifyBundleEntry, f as createBundleBuildState, i as createCandidateSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, t as createSourceCandidateScanSignature, w as isSourceStyleRequest } from "./source-candidate-scan-signature-DAg8QSgh.mjs";
|
|
8
8
|
import Module, { createRequire } from "node:module";
|
|
9
9
|
import fs from "node:fs";
|
|
10
10
|
import path from "node:path";
|
|
@@ -14,188 +14,7 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
14
14
|
import micromatch from "micromatch";
|
|
15
15
|
import { MappingChars2String } from "@weapp-core/escape";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
//#region src/shared/tailwindcss-css-redirect.ts
|
|
18
|
-
const moduleWithMutableResolve = Module;
|
|
19
|
-
const patched = /* @__PURE__ */ new WeakSet();
|
|
20
|
-
function installTailwindcssCssRedirect(pkgDir) {
|
|
21
|
-
const target = path.join(pkgDir, "index.css");
|
|
22
|
-
const original = moduleWithMutableResolve._resolveFilename;
|
|
23
|
-
if (patched.has(original)) return;
|
|
24
|
-
const replacements = /* @__PURE__ */ new Set(["tailwindcss", "tailwindcss$"]);
|
|
25
|
-
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
26
|
-
if (replacements.has(request)) return target;
|
|
27
|
-
if (request.startsWith("tailwindcss/")) return path.join(pkgDir, request.slice(12));
|
|
28
|
-
return original(request, parent, isMain, options);
|
|
29
|
-
};
|
|
30
|
-
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
31
|
-
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/shared/mpx.ts
|
|
35
|
-
const localRequire = createRequire(import.meta.url);
|
|
36
|
-
const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
|
|
37
|
-
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
38
|
-
function isMpxStyleResourceQuery(query) {
|
|
39
|
-
if (typeof query !== "string") return false;
|
|
40
|
-
return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
|
|
41
|
-
}
|
|
42
|
-
function isMpx(appType) {
|
|
43
|
-
return appType === "mpx";
|
|
44
|
-
}
|
|
45
|
-
function getTailwindcssCssEntry(pkgDir) {
|
|
46
|
-
return path.join(pkgDir, "index.css");
|
|
47
|
-
}
|
|
48
|
-
function resolveMpxWebpackPluginDir(compiler) {
|
|
49
|
-
const candidates = [
|
|
50
|
-
compiler?.context,
|
|
51
|
-
compiler?.options?.context,
|
|
52
|
-
process.cwd()
|
|
53
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
54
|
-
for (const candidate of candidates) try {
|
|
55
|
-
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
56
|
-
return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
57
|
-
} catch {}
|
|
58
|
-
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
59
|
-
if (cachedPackageJson) return path.dirname(cachedPackageJson);
|
|
60
|
-
try {
|
|
61
|
-
return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
62
|
-
} catch {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function isMpxWebpackPluginRequest(request) {
|
|
67
|
-
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
68
|
-
}
|
|
69
|
-
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
70
|
-
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
71
|
-
return path.join(mpxWebpackPluginDir, request.slice(22));
|
|
72
|
-
}
|
|
73
|
-
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
74
|
-
const recordLoader = path.join(pkgDir, "lib/record-loader");
|
|
75
|
-
const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
|
|
76
|
-
const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
77
|
-
if (Array.isArray(alias)) alias.push({
|
|
78
|
-
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
79
|
-
alias: recordLoader
|
|
80
|
-
}, {
|
|
81
|
-
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
82
|
-
alias: styleCompiler
|
|
83
|
-
}, {
|
|
84
|
-
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
85
|
-
alias: stripConditionalLoader
|
|
86
|
-
}, {
|
|
87
|
-
name: /^@mpxjs\/webpack-plugin\//,
|
|
88
|
-
alias: pkgDir
|
|
89
|
-
});
|
|
90
|
-
else {
|
|
91
|
-
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
92
|
-
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
93
|
-
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
94
|
-
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
95
|
-
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
99
|
-
compiler.options.resolveLoader = compiler.options.resolveLoader || {};
|
|
100
|
-
const alias = compiler.options.resolveLoader.alias ?? {};
|
|
101
|
-
compiler.options.resolveLoader.alias = alias;
|
|
102
|
-
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
103
|
-
}
|
|
104
|
-
function resolveMpxWebpackPluginRequire(compiler) {
|
|
105
|
-
const candidates = [
|
|
106
|
-
compiler?.context,
|
|
107
|
-
compiler?.options?.context,
|
|
108
|
-
process.cwd()
|
|
109
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
110
|
-
for (const candidate of candidates) try {
|
|
111
|
-
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
112
|
-
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
113
|
-
return projectRequire;
|
|
114
|
-
} catch {}
|
|
115
|
-
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
116
|
-
if (cachedPackageJson) return createRequire(cachedPackageJson);
|
|
117
|
-
return localRequire;
|
|
118
|
-
}
|
|
119
|
-
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
120
|
-
if (!mpxWebpackPluginDir) return false;
|
|
121
|
-
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
122
|
-
let normalize;
|
|
123
|
-
try {
|
|
124
|
-
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
125
|
-
} catch {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
if (typeof normalize.lib !== "function") return false;
|
|
129
|
-
if (normalize.lib.__weappTwPatched) return true;
|
|
130
|
-
const wrappedLib = (file) => path.join(mpxWebpackPluginDir, "lib", file);
|
|
131
|
-
wrappedLib.__weappTwPatched = true;
|
|
132
|
-
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
133
|
-
normalize.lib = wrappedLib;
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
137
|
-
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
138
|
-
compiler.options = compiler.options || {};
|
|
139
|
-
compiler.options.resolve = compiler.options.resolve || {};
|
|
140
|
-
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
141
|
-
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
142
|
-
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
143
|
-
const alias = compiler.options.resolve.alias ?? {};
|
|
144
|
-
compiler.options.resolve.alias = alias;
|
|
145
|
-
if (Array.isArray(alias)) alias.push({
|
|
146
|
-
name: "tailwindcss",
|
|
147
|
-
alias: tailwindcssCssEntry
|
|
148
|
-
}, {
|
|
149
|
-
name: "tailwindcss$",
|
|
150
|
-
alias: tailwindcssCssEntry
|
|
151
|
-
});
|
|
152
|
-
else {
|
|
153
|
-
alias.tailwindcss = tailwindcssCssEntry;
|
|
154
|
-
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
155
|
-
}
|
|
156
|
-
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
157
|
-
return tailwindcssCssEntry;
|
|
158
|
-
}
|
|
159
|
-
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
160
|
-
if (!enabled || typeof loaderContext.resolve !== "function") return;
|
|
161
|
-
const originalResolve = loaderContext.resolve;
|
|
162
|
-
if (originalResolve.__weappTwPatched) return;
|
|
163
|
-
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
164
|
-
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
165
|
-
const wrappedResolve = function(context, request, callback) {
|
|
166
|
-
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
167
|
-
if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
|
|
168
|
-
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
169
|
-
return originalResolve.call(this, context, request, callback);
|
|
170
|
-
};
|
|
171
|
-
wrappedResolve.__weappTwPatched = true;
|
|
172
|
-
loaderContext.resolve = wrappedResolve;
|
|
173
|
-
}
|
|
174
|
-
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
175
|
-
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
176
|
-
}
|
|
177
|
-
const CSS_EXT_RE = /\.css$/i;
|
|
178
|
-
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
179
|
-
var _compiler$options;
|
|
180
|
-
if (!loader) return;
|
|
181
|
-
const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
|
|
182
|
-
moduleOptions.rules = moduleOptions.rules || [];
|
|
183
|
-
const createRule = (match) => ({
|
|
184
|
-
...match,
|
|
185
|
-
enforce: "pre",
|
|
186
|
-
use: [{
|
|
187
|
-
loader,
|
|
188
|
-
options: loaderOptions
|
|
189
|
-
}]
|
|
190
|
-
});
|
|
191
|
-
moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
|
|
192
|
-
test: CSS_EXT_RE,
|
|
193
|
-
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
194
|
-
}));
|
|
195
|
-
}
|
|
196
|
-
//#endregion
|
|
197
17
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
|
|
198
|
-
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
|
|
199
18
|
function getCacheKey(filename) {
|
|
200
19
|
return filename;
|
|
201
20
|
}
|
|
@@ -203,12 +22,11 @@ function stripResourceQuery(resource) {
|
|
|
203
22
|
if (typeof resource !== "string") return resource;
|
|
204
23
|
return stripRequestQuery(resource);
|
|
205
24
|
}
|
|
206
|
-
function isCssLikeModuleResource(resource, cssMatcher
|
|
25
|
+
function isCssLikeModuleResource(resource, cssMatcher) {
|
|
207
26
|
if (typeof resource !== "string") return false;
|
|
208
27
|
const normalizedResource = stripResourceQuery(resource);
|
|
209
28
|
if (normalizedResource && cssMatcher(normalizedResource)) return true;
|
|
210
29
|
if (isSourceStyleRequest(resource)) return true;
|
|
211
|
-
if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
|
|
212
30
|
return false;
|
|
213
31
|
}
|
|
214
32
|
function hasLoaderEntry(entries, target) {
|
|
@@ -352,6 +170,11 @@ function hasMissingRuntimeCandidates(classSet, candidates) {
|
|
|
352
170
|
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate) && !classSet.has(candidate)) return true;
|
|
353
171
|
return false;
|
|
354
172
|
}
|
|
173
|
+
function hasStaleRuntimeCandidates(classSet, candidates) {
|
|
174
|
+
if (!classSet || !candidates) return false;
|
|
175
|
+
for (const candidate of classSet) if (isRuntimeTransformCandidate(candidate) && !candidates.has(candidate)) return true;
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
355
178
|
function resolveGeneratedCssRuntimeCandidates(source, fallbackClassSet) {
|
|
356
179
|
const classSet = collectGeneratedCssRuntimeCandidates(source);
|
|
357
180
|
if (classSet.size > 0 || fallbackClassSet === void 0) return classSet;
|
|
@@ -392,7 +215,7 @@ function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
|
|
|
392
215
|
}
|
|
393
216
|
function shouldConsumeWebpackLoaderGeneratedCss(options) {
|
|
394
217
|
if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
|
|
395
|
-
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
|
|
218
|
+
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && (hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) || hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates))) return false;
|
|
396
219
|
return options.hasBundlerGeneratedCssMarker;
|
|
397
220
|
}
|
|
398
221
|
function hasUsableWebpackGeneratorCssSources(cssSources) {
|
|
@@ -2230,11 +2053,188 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
2230
2053
|
});
|
|
2231
2054
|
}
|
|
2232
2055
|
//#endregion
|
|
2233
|
-
//#region ../../node_modules/.pnpm/tsdown@0.22.3_oxc-resolver@11.20.0_tsx@4.
|
|
2056
|
+
//#region ../../node_modules/.pnpm/tsdown@0.22.3_oxc-resolver@11.20.0_tsx@4.23.0_typescript@6.0.3_unrun@0.2.37_synckit@0.1_d637bff48b9176e0fee6cca26dd9f301/node_modules/tsdown/esm-shims.js
|
|
2234
2057
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
2235
2058
|
const getDirname = () => path.dirname(getFilename());
|
|
2236
2059
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
2237
2060
|
//#endregion
|
|
2061
|
+
//#region src/shared/tailwindcss-css-redirect.ts
|
|
2062
|
+
const moduleWithMutableResolve = Module;
|
|
2063
|
+
const patched = /* @__PURE__ */ new WeakSet();
|
|
2064
|
+
function installTailwindcssCssRedirect(pkgDir) {
|
|
2065
|
+
const target = path.join(pkgDir, "index.css");
|
|
2066
|
+
const original = moduleWithMutableResolve._resolveFilename;
|
|
2067
|
+
if (patched.has(original)) return;
|
|
2068
|
+
const replacements = /* @__PURE__ */ new Set(["tailwindcss", "tailwindcss$"]);
|
|
2069
|
+
const resolveTailwindcssCss = (request, parent, isMain, options) => {
|
|
2070
|
+
if (replacements.has(request)) return target;
|
|
2071
|
+
if (request.startsWith("tailwindcss/")) return path.join(pkgDir, request.slice(12));
|
|
2072
|
+
return original(request, parent, isMain, options);
|
|
2073
|
+
};
|
|
2074
|
+
moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
|
|
2075
|
+
patched.add(moduleWithMutableResolve._resolveFilename);
|
|
2076
|
+
}
|
|
2077
|
+
//#endregion
|
|
2078
|
+
//#region src/shared/mpx.ts
|
|
2079
|
+
const localRequire = createRequire(import.meta.url);
|
|
2080
|
+
const MPX_STYLE_RESOURCE_QUERY_RE = /(?:^|[?&])type=styles(?:&|$)/;
|
|
2081
|
+
const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
|
|
2082
|
+
function isMpxStyleResourceQuery(query) {
|
|
2083
|
+
if (typeof query !== "string") return false;
|
|
2084
|
+
return MPX_STYLE_RESOURCE_QUERY_RE.test(query);
|
|
2085
|
+
}
|
|
2086
|
+
function getTailwindcssCssEntry(pkgDir) {
|
|
2087
|
+
return path.join(pkgDir, "index.css");
|
|
2088
|
+
}
|
|
2089
|
+
function resolveMpxWebpackPluginDir(compiler) {
|
|
2090
|
+
const candidates = [
|
|
2091
|
+
compiler?.context,
|
|
2092
|
+
compiler?.options?.context,
|
|
2093
|
+
process.cwd()
|
|
2094
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
2095
|
+
for (const candidate of candidates) try {
|
|
2096
|
+
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
2097
|
+
return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
2098
|
+
} catch {}
|
|
2099
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
2100
|
+
if (cachedPackageJson) return path.dirname(cachedPackageJson);
|
|
2101
|
+
try {
|
|
2102
|
+
return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
|
|
2103
|
+
} catch {
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
function isMpxWebpackPluginRequest(request) {
|
|
2108
|
+
return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
|
|
2109
|
+
}
|
|
2110
|
+
function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
|
|
2111
|
+
if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
|
|
2112
|
+
return path.join(mpxWebpackPluginDir, request.slice(22));
|
|
2113
|
+
}
|
|
2114
|
+
function addMpxWebpackPluginAlias(alias, pkgDir) {
|
|
2115
|
+
const recordLoader = path.join(pkgDir, "lib/record-loader");
|
|
2116
|
+
const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
|
|
2117
|
+
const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
|
|
2118
|
+
if (Array.isArray(alias)) alias.push({
|
|
2119
|
+
name: "@mpxjs/webpack-plugin/lib/record-loader",
|
|
2120
|
+
alias: recordLoader
|
|
2121
|
+
}, {
|
|
2122
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
|
|
2123
|
+
alias: styleCompiler
|
|
2124
|
+
}, {
|
|
2125
|
+
name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
|
|
2126
|
+
alias: stripConditionalLoader
|
|
2127
|
+
}, {
|
|
2128
|
+
name: /^@mpxjs\/webpack-plugin\//,
|
|
2129
|
+
alias: pkgDir
|
|
2130
|
+
});
|
|
2131
|
+
else {
|
|
2132
|
+
alias["@mpxjs/webpack-plugin"] = pkgDir;
|
|
2133
|
+
alias["@mpxjs/webpack-plugin$"] = pkgDir;
|
|
2134
|
+
alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
|
|
2135
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
|
|
2136
|
+
alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
|
|
2140
|
+
compiler.options.resolveLoader = compiler.options.resolveLoader || {};
|
|
2141
|
+
const alias = compiler.options.resolveLoader.alias ?? {};
|
|
2142
|
+
compiler.options.resolveLoader.alias = alias;
|
|
2143
|
+
addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
2144
|
+
}
|
|
2145
|
+
function resolveMpxWebpackPluginRequire(compiler) {
|
|
2146
|
+
const candidates = [
|
|
2147
|
+
compiler?.context,
|
|
2148
|
+
compiler?.options?.context,
|
|
2149
|
+
process.cwd()
|
|
2150
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
2151
|
+
for (const candidate of candidates) try {
|
|
2152
|
+
const projectRequire = createRequire(path.join(candidate, "package.json"));
|
|
2153
|
+
projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
|
|
2154
|
+
return projectRequire;
|
|
2155
|
+
} catch {}
|
|
2156
|
+
const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
|
|
2157
|
+
if (cachedPackageJson) return createRequire(cachedPackageJson);
|
|
2158
|
+
return localRequire;
|
|
2159
|
+
}
|
|
2160
|
+
function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
|
|
2161
|
+
if (!mpxWebpackPluginDir) return false;
|
|
2162
|
+
const projectRequire = resolveMpxWebpackPluginRequire(compiler);
|
|
2163
|
+
let normalize;
|
|
2164
|
+
try {
|
|
2165
|
+
normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
|
|
2166
|
+
} catch {
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
if (typeof normalize.lib !== "function") return false;
|
|
2170
|
+
if (normalize.lib.__weappTwPatched) return true;
|
|
2171
|
+
const wrappedLib = (file) => path.join(mpxWebpackPluginDir, "lib", file);
|
|
2172
|
+
wrappedLib.__weappTwPatched = true;
|
|
2173
|
+
wrappedLib.__weappTwOriginal = normalize.lib;
|
|
2174
|
+
normalize.lib = wrappedLib;
|
|
2175
|
+
return true;
|
|
2176
|
+
}
|
|
2177
|
+
function ensureMpxTailwindcssAliases(compiler, pkgDir) {
|
|
2178
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
2179
|
+
compiler.options = compiler.options || {};
|
|
2180
|
+
compiler.options.resolve = compiler.options.resolve || {};
|
|
2181
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
|
|
2182
|
+
patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
|
|
2183
|
+
if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
|
|
2184
|
+
const alias = compiler.options.resolve.alias ?? {};
|
|
2185
|
+
compiler.options.resolve.alias = alias;
|
|
2186
|
+
if (Array.isArray(alias)) alias.push({
|
|
2187
|
+
name: "tailwindcss",
|
|
2188
|
+
alias: tailwindcssCssEntry
|
|
2189
|
+
}, {
|
|
2190
|
+
name: "tailwindcss$",
|
|
2191
|
+
alias: tailwindcssCssEntry
|
|
2192
|
+
});
|
|
2193
|
+
else {
|
|
2194
|
+
alias.tailwindcss = tailwindcssCssEntry;
|
|
2195
|
+
alias.tailwindcss$ = tailwindcssCssEntry;
|
|
2196
|
+
}
|
|
2197
|
+
if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
|
|
2198
|
+
return tailwindcssCssEntry;
|
|
2199
|
+
}
|
|
2200
|
+
function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
|
|
2201
|
+
if (!enabled || typeof loaderContext.resolve !== "function") return;
|
|
2202
|
+
const originalResolve = loaderContext.resolve;
|
|
2203
|
+
if (originalResolve.__weappTwPatched) return;
|
|
2204
|
+
const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
|
|
2205
|
+
const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
|
|
2206
|
+
const wrappedResolve = function(context, request, callback) {
|
|
2207
|
+
if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
|
|
2208
|
+
if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
|
|
2209
|
+
if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
|
|
2210
|
+
return originalResolve.call(this, context, request, callback);
|
|
2211
|
+
};
|
|
2212
|
+
wrappedResolve.__weappTwPatched = true;
|
|
2213
|
+
loaderContext.resolve = wrappedResolve;
|
|
2214
|
+
}
|
|
2215
|
+
function setupMpxTailwindcssRedirect(pkgDir, enabled) {
|
|
2216
|
+
if (enabled) installTailwindcssCssRedirect(pkgDir);
|
|
2217
|
+
}
|
|
2218
|
+
const CSS_EXT_RE = /\.css$/i;
|
|
2219
|
+
function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
|
|
2220
|
+
var _compiler$options;
|
|
2221
|
+
if (!loader) return;
|
|
2222
|
+
const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
|
|
2223
|
+
moduleOptions.rules = moduleOptions.rules || [];
|
|
2224
|
+
const createRule = (match) => ({
|
|
2225
|
+
...match,
|
|
2226
|
+
enforce: "pre",
|
|
2227
|
+
use: [{
|
|
2228
|
+
loader,
|
|
2229
|
+
options: loaderOptions
|
|
2230
|
+
}]
|
|
2231
|
+
});
|
|
2232
|
+
moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
|
|
2233
|
+
test: CSS_EXT_RE,
|
|
2234
|
+
resourceQuery: (query) => !isMpxStyleResourceQuery(query)
|
|
2235
|
+
}));
|
|
2236
|
+
}
|
|
2237
|
+
//#endregion
|
|
2238
2238
|
//#region src/bundlers/webpack/loaders/runtime-registry.ts
|
|
2239
2239
|
const runtimeRegistryHolder = globalThis;
|
|
2240
2240
|
const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
|
|
@@ -2261,11 +2261,13 @@ function createPrioritizedFinder(targets) {
|
|
|
2261
2261
|
return -1;
|
|
2262
2262
|
};
|
|
2263
2263
|
}
|
|
2264
|
-
function
|
|
2265
|
-
|
|
2264
|
+
function createMpxLoaderAnchorFinders() {
|
|
2265
|
+
return {
|
|
2266
2266
|
findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
|
|
2267
2267
|
findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
|
|
2268
2268
|
};
|
|
2269
|
+
}
|
|
2270
|
+
function createDefaultLoaderAnchorFinders() {
|
|
2269
2271
|
const fallbackFinder = createFinder(["postcss-loader"]);
|
|
2270
2272
|
return {
|
|
2271
2273
|
findRewriteAnchor: fallbackFinder,
|
|
@@ -2275,8 +2277,7 @@ function createLoaderAnchorFinders(appType) {
|
|
|
2275
2277
|
//#endregion
|
|
2276
2278
|
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
|
|
2277
2279
|
function setupWebpackV5Loaders(options) {
|
|
2278
|
-
const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, markWebpackCssSourceModule, registerWebpackGeneratedCss, registerWebpackCssSourceFile, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
|
|
2279
|
-
const isMpxApp = isMpx(appType);
|
|
2280
|
+
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;
|
|
2280
2281
|
const generatorTarget = compilerOptions.generator?.target ?? inferGeneratorTargetFromEnv();
|
|
2281
2282
|
const generatorBranch = resolveRuntimeBranch({
|
|
2282
2283
|
appType: compilerOptions.appType,
|
|
@@ -2285,7 +2286,7 @@ function setupWebpackV5Loaders(options) {
|
|
|
2285
2286
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
2286
2287
|
uniAppX: compilerOptions.uniAppX
|
|
2287
2288
|
});
|
|
2288
|
-
if (shouldRewriteCssImports &&
|
|
2289
|
+
if (shouldRewriteCssImports && mpxCssImportRewrite) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
|
|
2289
2290
|
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
2290
2291
|
const shouldInjectRuntimeClassSetLoader = !generatorBranch.isWeb;
|
|
2291
2292
|
const shouldInjectCssImportRewriteLoader = shouldRewriteCssImports || !generatorBranch.isWeb || runtimeState.tailwindRuntime.majorVersion === 4;
|
|
@@ -2316,9 +2317,9 @@ function setupWebpackV5Loaders(options) {
|
|
|
2316
2317
|
};
|
|
2317
2318
|
compiler.hooks.watchClose?.tap?.(pluginName, cleanupWebpackLoaderRuntime);
|
|
2318
2319
|
compiler.hooks.shutdown?.tap?.(pluginName, cleanupWebpackLoaderRuntime);
|
|
2319
|
-
const { findRewriteAnchor, findClassSetAnchor } =
|
|
2320
|
+
const { findRewriteAnchor, findClassSetAnchor } = loaderAnchorFinders;
|
|
2320
2321
|
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
|
|
2321
|
-
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions &&
|
|
2322
|
+
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && mpxCssImportRewrite) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
2322
2323
|
const createRuntimeClassSetLoaderEntry = () => ({
|
|
2323
2324
|
loader: runtimeClassSetLoader,
|
|
2324
2325
|
options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
|
|
@@ -2338,7 +2339,7 @@ function setupWebpackV5Loaders(options) {
|
|
|
2338
2339
|
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
2339
2340
|
NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
|
|
2340
2341
|
if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
|
|
2341
|
-
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports &&
|
|
2342
|
+
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && mpxCssImportRewrite);
|
|
2342
2343
|
const loaderEntries = module.loaders || [];
|
|
2343
2344
|
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
2344
2345
|
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
@@ -2384,16 +2385,12 @@ function setupWebpackV5Loaders(options) {
|
|
|
2384
2385
|
});
|
|
2385
2386
|
}
|
|
2386
2387
|
//#endregion
|
|
2387
|
-
//#region src/bundlers/webpack/
|
|
2388
|
+
//#region src/bundlers/webpack/shared/create-framework-plugin.ts
|
|
2388
2389
|
const debug = createDebug();
|
|
2389
2390
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
2390
2391
|
const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
|
|
2391
2392
|
function shouldKeepPreviousWebpackCssSource(previous, next) {
|
|
2392
|
-
|
|
2393
|
-
if (previous.processed === true || next.processed === true || !previous.css || !next.css || previous.css === next.css) return false;
|
|
2394
|
-
const previousMarkers = collectWebpackAssetUserCssMarkers(previous.css);
|
|
2395
|
-
const nextMarkers = collectWebpackAssetUserCssMarkers(next.css);
|
|
2396
|
-
return previousMarkers.size > nextMarkers.size && [...nextMarkers].every((marker) => previousMarkers.has(marker));
|
|
2393
|
+
return next.processed === true && previous.processed === false;
|
|
2397
2394
|
}
|
|
2398
2395
|
function normalizeIgnoredList(ignored) {
|
|
2399
2396
|
return (Array.isArray(ignored) ? [...ignored] : [ignored]).filter((item) => typeof item === "string" || item instanceof RegExp || typeof item === "function");
|
|
@@ -2454,32 +2451,40 @@ function setupWebpackWatchOutputIgnore(compiler) {
|
|
|
2454
2451
|
}
|
|
2455
2452
|
});
|
|
2456
2453
|
}
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
var WeappTailwindcss = class {
|
|
2463
|
-
constructor(options = {}) {
|
|
2454
|
+
function isInternalUserDefinedOptions(options) {
|
|
2455
|
+
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
2456
|
+
}
|
|
2457
|
+
var WebpackFrameworkPlugin = class {
|
|
2458
|
+
constructor(options = {}, frameworkBranch) {
|
|
2464
2459
|
_defineProperty(this, "options", void 0);
|
|
2465
2460
|
_defineProperty(this, "appType", void 0);
|
|
2466
2461
|
_defineProperty(this, "hasInitialTailwindCssRoots", void 0);
|
|
2462
|
+
_defineProperty(this, "frameworkBranch", void 0);
|
|
2463
|
+
this.frameworkBranch = frameworkBranch;
|
|
2467
2464
|
this.hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
|
|
2468
|
-
this.options = getCompilerContext({
|
|
2465
|
+
this.options = isInternalUserDefinedOptions(options) ? options : getCompilerContext({
|
|
2469
2466
|
...options,
|
|
2470
2467
|
__internalDeferMissingCssEntriesWarning: true
|
|
2471
2468
|
});
|
|
2472
2469
|
this.appType = this.options.appType;
|
|
2473
2470
|
}
|
|
2474
2471
|
apply(compiler) {
|
|
2472
|
+
debug("apply webpack framework plugin framework=%s", this.frameworkBranch.frameworkName);
|
|
2475
2473
|
compiler.options = compiler.options || {};
|
|
2476
2474
|
const { disabled, onLoad, runtimeLoaderPath, tailwindRuntime, refreshTailwindcssRuntime, styleInjector } = this.options;
|
|
2477
2475
|
const initialTailwindRuntime = tailwindRuntime;
|
|
2478
2476
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
2479
2477
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
2480
2478
|
const shouldRewriteCssImports = this.options.rewriteCssImports === true;
|
|
2481
|
-
const
|
|
2482
|
-
|
|
2479
|
+
const frameworkProfile = resolveWebpackFrameworkProfile({
|
|
2480
|
+
appType: this.appType,
|
|
2481
|
+
detectEnv: true,
|
|
2482
|
+
env: process.env,
|
|
2483
|
+
root: compiler.options.context ?? compiler.context,
|
|
2484
|
+
uniAppX: this.options.uniAppX
|
|
2485
|
+
});
|
|
2486
|
+
this.appType = frameworkProfile.appType ?? this.appType;
|
|
2487
|
+
if (shouldRewriteCssImports) this.frameworkBranch.setupCssImportRewriteRedirect?.(weappTailwindcssPackageDir);
|
|
2483
2488
|
if (disabledOptions.plugin) return;
|
|
2484
2489
|
if (initialTailwindRuntime.majorVersion !== 4) throw new Error("weapp-tailwindcss/webpack 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
2485
2490
|
setupWebpackWatchOutputIgnore(compiler);
|
|
@@ -2674,6 +2679,8 @@ var WeappTailwindcss = class {
|
|
|
2674
2679
|
contexts: runtimeWatchDependencyContexts
|
|
2675
2680
|
};
|
|
2676
2681
|
},
|
|
2682
|
+
loaderAnchorFinders: this.frameworkBranch.loaderAnchorFinders,
|
|
2683
|
+
mpxCssImportRewrite: this.frameworkBranch.mpxCssImportRewrite,
|
|
2677
2684
|
debug
|
|
2678
2685
|
});
|
|
2679
2686
|
setupWebpackV5ProcessAssetsHook({
|
|
@@ -2701,7 +2708,105 @@ var WeappTailwindcss = class {
|
|
|
2701
2708
|
prepareWebpackCssSources,
|
|
2702
2709
|
debug
|
|
2703
2710
|
});
|
|
2704
|
-
createBuiltinWebpackStyleInjectorPlugin(styleInjector, this.
|
|
2711
|
+
createBuiltinWebpackStyleInjectorPlugin(styleInjector, this.frameworkBranch.styleInjectorDelegate)?.apply(compiler);
|
|
2712
|
+
}
|
|
2713
|
+
};
|
|
2714
|
+
//#endregion
|
|
2715
|
+
//#region src/bundlers/webpack/frameworks/generic/index.ts
|
|
2716
|
+
var GenericWebpackPlugin = class extends WebpackFrameworkPlugin {
|
|
2717
|
+
constructor(options = {}) {
|
|
2718
|
+
super(options, {
|
|
2719
|
+
frameworkName: "generic",
|
|
2720
|
+
loaderAnchorFinders: createDefaultLoaderAnchorFinders(),
|
|
2721
|
+
styleInjectorDelegate: webpackStyleInjectorDelegates.generic
|
|
2722
|
+
});
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
//#endregion
|
|
2726
|
+
//#region src/bundlers/webpack/frameworks/mpx/index.ts
|
|
2727
|
+
var MpxWebpackPlugin = class extends WebpackFrameworkPlugin {
|
|
2728
|
+
constructor(options = {}) {
|
|
2729
|
+
super(options, {
|
|
2730
|
+
frameworkName: "mpx",
|
|
2731
|
+
loaderAnchorFinders: createMpxLoaderAnchorFinders(),
|
|
2732
|
+
mpxCssImportRewrite: true,
|
|
2733
|
+
setupCssImportRewriteRedirect: (packageDir) => setupMpxTailwindcssRedirect(packageDir, true),
|
|
2734
|
+
styleInjectorDelegate: webpackStyleInjectorDelegates.mpx
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
};
|
|
2738
|
+
//#endregion
|
|
2739
|
+
//#region src/bundlers/webpack/frameworks/taro/index.ts
|
|
2740
|
+
var TaroWebpackPlugin = class extends WebpackFrameworkPlugin {
|
|
2741
|
+
constructor(options = {}) {
|
|
2742
|
+
super(options, {
|
|
2743
|
+
frameworkName: "taro",
|
|
2744
|
+
loaderAnchorFinders: createDefaultLoaderAnchorFinders(),
|
|
2745
|
+
styleInjectorDelegate: webpackStyleInjectorDelegates.taro
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
//#endregion
|
|
2750
|
+
//#region src/bundlers/webpack/frameworks/uni-app/index.ts
|
|
2751
|
+
var UniAppWebpackPlugin = class extends WebpackFrameworkPlugin {
|
|
2752
|
+
constructor(options = {}) {
|
|
2753
|
+
super(options, {
|
|
2754
|
+
frameworkName: "uni-app",
|
|
2755
|
+
loaderAnchorFinders: createDefaultLoaderAnchorFinders(),
|
|
2756
|
+
styleInjectorDelegate: webpackStyleInjectorDelegates.uniApp
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
};
|
|
2760
|
+
//#endregion
|
|
2761
|
+
//#region src/bundlers/webpack/frameworks/weapp-vite/index.ts
|
|
2762
|
+
var WeappViteWebpackPlugin = class extends WebpackFrameworkPlugin {
|
|
2763
|
+
constructor(options = {}) {
|
|
2764
|
+
super(options, {
|
|
2765
|
+
frameworkName: "weapp-vite",
|
|
2766
|
+
loaderAnchorFinders: createDefaultLoaderAnchorFinders(),
|
|
2767
|
+
styleInjectorDelegate: webpackStyleInjectorDelegates.generic
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
//#endregion
|
|
2772
|
+
//#region src/bundlers/webpack/frameworks/index.ts
|
|
2773
|
+
function createWebpackFrameworkPlugin(frameworkName, options = {}) {
|
|
2774
|
+
switch (frameworkName) {
|
|
2775
|
+
case "mpx": return new MpxWebpackPlugin(options);
|
|
2776
|
+
case "taro": return new TaroWebpackPlugin(options);
|
|
2777
|
+
case "uni-app": return new UniAppWebpackPlugin(options);
|
|
2778
|
+
case "generic": return new GenericWebpackPlugin(options);
|
|
2779
|
+
default: return new WeappViteWebpackPlugin(options);
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
//#endregion
|
|
2783
|
+
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
2784
|
+
/**
|
|
2785
|
+
* @name WeappTailwindcss
|
|
2786
|
+
* @description Webpack 入口只负责早期识别框架分支,具体 hook 由 framework 目录下的插件拥有。
|
|
2787
|
+
* @link https://tw.icebreaker.top/docs/intro
|
|
2788
|
+
*/
|
|
2789
|
+
var WeappTailwindcss = class {
|
|
2790
|
+
constructor(options = {}) {
|
|
2791
|
+
_defineProperty(this, "options", void 0);
|
|
2792
|
+
_defineProperty(this, "appType", void 0);
|
|
2793
|
+
this.options = getCompilerContext({
|
|
2794
|
+
...options,
|
|
2795
|
+
__internalDeferMissingCssEntriesWarning: true
|
|
2796
|
+
});
|
|
2797
|
+
this.appType = this.options.appType;
|
|
2798
|
+
}
|
|
2799
|
+
apply(compiler) {
|
|
2800
|
+
const plugin = createWebpackFrameworkPlugin(resolveWebpackFrameworkProfile({
|
|
2801
|
+
appType: this.appType,
|
|
2802
|
+
detectEnv: true,
|
|
2803
|
+
env: process.env,
|
|
2804
|
+
root: compiler.options?.context ?? compiler.context,
|
|
2805
|
+
uniAppX: this.options.uniAppX
|
|
2806
|
+
}).frameworkName, this.options);
|
|
2807
|
+
plugin.apply(compiler);
|
|
2808
|
+
this.options = plugin.options;
|
|
2809
|
+
this.appType = plugin.appType;
|
|
2705
2810
|
}
|
|
2706
2811
|
};
|
|
2707
2812
|
//#endregion
|