ptech-preset 1.1.5 → 1.1.6

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.d.ts CHANGED
@@ -13,12 +13,12 @@ type MfAutoOptions = {
13
13
  cssInjection?: CssInjectionMode;
14
14
  cssEntry?: string;
15
15
  stylesExposeKey?: string;
16
+ /** Ép tách chunk cho từng expose */
17
+ separateExposes?: boolean;
18
+ separateExposeChunkPrefix?: string;
16
19
  /** options chuyển nguyên vẹn sang @module-federation/rsbuild-plugin */
17
20
  mf: Record<string, any>;
18
21
  };
19
- /**
20
- * Plugin bọc (wrapper) để tự động hoá exposes/remotes rồi compose MF plugin.
21
- */
22
22
  declare function pluginMFAuto(opts: MfAutoOptions): RsbuildPlugin;
23
23
 
24
24
  export { type MfAutoOptions, pluginMFAuto as default, pluginMFAuto };
package/dist/index.js CHANGED
@@ -125,6 +125,7 @@ function normalizeExposePath(root, maybeRel) {
125
125
  const relFromRoot = path3.relative(root, abs).replace(/\\/g, "/");
126
126
  return `./${relFromRoot}`;
127
127
  }
128
+ var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
128
129
  function pluginMFAuto(opts) {
129
130
  const {
130
131
  baseDir = "src",
@@ -136,6 +137,8 @@ function pluginMFAuto(opts) {
136
137
  cssInjection = "none",
137
138
  cssEntry = "src/index.css",
138
139
  stylesExposeKey = "./styles",
140
+ separateExposes = true,
141
+ separateExposeChunkPrefix = "mf-expose-",
139
142
  mf
140
143
  } = opts;
141
144
  if (!mf || typeof mf !== "object") {
@@ -149,8 +152,7 @@ function pluginMFAuto(opts) {
149
152
  async setup(api) {
150
153
  const { pluginModuleFederation } = await import("@module-federation/rsbuild-plugin");
151
154
  const getExposes = async () => {
152
- if (exposesMode === "jsdoc")
153
- return collectAutoExposes({ baseDir, globs });
155
+ if (exposesMode === "jsdoc") return collectAutoExposes({ baseDir, globs });
154
156
  if (exposesMode === "wrapper")
155
157
  return collectAutoExposesWithWrapper({ baseDir, globs });
156
158
  const a = await collectAutoExposes({ baseDir, globs });
@@ -231,11 +233,25 @@ function pluginMFAuto(opts) {
231
233
  };
232
234
  }
233
235
  }
234
- if (typeof mfMerged.dts === "undefined") {
235
- mfMerged.dts = true;
236
- }
236
+ if (typeof mfMerged.dts === "undefined") mfMerged.dts = true;
237
237
  const mfPlugin = pluginModuleFederation(mfMerged);
238
238
  await mfPlugin.setup?.(api);
239
+ if (separateExposes && mfMerged.exposes) {
240
+ const force = {};
241
+ for (const [key, rel] of Object.entries(
242
+ mfMerged.exposes
243
+ )) {
244
+ const abs = path3.resolve(root, String(rel).replace(/^\.\//, "")).replace(/\\/g, "/");
245
+ const safe = separateExposeChunkPrefix + key.replace(/[^a-zA-Z0-9_]/g, "_");
246
+ force[safe] = new RegExp(`${escapeRegExp(abs)}$`);
247
+ }
248
+ api.modifyRsbuildConfig((config) => {
249
+ (config.performance ??= {}).chunkSplit ??= {};
250
+ const cs = config.performance.chunkSplit;
251
+ cs.forceSplitting = { ...cs.forceSplitting || {}, ...force };
252
+ return config;
253
+ });
254
+ }
239
255
  }
240
256
  };
241
257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptech-preset",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Auto Module.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",