Skip to content

Commit

Permalink
Merge branch 'bump_rslib_010' into dirname_shims_1115
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 21, 2024
2 parents a71523d + efce0e8 commit b151312
Show file tree
Hide file tree
Showing 48 changed files with 544 additions and 625 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-flies-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rsbuild/plugin-assets-retry': patch
---

fix(plugin-assets-retry): avoid **webpack_require**.e pollution
29 changes: 11 additions & 18 deletions e2e/cases/module-federation-v2/host/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { ModuleFederationPlugin } from '@module-federation/rspack';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'host',
remotes: {
remote: `remote@http://localhost:${process.env.REMOTE_PORT || 3002}/mf-manifest.json`,
},
shared: ['react', 'react-dom'],
}),
],
dev: {
writeToDisk: true,
},
tools: {
rspack: {
output: {
uniqueName: 'host',
},
plugins: [
new ModuleFederationPlugin({
name: 'host',
remotes: {
remote: `remote@http://localhost:${process.env.REMOTE_PORT || 3002}/mf-manifest.json`,
},
shared: ['react', 'react-dom'],
}),
],
},
},
});
56 changes: 30 additions & 26 deletions e2e/cases/module-federation-v2/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,44 @@ rspackOnlyTest(
},
);

// TODO support for remote HMR
test.skip('should allow remote module to perform HMR', async ({ page }) => {
// HMR cases will fail in Windows
if (process.platform === 'win32') {
test.skip();
}
rspackOnlyTest(
'should allow remote module to perform HMR',
async ({ page }) => {
// HMR cases will fail in Windows
if (process.platform === 'win32') {
test.skip();
}

writeButtonCode();
writeButtonCode();

const remotePort = await getRandomPort();
const remotePort = await getRandomPort();

process.env.REMOTE_PORT = remotePort.toString();
process.env.REMOTE_PORT = remotePort.toString();

const remoteApp = await dev({
cwd: remote,
});
const hostApp = await dev({
cwd: host,
});
const remoteApp = await dev({
cwd: remote,
});
const hostApp = await dev({
cwd: host,
});

await gotoPage(page, remoteApp);
await expect(page.locator('#title')).toHaveText('Remote');
await expect(page.locator('#button')).toHaveText('Button from remote');
await gotoPage(page, remoteApp);
await expect(page.locator('#title')).toHaveText('Remote');
await expect(page.locator('#button')).toHaveText('Button from remote');

await gotoPage(page, hostApp);
await expect(page.locator('#title')).toHaveText('Host');
await expect(page.locator('#button')).toHaveText('Button from remote');
await gotoPage(page, hostApp);
await expect(page.locator('#title')).toHaveText('Host');
await expect(page.locator('#button')).toHaveText('Button from remote');

writeButtonCode('Button from remote (HMR)');
await expect(page.locator('#button')).toHaveText('Button from remote (HMR)');
writeButtonCode('Button from remote (HMR)');
await expect(page.locator('#button')).toHaveText(
'Button from remote (HMR)',
);

await hostApp.close();
await remoteApp.close();
});
await hostApp.close();
await remoteApp.close();
},
);

