ptech-preset 1.3.4 → 1.3.5
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/index.js +47 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -338,7 +338,6 @@ function pluginCore(opts) {
|
|
|
338
338
|
return {
|
|
339
339
|
name: "plugin-mf-auto",
|
|
340
340
|
async setup(api) {
|
|
341
|
-
const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
|
|
342
341
|
const getExposes = async () => {
|
|
343
342
|
if (exposesMode === "jsdoc") return collectAutoExposes({ baseDir, globs });
|
|
344
343
|
if (exposesMode === "wrapper") return collectAutoExposesWithWrapper({ baseDir, globs });
|
|
@@ -377,6 +376,17 @@ function pluginCore(opts) {
|
|
|
377
376
|
if (typeof mfMerged.shared === "undefined") {
|
|
378
377
|
mfMerged.shared = DEFAULT_SHARED;
|
|
379
378
|
}
|
|
379
|
+
const command = api?.context?.command;
|
|
380
|
+
const isBuild = command === "build";
|
|
381
|
+
const isDev = !isBuild;
|
|
382
|
+
if (isDev && mfMerged.shared && typeof mfMerged.shared === "object") {
|
|
383
|
+
for (const key of Object.keys(mfMerged.shared)) {
|
|
384
|
+
const conf = mfMerged.shared[key];
|
|
385
|
+
if (conf && typeof conf === "object" && "eager" in conf) {
|
|
386
|
+
conf.eager = false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
380
390
|
if (cssInjection !== "none") {
|
|
381
391
|
const cssAbs = path3.resolve(root, cssEntry);
|
|
382
392
|
const hasCss = fs3.existsSync(cssAbs);
|
|
@@ -385,14 +395,24 @@ function pluginCore(opts) {
|
|
|
385
395
|
if (cssInjection === "wrapper" && mfMerged.exposes) {
|
|
386
396
|
const wrapped = {};
|
|
387
397
|
for (const [key, rel] of Object.entries(mfMerged.exposes)) {
|
|
388
|
-
const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, ""));
|
|
398
|
+
const targetAbs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
389
399
|
const proxyFile = path3.join(tempDir, `expose_${key.replace(/[./]/g, "_")}.ts`);
|
|
390
400
|
const lines = [];
|
|
391
|
-
if (hasCss)
|
|
392
|
-
|
|
393
|
-
|
|
401
|
+
if (hasCss) {
|
|
402
|
+
const cssRel = path3.relative(path3.dirname(proxyFile), cssAbs).replace(/\\/g, "/");
|
|
403
|
+
const cssImport = cssRel.startsWith(".") ? cssRel : `./${cssRel}`;
|
|
404
|
+
lines.push(`import ${JSON.stringify(cssImport)};`);
|
|
405
|
+
} else {
|
|
406
|
+
lines.push(`/* no css: ${cssEntry} not found */`);
|
|
407
|
+
}
|
|
408
|
+
const targetRel = path3.relative(path3.dirname(proxyFile), targetAbs).replace(/\\/g, "/");
|
|
409
|
+
const targetImport = targetRel.startsWith(".") ? targetRel : `./${targetRel}`;
|
|
410
|
+
const target = JSON.stringify(targetImport);
|
|
394
411
|
lines.push(`export * from ${target};`);
|
|
395
412
|
lines.push(`export { default } from ${target};`);
|
|
413
|
+
lines.push(
|
|
414
|
+
`if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpackHot.accept();}`
|
|
415
|
+
);
|
|
396
416
|
lines.push(`// generated by plugin-mf-auto`);
|
|
397
417
|
fs3.writeFileSync(proxyFile, lines.join(os.EOL), "utf8");
|
|
398
418
|
const relFromRoot = path3.relative(root, proxyFile).replace(/\\/g, "/");
|
|
@@ -402,9 +422,12 @@ function pluginCore(opts) {
|
|
|
402
422
|
}
|
|
403
423
|
if (cssInjection === "styles-expose" && hasCss) {
|
|
404
424
|
const stylesFile = path3.join(tempDir, `styles_expose.ts`);
|
|
425
|
+
const cssRel = path3.relative(path3.dirname(stylesFile), cssAbs).replace(/\\/g, "/");
|
|
426
|
+
const cssImport = cssRel.startsWith(".") ? cssRel : `./${cssRel}`;
|
|
405
427
|
fs3.writeFileSync(
|
|
406
428
|
stylesFile,
|
|
407
|
-
`import ${JSON.stringify(
|
|
429
|
+
`import ${JSON.stringify(cssImport)};
|
|
430
|
+
if (import.meta && (import.meta as any).webpackHot) {(import.meta as any).webpackHot.accept();}
|
|
408
431
|
// generated by plugin-mf-auto`,
|
|
409
432
|
"utf8"
|
|
410
433
|
);
|
|
@@ -412,9 +435,6 @@ function pluginCore(opts) {
|
|
|
412
435
|
mfMerged.exposes = { ...mfMerged.exposes ?? {}, [stylesExposeKey]: `./${relFromRoot}` };
|
|
413
436
|
}
|
|
414
437
|
}
|
|
415
|
-
const command = api?.context?.command;
|
|
416
|
-
const isProdLike = command === "build" || process.env.NODE_ENV === "production";
|
|
417
|
-
const isDev = !isProdLike;
|
|
418
438
|
const autoTypeUrls = buildRemoteTypeUrls(mfMerged.remotes || {});
|
|
419
439
|
const remoteAliases = Object.keys(autoTypeUrls);
|
|
420
440
|
const tsconfigForDtsAbs = writePatchedTsconfig({
|
|
@@ -438,18 +458,23 @@ function pluginCore(opts) {
|
|
|
438
458
|
await devFetchRemoteTypesOnce({ root, baseDir, typesFolderRel: typesFolder, urls: autoTypeUrls });
|
|
439
459
|
}
|
|
440
460
|
}
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
461
|
+
const dtsGenMaybe = ensureDtsObject(mfMerged.dts);
|
|
462
|
+
if (dtsGenMaybe !== false) {
|
|
463
|
+
const dtsGen = dtsGenMaybe;
|
|
464
|
+
dtsGen.generateTypes = { ...dtsGen.generateTypes ?? {}, tsConfigPath: tsconfigForDtsToUse };
|
|
465
|
+
if (isBuild && remoteAliases.length > 0) {
|
|
466
|
+
const existingConsume = dtsGen.consumeTypes ?? {};
|
|
467
|
+
const existingRt = existingConsume.remoteTypeUrls ?? {};
|
|
468
|
+
dtsGen.consumeTypes = {
|
|
469
|
+
typesFolder: existingConsume.typesFolder ?? typesFolder,
|
|
470
|
+
maxRetries: existingConsume.maxRetries ?? 3,
|
|
471
|
+
remoteTypeUrls: { ...autoTypeUrls, ...existingRt }
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
mfMerged.dts = dtsGen;
|
|
475
|
+
} else {
|
|
476
|
+
mfMerged.dts = false;
|
|
451
477
|
}
|
|
452
|
-
mfMerged.dts = dtsGen;
|
|
453
478
|
const { pluginModuleFederation: mfPluginFactory } = await import("@module-federation/rsbuild-plugin");
|
|
454
479
|
const mfPlugin = mfPluginFactory(mfMerged);
|
|
455
480
|
await mfPlugin.setup?.(api);
|
|
@@ -460,7 +485,7 @@ function pluginCore(opts) {
|
|
|
460
485
|
const fromEnv = process.env.CDN_URL || process.env.ASSET_PREFIX;
|
|
461
486
|
const fallbackCdn = `${CDN_BASE}${pkgSafe}/`;
|
|
462
487
|
const target = fromEnv ?? fallbackCdn;
|
|
463
|
-
if (
|
|
488
|
+
if (isBuild && (!current || current === "/" || current === "./")) {
|
|
464
489
|
config.output.assetPrefix = target;
|
|
465
490
|
}
|
|
466
491
|
return config;
|
|
@@ -470,7 +495,7 @@ function pluginCore(opts) {
|
|
|
470
495
|
for (const [key, rel] of Object.entries(mfMerged.exposes)) {
|
|
471
496
|
const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
|
|
472
497
|
const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
473
|
-
force[safe] = new RegExp(`${escapeRegExp(abs)}
|
|
498
|
+
force[safe] = new RegExp(`${escapeRegExp(abs)}(\\?.*)?$`);
|
|
474
499
|
}
|
|
475
500
|
api.modifyRsbuildConfig((config) => {
|
|
476
501
|
(config.performance ??= {}).chunkSplit ??= {};
|