weapp-tailwindcss 4.9.2 → 4.9.3
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/{chunk-DNRNFN4I.js → chunk-3UOPODB3.js} +44 -44
- package/dist/{chunk-2L6NDZIQ.mjs → chunk-4HESZS5A.mjs} +2 -2
- package/dist/{chunk-5O6237HX.js → chunk-4RUFPPI6.js} +400 -377
- package/dist/{chunk-ZE7JKKFT.mjs → chunk-7D27E7TU.mjs} +438 -415
- package/dist/{chunk-W3MTTQ5M.js → chunk-A2BRI46M.js} +5 -5
- package/dist/{chunk-3SKEY32E.mjs → chunk-F2CKKG6Q.mjs} +67 -67
- package/dist/{chunk-VU2GIXVH.js → chunk-I3IRT5VH.js} +7 -7
- package/dist/chunk-IMOEZLDR.js +441 -0
- package/dist/{chunk-WGBJY2H3.mjs → chunk-IW3B6ZJD.mjs} +646 -565
- package/dist/{chunk-U7BH6QHE.js → chunk-KXZ4MP4L.js} +277 -236
- package/dist/chunk-PU5CC4ZI.mjs +444 -0
- package/dist/{chunk-FFGR5V3H.mjs → chunk-SPH6SCTM.mjs} +1 -1
- package/dist/{chunk-XXJNXESJ.js → chunk-VOD2WUH6.js} +635 -554
- package/dist/{chunk-2WPTDMN3.js → chunk-VPHA77FH.js} +61 -61
- package/dist/{chunk-CBOVUIXD.mjs → chunk-WH65CIYG.mjs} +41 -41
- package/dist/{chunk-UAEME5HT.js → chunk-Y6F6NBA7.js} +1 -1
- package/dist/{chunk-DSD5JRCQ.mjs → chunk-Z2D5NSG5.mjs} +265 -224
- package/dist/{chunk-G5OV7IOU.mjs → chunk-ZL22KEHH.mjs} +2 -2
- package/dist/cli.js +182 -136
- package/dist/cli.mjs +194 -148
- package/dist/core.js +10 -10
- package/dist/core.mjs +4 -4
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.js +6 -6
- package/dist/gulp.mjs +5 -5
- package/dist/index.js +10 -10
- package/dist/index.mjs +9 -9
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.js +5 -5
- package/dist/presets.mjs +2 -2
- package/dist/reset.d.mts +2 -1
- package/dist/reset.d.ts +2 -1
- package/dist/reset.js +25 -21
- package/dist/reset.mjs +25 -21
- package/dist/types.d.mts +503 -474
- package/dist/types.d.ts +503 -474
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.js +7 -7
- package/dist/vite.mjs +6 -6
- package/dist/weapp-tw-css-import-rewrite-loader.js +2 -4
- package/dist/webpack.js +8 -8
- package/dist/webpack.mjs +7 -7
- package/dist/webpack4.js +351 -307
- package/dist/webpack4.mjs +341 -297
- package/package.json +10 -10
- package/dist/chunk-5AKI6FQP.mjs +0 -397
- package/dist/chunk-SNEMGP42.js +0 -394
package/dist/webpack4.mjs
CHANGED
|
@@ -9,41 +9,357 @@ import {
|
|
|
9
9
|
isMpx,
|
|
10
10
|
patchMpxLoaderResolve,
|
|
11
11
|
setupMpxTailwindcssRedirect
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WH65CIYG.mjs";
|
|
13
13
|
import {
|
|
14
14
|
pushConcurrentTaskFactories,
|
|
15
15
|
resolveDisabledOptions,
|
|
16
16
|
resolveOutputSpecifier,
|
|
17
17
|
resolvePackageDir,
|
|
18
18
|
toAbsoluteOutputPath
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-F2CKKG6Q.mjs";
|
|
20
20
|
import {
|
|
21
21
|
processCachedTask
|
|
22
22
|
} from "./chunk-RRHPTTCP.mjs";
|
|
23
23
|
import {
|
|
24
24
|
setupPatchRecorder
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-ZL22KEHH.mjs";
|
|
26
26
|
import {
|
|
27
27
|
collectRuntimeClassSet,
|
|
28
28
|
createDebug,
|
|
29
29
|
getCompilerContext,
|
|
30
30
|
pluginName,
|
|
31
31
|
refreshTailwindRuntimeState
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import "./chunk-
|
|
32
|
+
} from "./chunk-IW3B6ZJD.mjs";
|
|
33
|
+
import "./chunk-7D27E7TU.mjs";
|
|
34
34
|
import "./chunk-HWF5U4CI.mjs";
|
|
35
35
|
import {
|
|
36
36
|
getGroupedEntries
|
|
37
37
|
} from "./chunk-OOHJLO5M.mjs";
|
|
38
38
|
import {
|
|
39
39
|
__dirname
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-SPH6SCTM.mjs";
|
|
41
41
|
|
|
42
42
|
// src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
|
|
43
|
-
import
|
|
43
|
+
import process3 from "process";
|
|
44
|
+
|
|
45
|
+
// src/bundlers/webpack/BaseUnifiedPlugin/v4-assets.ts
|
|
44
46
|
import path from "path";
|
|
45
47
|
import process from "process";
|
|
46
48
|
import { ConcatSource } from "webpack-sources";
|
|
49
|
+
function setupWebpackV4EmitHook(options) {
|
|
50
|
+
const {
|
|
51
|
+
compiler,
|
|
52
|
+
options: compilerOptions,
|
|
53
|
+
appType,
|
|
54
|
+
runtimeState,
|
|
55
|
+
refreshRuntimeState,
|
|
56
|
+
debug: debug2
|
|
57
|
+
} = options;
|
|
58
|
+
compiler.hooks.emit.tapPromise(pluginName, async (compilation) => {
|
|
59
|
+
await runtimeState.patchPromise;
|
|
60
|
+
compilerOptions.onStart();
|
|
61
|
+
debug2("start");
|
|
62
|
+
for (const chunk of compilation.chunks) {
|
|
63
|
+
if (chunk.id && chunk.hash) {
|
|
64
|
+
compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const assets = compilation.assets;
|
|
68
|
+
const entries = Object.entries(assets);
|
|
69
|
+
const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
|
|
70
|
+
const jsAssets = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const [file] of entries) {
|
|
72
|
+
if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
|
|
73
|
+
const absolute = toAbsoluteOutputPath(file, outputDir);
|
|
74
|
+
jsAssets.set(absolute, file);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const moduleGraphOptions = {
|
|
78
|
+
resolve(specifier, importer) {
|
|
79
|
+
return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
80
|
+
},
|
|
81
|
+
load: (id) => {
|
|
82
|
+
const assetName = jsAssets.get(id);
|
|
83
|
+
if (!assetName) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const assetSource = compilation.assets[assetName];
|
|
87
|
+
if (!assetSource) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
const source = assetSource.source();
|
|
91
|
+
return typeof source === "string" ? source : source.toString();
|
|
92
|
+
},
|
|
93
|
+
filter(id) {
|
|
94
|
+
return jsAssets.has(id);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const applyLinkedResults = (linked) => {
|
|
98
|
+
if (!linked) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
for (const [id, { code }] of Object.entries(linked)) {
|
|
102
|
+
const assetName = jsAssets.get(id);
|
|
103
|
+
if (!assetName) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const assetSource = compilation.assets[assetName];
|
|
107
|
+
if (!assetSource) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const previousSource = assetSource.source();
|
|
111
|
+
const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
|
|
112
|
+
if (previous === code) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const source = new ConcatSource(code);
|
|
116
|
+
compilation.updateAsset(assetName, source);
|
|
117
|
+
compilerOptions.onUpdate(assetName, previous, code);
|
|
118
|
+
debug2("js linked handle: %s", assetName);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const groupedEntries = getGroupedEntries(entries, compilerOptions);
|
|
122
|
+
await refreshRuntimeState(true);
|
|
123
|
+
await runtimeState.patchPromise;
|
|
124
|
+
const runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
|
|
125
|
+
debug2("get runtimeSet, class count: %d", runtimeSet.size);
|
|
126
|
+
const tasks = [];
|
|
127
|
+
if (Array.isArray(groupedEntries.html)) {
|
|
128
|
+
for (const element of groupedEntries.html) {
|
|
129
|
+
const [file, originalSource] = element;
|
|
130
|
+
const rawSource = originalSource.source().toString();
|
|
131
|
+
const cacheKey = file;
|
|
132
|
+
tasks.push(
|
|
133
|
+
processCachedTask({
|
|
134
|
+
cache: compilerOptions.cache,
|
|
135
|
+
cacheKey,
|
|
136
|
+
rawSource,
|
|
137
|
+
applyResult(source) {
|
|
138
|
+
compilation.updateAsset(file, source);
|
|
139
|
+
},
|
|
140
|
+
onCacheHit() {
|
|
141
|
+
debug2("html cache hit: %s", file);
|
|
142
|
+
},
|
|
143
|
+
transform: async () => {
|
|
144
|
+
const wxml = await compilerOptions.templateHandler(rawSource, {
|
|
145
|
+
runtimeSet
|
|
146
|
+
});
|
|
147
|
+
const source = new ConcatSource(wxml);
|
|
148
|
+
compilerOptions.onUpdate(file, rawSource, wxml);
|
|
149
|
+
debug2("html handle: %s", file);
|
|
150
|
+
return {
|
|
151
|
+
result: source
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const jsTaskFactories = [];
|
|
159
|
+
if (Array.isArray(groupedEntries.js)) {
|
|
160
|
+
for (const [file] of groupedEntries.js) {
|
|
161
|
+
const cacheKey = getCacheKey(file);
|
|
162
|
+
const assetSource = compilation.assets[file];
|
|
163
|
+
if (!assetSource) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const initialValue = assetSource.source();
|
|
167
|
+
const initialRawSource = typeof initialValue === "string" ? initialValue : initialValue.toString();
|
|
168
|
+
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
169
|
+
jsTaskFactories.push(async () => {
|
|
170
|
+
await processCachedTask({
|
|
171
|
+
cache: compilerOptions.cache,
|
|
172
|
+
cacheKey,
|
|
173
|
+
rawSource: initialRawSource,
|
|
174
|
+
applyResult(source) {
|
|
175
|
+
compilation.updateAsset(file, source);
|
|
176
|
+
},
|
|
177
|
+
onCacheHit() {
|
|
178
|
+
debug2("js cache hit: %s", file);
|
|
179
|
+
},
|
|
180
|
+
transform: async () => {
|
|
181
|
+
const currentAsset = compilation.assets[file];
|
|
182
|
+
const currentValue = currentAsset?.source();
|
|
183
|
+
const currentSource = typeof currentValue === "string" ? currentValue : currentValue?.toString() ?? "";
|
|
184
|
+
const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, {
|
|
185
|
+
filename: absoluteFile,
|
|
186
|
+
moduleGraph: moduleGraphOptions,
|
|
187
|
+
babelParserOptions: {
|
|
188
|
+
sourceFilename: absoluteFile
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const source = new ConcatSource(code);
|
|
192
|
+
compilerOptions.onUpdate(file, currentSource, code);
|
|
193
|
+
debug2("js handle: %s", file);
|
|
194
|
+
applyLinkedResults(linked);
|
|
195
|
+
return {
|
|
196
|
+
result: source
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (Array.isArray(groupedEntries.css)) {
|
|
204
|
+
for (const element of groupedEntries.css) {
|
|
205
|
+
const [file, originalSource] = element;
|
|
206
|
+
const rawSource = originalSource.source().toString();
|
|
207
|
+
const cacheKey = file;
|
|
208
|
+
tasks.push(
|
|
209
|
+
processCachedTask({
|
|
210
|
+
cache: compilerOptions.cache,
|
|
211
|
+
cacheKey,
|
|
212
|
+
rawSource,
|
|
213
|
+
applyResult(source) {
|
|
214
|
+
compilation.updateAsset(file, source);
|
|
215
|
+
},
|
|
216
|
+
onCacheHit() {
|
|
217
|
+
debug2("css cache hit: %s", file);
|
|
218
|
+
},
|
|
219
|
+
transform: async () => {
|
|
220
|
+
await runtimeState.patchPromise;
|
|
221
|
+
const { css } = await compilerOptions.styleHandler(rawSource, {
|
|
222
|
+
isMainChunk: compilerOptions.mainCssChunkMatcher(file, appType),
|
|
223
|
+
postcssOptions: {
|
|
224
|
+
options: {
|
|
225
|
+
from: file
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
majorVersion: runtimeState.twPatcher.majorVersion
|
|
229
|
+
});
|
|
230
|
+
const source = new ConcatSource(css);
|
|
231
|
+
compilerOptions.onUpdate(file, rawSource, css);
|
|
232
|
+
debug2("css handle: %s", file);
|
|
233
|
+
return {
|
|
234
|
+
result: source
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
242
|
+
await Promise.all(tasks);
|
|
243
|
+
debug2("end");
|
|
244
|
+
compilerOptions.onEnd();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.ts
|
|
249
|
+
import fs from "fs";
|
|
250
|
+
import path2 from "path";
|
|
251
|
+
import process2 from "process";
|
|
252
|
+
function setupWebpackV4Loaders(options) {
|
|
253
|
+
const {
|
|
254
|
+
compiler,
|
|
255
|
+
options: compilerOptions,
|
|
256
|
+
appType,
|
|
257
|
+
weappTailwindcssPackageDir: weappTailwindcssPackageDir2,
|
|
258
|
+
shouldRewriteCssImports,
|
|
259
|
+
runtimeLoaderPath,
|
|
260
|
+
runtimeCssImportRewriteLoaderPath,
|
|
261
|
+
getClassSetInLoader,
|
|
262
|
+
debug: debug2
|
|
263
|
+
} = options;
|
|
264
|
+
const isMpxApp = isMpx(appType);
|
|
265
|
+
if (shouldRewriteCssImports && isMpxApp) {
|
|
266
|
+
ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir2);
|
|
267
|
+
}
|
|
268
|
+
const runtimeClassSetLoader = runtimeLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
269
|
+
const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
270
|
+
const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
|
|
271
|
+
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
272
|
+
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
273
|
+
pkgDir: weappTailwindcssPackageDir2,
|
|
274
|
+
appType
|
|
275
|
+
} : void 0;
|
|
276
|
+
const classSetLoaderOptions = {
|
|
277
|
+
getClassSet: getClassSetInLoader
|
|
278
|
+
};
|
|
279
|
+
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
280
|
+
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
281
|
+
rewriteCssImports: runtimeLoaderRewriteOptions
|
|
282
|
+
} : void 0;
|
|
283
|
+
if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) {
|
|
284
|
+
injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
|
|
285
|
+
}
|
|
286
|
+
const createRuntimeClassSetLoaderEntry = () => ({
|
|
287
|
+
loader: runtimeClassSetLoader,
|
|
288
|
+
options: classSetLoaderOptions,
|
|
289
|
+
ident: null,
|
|
290
|
+
type: null
|
|
291
|
+
});
|
|
292
|
+
const createCssImportRewriteLoaderEntry = () => {
|
|
293
|
+
if (!runtimeCssImportRewriteLoader) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
loader: runtimeCssImportRewriteLoader,
|
|
298
|
+
options: cssImportRewriteLoaderOptions,
|
|
299
|
+
ident: null,
|
|
300
|
+
type: null
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
304
|
+
compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
|
|
305
|
+
const hasRuntimeLoader = runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists;
|
|
306
|
+
if (!hasRuntimeLoader) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (shouldRewriteCssImports && isMpx(appType) && typeof _loaderContext.resolve === "function") {
|
|
310
|
+
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir2, true);
|
|
311
|
+
}
|
|
312
|
+
const loaderEntries = module.loaders || [];
|
|
313
|
+
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
314
|
+
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
315
|
+
const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
|
|
316
|
+
if (process2.env.WEAPP_TW_LOADER_DEBUG && isCssModule) {
|
|
317
|
+
debug2("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
318
|
+
}
|
|
319
|
+
if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.includes("app.css")) {
|
|
320
|
+
debug2("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
321
|
+
} else if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.endsWith(".css")) {
|
|
322
|
+
debug2("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
323
|
+
}
|
|
324
|
+
if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const anchorlessInsert = (entry, position) => {
|
|
328
|
+
if (position === "after") {
|
|
329
|
+
loaderEntries.push(entry);
|
|
330
|
+
} else {
|
|
331
|
+
loaderEntries.unshift(entry);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
|
|
335
|
+
const existingIndex = loaderEntries.findIndex(
|
|
336
|
+
(entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader)
|
|
337
|
+
);
|
|
338
|
+
const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
|
|
339
|
+
if (rewriteEntry) {
|
|
340
|
+
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
341
|
+
if (anchorIndex === -1) {
|
|
342
|
+
anchorlessInsert(rewriteEntry, "after");
|
|
343
|
+
} else {
|
|
344
|
+
loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
|
|
345
|
+
}
|
|
346
|
+
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
350
|
+
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
351
|
+
if (anchorIndex === -1) {
|
|
352
|
+
anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
|
|
353
|
+
} else {
|
|
354
|
+
const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
|
|
355
|
+
loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
|
|
47
363
|
var debug = createDebug();
|
|
48
364
|
var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
49
365
|
var UnifiedWebpackPluginV4 = class {
|
|
@@ -54,18 +370,10 @@ var UnifiedWebpackPluginV4 = class {
|
|
|
54
370
|
apply(compiler) {
|
|
55
371
|
compiler.options = compiler.options || {};
|
|
56
372
|
const {
|
|
57
|
-
mainCssChunkMatcher,
|
|
58
373
|
disabled,
|
|
59
374
|
onLoad,
|
|
60
|
-
onUpdate,
|
|
61
|
-
onEnd,
|
|
62
|
-
onStart,
|
|
63
|
-
styleHandler,
|
|
64
|
-
templateHandler,
|
|
65
|
-
jsHandler,
|
|
66
375
|
runtimeLoaderPath,
|
|
67
376
|
runtimeCssImportRewriteLoaderPath,
|
|
68
|
-
cache,
|
|
69
377
|
twPatcher: initialTwPatcher,
|
|
70
378
|
refreshTailwindcssPatcher
|
|
71
379
|
} = this.options;
|
|
@@ -86,7 +394,7 @@ var UnifiedWebpackPluginV4 = class {
|
|
|
86
394
|
}
|
|
87
395
|
const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
|
|
88
396
|
source: "runtime",
|
|
89
|
-
cwd: this.options.tailwindcssBasedir ??
|
|
397
|
+
cwd: this.options.tailwindcssBasedir ?? process3.cwd()
|
|
90
398
|
});
|
|
91
399
|
const runtimeState = {
|
|
92
400
|
twPatcher: initialTwPatcher,
|
|
@@ -102,289 +410,25 @@ var UnifiedWebpackPluginV4 = class {
|
|
|
102
410
|
await runtimeState.patchPromise;
|
|
103
411
|
await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
|
|
104
412
|
}
|
|
105
|
-
const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
|
|
106
|
-
const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
|
|
107
|
-
const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
|
|
108
|
-
const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
|
|
109
|
-
const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
|
|
110
|
-
pkgDir: weappTailwindcssPackageDir,
|
|
111
|
-
appType: this.appType
|
|
112
|
-
} : void 0;
|
|
113
|
-
const classSetLoaderOptions = {
|
|
114
|
-
getClassSet: getClassSetInLoader
|
|
115
|
-
};
|
|
116
|
-
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(this.appType);
|
|
117
|
-
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
118
|
-
rewriteCssImports: runtimeLoaderRewriteOptions
|
|
119
|
-
} : void 0;
|
|
120
413
|
onLoad();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
type: null
|
|
132
|
-
});
|
|
133
|
-
const createCssImportRewriteLoaderEntry = () => {
|
|
134
|
-
if (!runtimeCssImportRewriteLoader) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
loader: runtimeCssImportRewriteLoader,
|
|
139
|
-
options: cssImportRewriteLoaderOptions,
|
|
140
|
-
ident: null,
|
|
141
|
-
type: null
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
145
|
-
compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
|
|
146
|
-
const hasRuntimeLoader = runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists;
|
|
147
|
-
if (!hasRuntimeLoader) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (shouldRewriteCssImports && isMpx(this.appType) && typeof _loaderContext.resolve === "function") {
|
|
151
|
-
patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, true);
|
|
152
|
-
}
|
|
153
|
-
const loaderEntries = module.loaders || [];
|
|
154
|
-
let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
155
|
-
const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
|
|
156
|
-
const isCssModule = isCssLikeModuleResource(module.resource, this.options.cssMatcher, this.appType);
|
|
157
|
-
if (process.env.WEAPP_TW_LOADER_DEBUG && isCssModule) {
|
|
158
|
-
debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
159
|
-
}
|
|
160
|
-
if (process.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.includes("app.css")) {
|
|
161
|
-
debug("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
162
|
-
} else if (process.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.endsWith(".css")) {
|
|
163
|
-
debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
|
|
164
|
-
}
|
|
165
|
-
if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const anchorlessInsert = (entry, position) => {
|
|
169
|
-
if (position === "after") {
|
|
170
|
-
loaderEntries.push(entry);
|
|
171
|
-
} else {
|
|
172
|
-
loaderEntries.unshift(entry);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
|
|
176
|
-
const existingIndex = loaderEntries.findIndex(
|
|
177
|
-
(entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader)
|
|
178
|
-
);
|
|
179
|
-
const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
|
|
180
|
-
if (rewriteEntry) {
|
|
181
|
-
const anchorIndex = findRewriteAnchor(loaderEntries);
|
|
182
|
-
if (anchorIndex === -1) {
|
|
183
|
-
anchorlessInsert(rewriteEntry, "after");
|
|
184
|
-
} else {
|
|
185
|
-
loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
|
|
186
|
-
}
|
|
187
|
-
rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
|
|
191
|
-
const anchorIndex = findClassSetAnchor(loaderEntries);
|
|
192
|
-
if (anchorIndex === -1) {
|
|
193
|
-
anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
|
|
194
|
-
} else {
|
|
195
|
-
const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
|
|
196
|
-
loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
414
|
+
setupWebpackV4Loaders({
|
|
415
|
+
compiler,
|
|
416
|
+
options: this.options,
|
|
417
|
+
appType: this.appType,
|
|
418
|
+
weappTailwindcssPackageDir,
|
|
419
|
+
shouldRewriteCssImports,
|
|
420
|
+
runtimeLoaderPath,
|
|
421
|
+
runtimeCssImportRewriteLoaderPath,
|
|
422
|
+
getClassSetInLoader,
|
|
423
|
+
debug
|
|
200
424
|
});
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const assets = compilation.assets;
|
|
211
|
-
const entries = Object.entries(assets);
|
|
212
|
-
const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
|
|
213
|
-
const jsAssets = /* @__PURE__ */ new Map();
|
|
214
|
-
for (const [file] of entries) {
|
|
215
|
-
if (this.options.jsMatcher(file) || this.options.wxsMatcher(file)) {
|
|
216
|
-
const absolute = toAbsoluteOutputPath(file, outputDir);
|
|
217
|
-
jsAssets.set(absolute, file);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const moduleGraphOptions = {
|
|
221
|
-
resolve(specifier, importer) {
|
|
222
|
-
return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
|
|
223
|
-
},
|
|
224
|
-
load: (id) => {
|
|
225
|
-
const assetName = jsAssets.get(id);
|
|
226
|
-
if (!assetName) {
|
|
227
|
-
return void 0;
|
|
228
|
-
}
|
|
229
|
-
const assetSource = compilation.assets[assetName];
|
|
230
|
-
if (!assetSource) {
|
|
231
|
-
return void 0;
|
|
232
|
-
}
|
|
233
|
-
const source = assetSource.source();
|
|
234
|
-
return typeof source === "string" ? source : source.toString();
|
|
235
|
-
},
|
|
236
|
-
filter(id) {
|
|
237
|
-
return jsAssets.has(id);
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
const applyLinkedResults = (linked) => {
|
|
241
|
-
if (!linked) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
for (const [id, { code }] of Object.entries(linked)) {
|
|
245
|
-
const assetName = jsAssets.get(id);
|
|
246
|
-
if (!assetName) {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const assetSource = compilation.assets[assetName];
|
|
250
|
-
if (!assetSource) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const previousSource = assetSource.source();
|
|
254
|
-
const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
|
|
255
|
-
if (previous === code) {
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
const source = new ConcatSource(code);
|
|
259
|
-
compilation.updateAsset(assetName, source);
|
|
260
|
-
onUpdate(assetName, previous, code);
|
|
261
|
-
debug("js linked handle: %s", assetName);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
const groupedEntries = getGroupedEntries(entries, this.options);
|
|
265
|
-
await refreshRuntimeState(true);
|
|
266
|
-
await runtimeState.patchPromise;
|
|
267
|
-
const runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
|
|
268
|
-
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
269
|
-
const tasks = [];
|
|
270
|
-
if (Array.isArray(groupedEntries.html)) {
|
|
271
|
-
for (const element of groupedEntries.html) {
|
|
272
|
-
const [file, originalSource] = element;
|
|
273
|
-
const rawSource = originalSource.source().toString();
|
|
274
|
-
const cacheKey = file;
|
|
275
|
-
tasks.push(
|
|
276
|
-
processCachedTask({
|
|
277
|
-
cache,
|
|
278
|
-
cacheKey,
|
|
279
|
-
rawSource,
|
|
280
|
-
applyResult(source) {
|
|
281
|
-
compilation.updateAsset(file, source);
|
|
282
|
-
},
|
|
283
|
-
onCacheHit() {
|
|
284
|
-
debug("html cache hit: %s", file);
|
|
285
|
-
},
|
|
286
|
-
transform: async () => {
|
|
287
|
-
const wxml = await templateHandler(rawSource, {
|
|
288
|
-
runtimeSet
|
|
289
|
-
});
|
|
290
|
-
const source = new ConcatSource(wxml);
|
|
291
|
-
onUpdate(file, rawSource, wxml);
|
|
292
|
-
debug("html handle: %s", file);
|
|
293
|
-
return {
|
|
294
|
-
result: source
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
const jsTaskFactories = [];
|
|
302
|
-
if (Array.isArray(groupedEntries.js)) {
|
|
303
|
-
for (const [file] of groupedEntries.js) {
|
|
304
|
-
const cacheKey = getCacheKey(file);
|
|
305
|
-
const assetSource = compilation.assets[file];
|
|
306
|
-
if (!assetSource) {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
const initialValue = assetSource.source();
|
|
310
|
-
const initialRawSource = typeof initialValue === "string" ? initialValue : initialValue.toString();
|
|
311
|
-
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
312
|
-
jsTaskFactories.push(async () => {
|
|
313
|
-
await processCachedTask({
|
|
314
|
-
cache,
|
|
315
|
-
cacheKey,
|
|
316
|
-
rawSource: initialRawSource,
|
|
317
|
-
applyResult(source) {
|
|
318
|
-
compilation.updateAsset(file, source);
|
|
319
|
-
},
|
|
320
|
-
onCacheHit() {
|
|
321
|
-
debug("js cache hit: %s", file);
|
|
322
|
-
},
|
|
323
|
-
transform: async () => {
|
|
324
|
-
const currentAsset = compilation.assets[file];
|
|
325
|
-
const currentValue = currentAsset?.source();
|
|
326
|
-
const currentSource = typeof currentValue === "string" ? currentValue : currentValue?.toString() ?? "";
|
|
327
|
-
const { code, linked } = await jsHandler(currentSource, runtimeSet, {
|
|
328
|
-
filename: absoluteFile,
|
|
329
|
-
moduleGraph: moduleGraphOptions,
|
|
330
|
-
babelParserOptions: {
|
|
331
|
-
sourceFilename: absoluteFile
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
const source = new ConcatSource(code);
|
|
335
|
-
onUpdate(file, currentSource, code);
|
|
336
|
-
debug("js handle: %s", file);
|
|
337
|
-
applyLinkedResults(linked);
|
|
338
|
-
return {
|
|
339
|
-
result: source
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (Array.isArray(groupedEntries.css)) {
|
|
347
|
-
for (const element of groupedEntries.css) {
|
|
348
|
-
const [file, originalSource] = element;
|
|
349
|
-
const rawSource = originalSource.source().toString();
|
|
350
|
-
const cacheKey = file;
|
|
351
|
-
tasks.push(
|
|
352
|
-
processCachedTask({
|
|
353
|
-
cache,
|
|
354
|
-
cacheKey,
|
|
355
|
-
rawSource,
|
|
356
|
-
applyResult(source) {
|
|
357
|
-
compilation.updateAsset(file, source);
|
|
358
|
-
},
|
|
359
|
-
onCacheHit() {
|
|
360
|
-
debug("css cache hit: %s", file);
|
|
361
|
-
},
|
|
362
|
-
transform: async () => {
|
|
363
|
-
await runtimeState.patchPromise;
|
|
364
|
-
const { css } = await styleHandler(rawSource, {
|
|
365
|
-
isMainChunk: mainCssChunkMatcher(file, this.appType),
|
|
366
|
-
postcssOptions: {
|
|
367
|
-
options: {
|
|
368
|
-
from: file
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
majorVersion: runtimeState.twPatcher.majorVersion
|
|
372
|
-
});
|
|
373
|
-
const source = new ConcatSource(css);
|
|
374
|
-
onUpdate(file, rawSource, css);
|
|
375
|
-
debug("css handle: %s", file);
|
|
376
|
-
return {
|
|
377
|
-
result: source
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
})
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
385
|
-
await Promise.all(tasks);
|
|
386
|
-
debug("end");
|
|
387
|
-
onEnd();
|
|
425
|
+
setupWebpackV4EmitHook({
|
|
426
|
+
compiler,
|
|
427
|
+
options: this.options,
|
|
428
|
+
appType: this.appType,
|
|
429
|
+
runtimeState,
|
|
430
|
+
refreshRuntimeState,
|
|
431
|
+
debug
|
|
388
432
|
});
|
|
389
433
|
}
|
|
390
434
|
};
|