// TODO downgrade syntax
test.skip('should transform module federation runtime with SWC', async () => {
Expand Down
30 changes: 11 additions & 19 deletions e2e/cases/module-federation-v2/remote/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import { ModuleFederationPlugin } from '@module-federation/rspack';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'remote',
exposes: {
'./Button': './src/test-temp-Button',
},
shared: ['react', 'react-dom'],
}),
],
server: {
port: Number(process.env.REMOTE_PORT) || 3002,
},
dev: {
writeToDisk: true,
assetPrefix: true,
},
tools: {
rspack: {
output: {
uniqueName: 'remote',
},
plugins: [
new ModuleFederationPlugin({
name: 'remote',
exposes: {
'./Button': './src/test-temp-Button',
},
shared: ['react', 'react-dom'],
}),
],
},
},
});
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rsbuild/plugin-vue": "workspace:*",
"@rsbuild/plugin-vue-jsx": "^1.0.1",
"@rsbuild/webpack": "workspace:*",
"@module-federation/rspack": "0.7.6",
"@module-federation/rsbuild-plugin": "0.7.6",
"@scripts/test-helper": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.13",
Expand Down
2 changes: 1 addition & 1 deletion examples/module-federation-v2/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@module-federation/rspack": "0.7.6",
"@module-federation/rsbuild-plugin": "0.7.6",
"@rsbuild/core": "workspace:*",
"@rsbuild/plugin-react": "workspace:*"
}
Expand Down
29 changes: 11 additions & 18 deletions examples/module-federation-v2/host/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { ModuleFederationPlugin } from '@module-federation/rspack';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'host',
remotes: {
remote: 'remote@http://localhost:3002/mf-manifest.json',
},
shared: ['react', 'react-dom'],
}),
],
server: {
port: 3000,
},
tools: {
rspack: {
output: {
uniqueName: 'host',
},
plugins: [
new ModuleFederationPlugin({
name: 'host',
remotes: {
remote: 'remote@http://localhost:3002/mf-manifest.json',
},
shared: ['react', 'react-dom'],
}),
],
},
},
});
2 changes: 1 addition & 1 deletion examples/module-federation-v2/remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@module-federation/rspack": "0.7.6",
"@module-federation/rsbuild-plugin": "0.7.6",
"@rsbuild/core": "workspace:*",
"@rsbuild/plugin-react": "workspace:*"
}
Expand Down
32 changes: 11 additions & 21 deletions examples/module-federation-v2/remote/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { ModuleFederationPlugin } from '@module-federation/rspack';
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
plugins: [
pluginReact(),
pluginModuleFederation({
name: 'remote',
exposes: {
'./Button': './src/Button',
},
shared: ['react', 'react-dom'],
}),
],
server: {
port: 3002,
},
dev: {
assetPrefix: true,
},
tools: {
rspack: {
output: {
uniqueName: 'remote',
},
plugins: [
new ModuleFederationPlugin({
name: 'remote',
exposes: {
'./Button': './src/Button',
},
shared: ['react', 'react-dom'],
}),
],
},
},
});
2 changes: 1 addition & 1 deletion packages/compat/plugin-webpack-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@rsbuild/webpack": "workspace:*",
"@rslib/core": "0.0.18",
"@rslib/core": "0.1.0",
"@types/lodash": "^4.17.13",
"@types/semver": "^7.5.8",
"typescript": "^5.6.3",
Expand Down
25 changes: 14 additions & 11 deletions packages/compat/plugin-webpack-swc/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { defineConfig } from '@rslib/core';
export default defineConfig({
...dualPackage,
lib: [
...dualPackage.lib.map((config) => {
if (config.format === 'cjs') {
config.source = {
entry: {
index: './src/index.ts',
loader: './src/loader.ts',
},
};
}
return config;
}),
...dualPackage.lib,
{
format: 'esm',
source: {
entry: {
loader: './src/loader.ts',
},
},
output: {
filename: {
js: '[name].mjs',
},
},
},
],
});
4 changes: 2 additions & 2 deletions packages/compat/plugin-webpack-swc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({
rule
.test(test || /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/)
.use(CHAIN_ID.USE.SWC)
.loader(path.resolve(__dirname, './loader.cjs'))
.loader(path.resolve(__dirname, './loader.mjs'))
.options(removeUselessOptions(swcConfig) satisfies TransformConfig);

if (include) {
Expand Down Expand Up @@ -103,7 +103,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({
.resolve.set('fullySpecified', false)
.end()
.use(CHAIN_ID.USE.SWC)
.loader(path.resolve(__dirname, './loader.cjs'))
.loader(path.resolve(__dirname, './loader.mjs'))
.options(removeUselessOptions(mainConfig) satisfies TransformConfig);
},
});
Expand Down
Loading

0 comments on commit b151312

Please sign in to comment.