@module-federation/rsbuild-plugin 0.0.0-next-20241021083129 → 0.0.0-next-20241021084851

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.cjs.js CHANGED
@@ -5,6 +5,8 @@ var rspack = require('@module-federation/enhanced/rspack');
5
5
  var sdk = require('@module-federation/sdk');
6
6
  var util = require('util');
7
7
 
8
+ var DEFAULT_ASSET_PREFIX = '/';
9
+
8
10
  function isRegExp(target) {
9
11
  return util.types.isRegExp(target);
10
12
  }
@@ -297,14 +299,24 @@ var pluginModuleFederation = function(moduleFederationOptions) {
297
299
  return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
298
300
  });
299
301
  api.modifyRsbuildConfig(function(config) {
300
- var _config_server, _config_dev_client, _config_dev;
301
- // If this is a provider app, Rsbuild should send the ws request to the provider's dev server.
302
- // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
303
- if (moduleFederationOptions.exposes && ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : (_config_dev_client = _config_dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
304
- var _config, _config_dev1;
302
+ // Change some default configs for remote modules
303
+ if (moduleFederationOptions.exposes) {
304
+ var _config_server, _config_dev_client, _originalConfig_dev;
305
+ var _config;
305
306
  (_config = config).dev || (_config.dev = {});
306
- (_config_dev1 = config.dev).client || (_config_dev1.client = {});
307
- config.dev.client.port = config.server.port;
307
+ // For remote modules, Rsbuild should send the ws request to the provider's dev server.
308
+ // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
309
+ if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
310
+ var _config_dev;
311
+ (_config_dev = config.dev).client || (_config_dev.client = {});
312
+ config.dev.client.port = config.server.port;
313
+ }
314
+ // Change the default assetPrefix to `true` for remote modules.
315
+ // This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
316
+ var originalConfig = api.getRsbuildConfig('original');
317
+ if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === DEFAULT_ASSET_PREFIX) {
318
+ config.dev.assetPrefix = true;
319
+ }
308
320
  }
309
321
  });
310
322
  api.modifyEnvironmentConfig(function(config, param) {
@@ -375,7 +387,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
375
387
  });
376
388
  api.modifyBundlerChain(/*#__PURE__*/ function() {
377
389
  var _ref = _async_to_generator(function(chain) {
378
- var publicPath;
379
390
  return _ts_generator(this, function(_state) {
380
391
  chain.plugin('module-federation').use(rspack.ModuleFederationPlugin, [
381
392
  moduleFederationOptions
@@ -384,11 +395,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
384
395
  if (!chain.output.get('uniqueName')) {
385
396
  chain.output.set('uniqueName', moduleFederationOptions.name);
386
397
  }
387
- publicPath = chain.output.get('publicPath');
388
- // set the default publicPath to 'auto' to make MF work
389
- if (publicPath === '/') {
390
- chain.output.set('publicPath', 'auto');
391
- }
392
398
  return [
393
399
  2
394
400
  ];
package/dist/index.esm.js CHANGED
@@ -3,6 +3,8 @@ import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
3
3
  import { isRequiredVersion } from '@module-federation/sdk';
4
4
  import util from 'util';
5
5
 
6
+ var DEFAULT_ASSET_PREFIX = '/';
7
+
6
8
  function isRegExp(target) {
7
9
  return util.types.isRegExp(target);
8
10
  }
@@ -295,14 +297,24 @@ var pluginModuleFederation = function(moduleFederationOptions) {
295
297
  return shared[0].endsWith('/') ? shared[0].slice(0, -1) : shared[0];
296
298
  });
297
299
  api.modifyRsbuildConfig(function(config) {
298
- var _config_server, _config_dev_client, _config_dev;
299
- // If this is a provider app, Rsbuild should send the ws request to the provider's dev server.
300
- // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
301
- if (moduleFederationOptions.exposes && ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : (_config_dev_client = _config_dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
302
- var _config, _config_dev1;
300
+ // Change some default configs for remote modules
301
+ if (moduleFederationOptions.exposes) {
302
+ var _config_server, _config_dev_client, _originalConfig_dev;
303
+ var _config;
303
304
  (_config = config).dev || (_config.dev = {});
304
- (_config_dev1 = config.dev).client || (_config_dev1.client = {});
305
- config.dev.client.port = config.server.port;
305
+ // For remote modules, Rsbuild should send the ws request to the provider's dev server.
306
+ // This allows the provider to do HMR when the provider module is loaded in the consumer's page.
307
+ if (((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.port) && !((_config_dev_client = config.dev.client) === null || _config_dev_client === void 0 ? void 0 : _config_dev_client.port)) {
308
+ var _config_dev;
309
+ (_config_dev = config.dev).client || (_config_dev.client = {});
310
+ config.dev.client.port = config.server.port;
311
+ }
312
+ // Change the default assetPrefix to `true` for remote modules.
313
+ // This ensures that the remote module's assets can be requested by consumer apps with the correct URL.
314
+ var originalConfig = api.getRsbuildConfig('original');
315
+ if (((_originalConfig_dev = originalConfig.dev) === null || _originalConfig_dev === void 0 ? void 0 : _originalConfig_dev.assetPrefix) === undefined && config.dev.assetPrefix === DEFAULT_ASSET_PREFIX) {
316
+ config.dev.assetPrefix = true;
317
+ }
306
318
  }
307
319
  });
308
320
  api.modifyEnvironmentConfig(function(config, param) {
@@ -373,7 +385,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
373
385
  });
374
386
  api.modifyBundlerChain(/*#__PURE__*/ function() {
375
387
  var _ref = _async_to_generator(function(chain) {
376
- var publicPath;
377
388
  return _ts_generator(this, function(_state) {
378
389
  chain.plugin('module-federation').use(ModuleFederationPlugin, [
379
390
  moduleFederationOptions
@@ -382,11 +393,6 @@ var pluginModuleFederation = function(moduleFederationOptions) {
382
393
  if (!chain.output.get('uniqueName')) {
383
394
  chain.output.set('uniqueName', moduleFederationOptions.name);
384
395
  }
385
- publicPath = chain.output.get('publicPath');
386
- // set the default publicPath to 'auto' to make MF work
387
- if (publicPath === '/') {
388
- chain.output.set('publicPath', 'auto');
389
- }
390
396
  return [
391
397
  2
392
398
  ];
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_ASSET_PREFIX = "/";
@@ -1 +1,2 @@
1
1
  export declare function isRegExp(target: any): target is RegExp;
2
+ export * from './constant';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/rsbuild-plugin",
3
- "version": "0.0.0-next-20241021083129",
3
+ "version": "0.0.0-next-20241021084851",
4
4
  "description": "Module Federation plugin for Rsbuild",
5
5
  "homepage": "https://module-federation.io",
6
6
  "bugs": {
@@ -32,14 +32,14 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@module-federation/sdk": "0.0.0-next-20241021083129"
35
+ "@module-federation/sdk": "0.0.0-next-20241021084851"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@rsbuild/core": "1.x"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@rsbuild/core": "1.x",
42
- "@module-federation/enhanced": "0.0.0-next-20241021083129"
42
+ "@module-federation/enhanced": "0.0.0-next-20241021084851"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=16.0.0"