Skip to content

feat(rspack): Node Support Via Runtime plugin #3808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loadable-react-18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "pnpm --filter loadable-react-18_* build",
"serve": "pnpm --filter loadable-react-18_* --parallel serve",
"clean": "pnpm --filter loadable-react-18_* --parallel clean",
"e2e:ci": "pnpm start & wait-on tcp:3000 && wait-on tcp:3001 && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome && kill-port 3000 3001 3002"
"e2e:ci": "pnpm start & sleep 2 && wait-on tcp:3000 && wait-on tcp:3001 && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome && kill-port 3000 3001 3002"
},
"devDependencies": {
"wait-on": "7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion nextjs-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"main": "index.js",
"scripts": {
"start": "pnpm --parallel --filter nextjs-react_* run dev",
"e2e:ci": "pnpm start & wait-on http-get://localhost:3000/ && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/runAll.cy.ts\" --browser=chrome"
"e2e:ci": "pnpm start & sleep 2 && wait-on http-get://localhost:3000/ && wait-on http-get://localhost:3001/ && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/runAll.cy.ts\" --browser=chrome"
},
"keywords": [],
"author": "rahulteja-dev",
Expand Down
2 changes: 1 addition & 1 deletion nextjs-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": " pnpm --parallel --filter nextjs-ssr_* dev",
"build": "pnpm --parallel --filter nextjs-ssr_* build",
"serve": "pnpm --parallel --filter nextjs-ssr_* start",
"e2e:ci": "pnpm run start & wait-on http-get://localhost:3001/ && wait-on http-get://localhost:3002/ && wait-on http-get://localhost:3000/ && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome"
"e2e:ci": "pnpm run start & sleep 10 && wait-on http-get://localhost:3001/ && wait-on http-get://localhost:3002/ && wait-on http-get://localhost:3000/ && npx cypress run --config-file ../cypress-e2e/config/cypress.config.ts --config '{\"supportFile\": \"../cypress-e2e/support/e2e.ts\"}' --spec \"./e2e/*.cy.ts\" --browser=chrome"
},
"dependencies": {
"concurrently": "^8.2.2",
Expand Down
58 changes: 39 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rspack-webpack-interop/app-01/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log(__webpack_require__.federation);
import('./bootstrap');
13 changes: 8 additions & 5 deletions simple-node/node-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "node-host-1234",
"version": "1.0.0",
"scripts": {
"start": "webpack serve --config webpack.config.js"
},
"dependencies": {
"@module-federation/node": "^2.2.0"
"start:legacy": "webpack serve --config webpack.config.js",
"start": "rspack serve --config rspack.config.js"
},
"devDependencies": {
"@module-federation/node": "^2.2.0",
"@module-federation/enhanced": "^0.1.9",
"webpack": "^5.91.0",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^4.0.0"
"webpack-dev-server": "^4.0.0",
"@rspack/core": "^0.6.2",
"@rspack/cli": "^0.6.2",
"@rspack/dev-server": "^0.6.2"
}
}
39 changes: 39 additions & 0 deletions simple-node/node-host/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { container:{ModuleFederationPlugin} } = require('@rspack/core');
const path = require('path');

module.exports = {
cache: false,
devtool: false,
entry: './src/main.js',
mode:'development',
target: 'async-node',
output: {
path: path.join(__dirname, 'dist'),
filename: 'server.js',
},
module: {
rules: [],
},
devServer: {
port: 3000,
devMiddleware: {
writeToDisk: true,
},
onAfterSetupMiddleware: function() {
setTimeout(() => {
const app = require('./dist/server.js');
}, 3000);
}
},
plugins: [
new ModuleFederationPlugin({
remoteType: 'script',
name: 'node_host',
runtimePlugins: [require.resolve('@module-federation/node/runtimePlugin')],
remotes: {
"node_local_remote": 'commonjs ../../node-local-remote/dist/remoteEntry.js',
"node_remote": 'node_remote@http://localhost:3002/remoteEntry.js',
},
})
]
};
2 changes: 0 additions & 2 deletions simple-node/node-host/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import express from 'express';
import * as path from 'path';

Expand All @@ -11,7 +10,6 @@ import node_local_remote from 'node_local_remote/test';
import('node_remote/test').then((m) => {
console.log('\x1b[32m%s\x1b[0m', m.default || m);
//eslint-disable-next-line
console.log(__webpack_require__.federation);
if(process.env.E2E) {
process.exit(0);
}
Expand Down
9 changes: 4 additions & 5 deletions simple-node/node-host/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { UniversalFederationPlugin } = require('@module-federation/node');
const { ModuleFederationPlugin } = require('@module-federation/enhanced');
const path = require('path');

module.exports = {
cache: false,
devtool: false,
entry: './src/main.js',
mode:'development',
target: false, // in order to ignore built-in modules like path, fs, etc.
target: 'async-node', // in order to ignore built-in modules like path, fs, etc.
output: {
path: path.join(__dirname, 'dist'),
filename: 'server.js',
Expand All @@ -26,15 +26,14 @@ module.exports = {
}
},
plugins: [
new UniversalFederationPlugin({
new ModuleFederationPlugin({
remoteType: 'script',
isServer: true,
name: 'node_host',
runtimePlugins: [require.resolve('@module-federation/node/runtimePlugin')],
remotes: {
"node_local_remote": 'commonjs ../../node-local-remote/dist/remoteEntry.js',
"node_remote": 'node_remote@http://localhost:3002/remoteEntry.js',
},
experiments: {},
})
]
};
13 changes: 8 additions & 5 deletions simple-node/node-local-remote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "node-local-remote",
"version": "1.0.0",
"scripts": {
"start": "webpack serve --config webpack.config.js"
},
"dependencies": {
"@module-federation/node": "^2.2.0"
"start:legacy": "webpack serve --config webpack.config.js",
"start": "rspack serve --config rspack.config.js"
},
"devDependencies": {
"@module-federation/node": "^2.2.0",
"@module-federation/enhanced": "^0.1.9",
"webpack": "^5.91.0",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^4.0.0"
"webpack-dev-server": "^4.0.0",
"@rspack/core": "^0.6.2",
"@rspack/cli": "^0.6.2",
"@rspack/dev-server": "^0.6.2"
}
}
33 changes: 33 additions & 0 deletions simple-node/node-local-remote/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');
const { container:{ModuleFederationPlugin} } = require('@rspack/core');

module.exports = {
mode: 'development',
entry: './src/main.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
// publicPath: 'auto',
},
target: 'async-node',
devtool: false,
cache: false,
devServer: {
port: 3001,
devMiddleware: {
writeToDisk: true,
},
},
plugins: [
new ModuleFederationPlugin({
isServer: true,
name: 'node_local_remote',
library: { type: 'commonjs-module' },
filename: 'remoteEntry.js',
exposes: {
'./test': './src/expose.js',
},
runtimePlugins: [require.resolve('@module-federation/node/runtimePlugin')],
})
]
};
Loading