Skip to content

Commit 0ee5e60

Browse files
committed
works with rspack
1 parent 402d95c commit 0ee5e60

9 files changed

Lines changed: 557 additions & 2759 deletions

File tree

pnpm-lock.yaml

Lines changed: 514 additions & 2676 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import React from "react";
22

3-
export const App: React.FC = () => <p>Hello from Client</p>;
3+
export const App: React.FC = () => <p>Rspack + React + SSR + ESM</p>;

rspack/react-ssr-esm/dev.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { spawn } from "cross-spawn";
22
import path from "path";
3-
import webpack from "webpack";
4-
import webpackConfigClient from "./webpack.config.client.js";
5-
import webpackConfigServer from "./webpack.config.server.js";
3+
import rspack from "@rspack/core";
4+
import rspackConfigClient from "./rspack.config.client.js";
5+
import rspackConfigServer from "./rspack.config.server.js";
66
import { fileURLToPath } from 'url'
77
import { dirname } from 'path'
88

99
const __filename = fileURLToPath(import.meta.url)
1010
const __dirname = dirname(__filename)
1111

12-
const compiler = webpack([
12+
const compiler = rspack([
1313
{
14-
...webpackConfigClient,
14+
...rspackConfigClient,
1515
mode: "development",
1616
devtool: "source-map",
1717
output: {
18-
...webpackConfigClient.output,
18+
...rspackConfigClient.output,
1919
filename: "[name].js",
2020
},
2121
},
2222
{
23-
...webpackConfigServer,
23+
...rspackConfigServer,
2424
mode: "development",
2525
devtool: "source-map",
2626
},

rspack/react-ssr-esm/package.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,27 @@
33
"version": "1.0.0",
44
"type": "module",
55
"scripts": {
6-
"build:server": "webpack --config webpack.config.server.js",
7-
"build:client": "webpack --config webpack.config.client.js",
6+
"build:server": "rspack --config rspack.config.server.js",
7+
"build:client": "rspack --config rspack.config.client.js",
88
"start": "node ./dist/server.js",
99
"start:dev": "node dev.js"
1010
},
1111
"devDependencies": {
12-
"@types/cross-spawn": "^6.0.2",
13-
"@types/express": "^4.17.11",
14-
"@types/node": "^14.14.35",
15-
"@types/react": "^17.0.3",
16-
"@types/react-dom": "^17.0.3",
17-
"clean-webpack-plugin": "^3.0.0",
18-
"copy-webpack-plugin": "^8.1.0",
19-
"cross-spawn": "^7.0.3",
20-
"ts-loader": "^8.0.18",
21-
"typescript": "^4.2.3",
22-
"webpack": "^5.101.1",
23-
"webpack-cli": "^4.5.0",
24-
"webpack-manifest-plugin": "^3.1.0",
25-
"webpack-node-externals": "^2.5.2"
12+
"@types/cross-spawn": "^6.0.6",
13+
"@types/express": "^5.0.3",
14+
"@types/node": "^22.17.1",
15+
"@types/react": "^19.1.9",
16+
"@types/react-dom": "^19.1.7",
17+
"cross-spawn": "^7.0.6",
18+
"typescript": "^5.9.2",
19+
"rspack-manifest-plugin": "^5.0.3",
20+
"@rspack/core": "1.4.11",
21+
"@rspack/cli": "1.4.11"
2622
},
2723
"dependencies": {
28-
"ejs": "^3.1.6",
29-
"express": "^4.17.1",
30-
"react": "^17.0.2",
31-
"react-dom": "^17.0.2"
24+
"ejs": "^3.1.10",
25+
"express": "^5.1.0",
26+
"react": "^19.1.1",
27+
"react-dom": "^19.1.1"
3228
}
3329
}

rspack/react-ssr-esm/webpack.config.client.js renamed to rspack/react-ssr-esm/rspack.config.client.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from "path";
2-
import { CleanWebpackPlugin } from "clean-webpack-plugin";
3-
import { WebpackManifestPlugin } from "webpack-manifest-plugin";
2+
import { RspackManifestPlugin } from "rspack-manifest-plugin";
43
import { fileURLToPath } from "url";
54

65
const __filename = fileURLToPath(import.meta.url);
@@ -13,6 +12,7 @@ export default {
1312
},
1413
mode: "production",
1514
output: {
15+
clean: true,
1616
path: path.resolve(__dirname + "/dist/static"),
1717
filename: "[name].[contenthash].js",
1818
publicPath: "",
@@ -24,13 +24,16 @@ export default {
2424
rules: [
2525
{
2626
test: /\.tsx?$/,
27-
loader: "ts-loader",
28-
options: {
29-
configFile: "tsconfig.client.json",
30-
},
27+
loader: "builtin:swc-loader",
3128
},
3229
],
3330
},
3431
target: "web",
35-
plugins: [new CleanWebpackPlugin(), new WebpackManifestPlugin()],
32+
plugins: [new RspackManifestPlugin()],
33+
output: {
34+
module: true,
35+
},
36+
experiments: {
37+
outputModule: true,
38+
},
3639
};

rspack/react-ssr-esm/webpack.config.server.js renamed to rspack/react-ssr-esm/rspack.config.server.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// import nodeExternals from 'webpack-node-externals'
21
import path from 'path'
3-
import CopyPlugin from 'copy-webpack-plugin'
4-
import * as webpack from 'webpack'
2+
import rspack from '@rspack/core'
53
import { fileURLToPath } from 'url'
64
import { dirname } from 'path'
75

@@ -31,10 +29,7 @@ export default {
3129
rules: [
3230
{
3331
test: /\.tsx?$/,
34-
loader: 'ts-loader',
35-
options: {
36-
configFile: 'tsconfig.server.json',
37-
},
32+
loader: "builtin:swc-loader",
3833
},
3934
],
4035
},
@@ -45,16 +40,16 @@ export default {
4540
},
4641

4742
plugins: [
48-
new webpack.default.BannerPlugin({
43+
new rspack.BannerPlugin({
4944
banner: `
50-
import { fileURLToPath as __rspack_fileURLToPath } from 'url';
51-
import { dirname as __rspack_dirname } from 'path'
52-
const __filename = __rspack_fileURLToPath(import.meta.url);
53-
const __dirname = __rspack_dirname(__filename);
45+
import { fileURLToPath as __rspack_fileURLToPath } from 'url';
46+
import { dirname as __rspack_dirname } from 'path'
47+
const __filename = __rspack_fileURLToPath(import.meta.url);
48+
const __dirname = __rspack_dirname(__filename);
5449
`,
5550
raw: true,
5651
}),
57-
new CopyPlugin({
52+
new rspack.CopyRspackPlugin({
5853
patterns: [{ context: 'server', from: 'views', to: 'views' }],
5954
}),
6055
],

rspack/react-ssr-esm/server/views/client.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8" />
5-
<title>React + Node.js App</title>
5+
<title>Rspack + React + Node.js App</title>
66
</head>
77
<body>
88
<div id="root"><%- component %></div>

rspack/react-ssr-esm/tsconfig.client.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

rspack/react-ssr-esm/tsconfig.server.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)