Skip to content

Commit 81487f8

Browse files
committed
feat(create-rsbuild): add React 18 templates
1 parent 50f01a5 commit 81487f8

File tree

17 files changed

+206
-5
lines changed

17 files changed

+206
-5
lines changed

e2e/cases/create-rsbuild/jsTemplates.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ rspackOnlyTest('should create react project as expected', async () => {
99
expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy();
1010
});
1111

12+
rspackOnlyTest('should create react18 project as expected', async () => {
13+
const { pkgJson } = await createAndValidate(import.meta.dirname, 'react18');
14+
expect(pkgJson.dependencies.react.startsWith('^18')).toBeTruthy();
15+
expect(pkgJson.dependencies['react-dom'].startsWith('^18')).toBeTruthy();
16+
expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy();
17+
});
18+
1219
rspackOnlyTest('should create preact project as expected', async () => {
1320
const { pkgJson } = await createAndValidate(import.meta.dirname, 'preact');
1421
expect(pkgJson.dependencies.preact).toBeTruthy();

e2e/cases/create-rsbuild/tsTemplates.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ rspackOnlyTest('should create react-ts project as expected', async () => {
88
expect(pkgJson.dependencies['react-dom']).toBeTruthy();
99
expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy();
1010
});
11+
rspackOnlyTest('should create react18-ts project as expected', async () => {
12+
const { pkgJson } = await createAndValidate(
13+
import.meta.dirname,
14+
'react18-ts',
15+
);
16+
expect(pkgJson.dependencies.react.startsWith('^18')).toBeTruthy();
17+
expect(pkgJson.dependencies['react-dom'].startsWith('^18')).toBeTruthy();
18+
expect(pkgJson.devDependencies['@rsbuild/plugin-react']).toBeTruthy();
19+
});
1120

1221
rspackOnlyTest('should create preact-ts project as expected', async () => {
1322
const { pkgJson } = await createAndValidate(import.meta.dirname, 'preact-ts');

packages/create-rsbuild/src/index.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ async function getTemplateName({ template }: Argv) {
2929
message: 'Select framework',
3030
options: [
3131
{ value: 'vanilla', label: 'Vanilla' },
32-
{ value: 'react', label: 'React' },
32+
{ value: 'react', label: 'React 19' },
33+
{ value: 'react18', label: 'React 18' },
3334
{ value: 'vue3', label: 'Vue 3' },
3435
{ value: 'vue2', label: 'Vue 2' },
3536
{ value: 'lit', label: 'Lit' },
@@ -62,6 +63,10 @@ function mapESLintTemplate(templateName: string): ESLintTemplateName {
6263
case 'svelte-js':
6364
case 'svelte-ts':
6465
return templateName;
66+
case 'react18-js':
67+
return 'react-js';
68+
case 'react18-ts':
69+
return 'react-js';
6570
}
6671
const language = templateName.split('-')[1];
6772
return `vanilla-${language}` as ESLintTemplateName;
@@ -71,8 +76,12 @@ create({
7176
root: path.resolve(__dirname, '..'),
7277
name: 'rsbuild',
7378
templates: [
79+
'vanilla-js',
80+
'vanilla-ts',
7481
'react-js',
7582
'react-ts',
83+
'react18-js',
84+
'react18-ts',
7685
'vue3-js',
7786
'vue3-ts',
7887
'vue2-js',
@@ -81,8 +90,6 @@ create({
8190
'svelte-ts',
8291
'solid-js',
8392
'solid-ts',
84-
'vanilla-js',
85-
'vanilla-ts',
8693
],
8794
getTemplateName,
8895
mapESLintTemplate,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "rsbuild-react18-js",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "rsbuild build",
8+
"dev": "rsbuild dev --open",
9+
"preview": "rsbuild preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.3.1",
13+
"react-dom": "^18.3.1"
14+
},
15+
"devDependencies": {
16+
"@rsbuild/core": "^1.2.8",
17+
"@rsbuild/plugin-react": "^1.1.0"
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginReact } from '@rsbuild/plugin-react';
3+
4+
export default defineConfig({
5+
plugins: [pluginReact()],
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}
7+
8+
.content {
9+
display: flex;
10+
min-height: 100vh;
11+
line-height: 1.1;
12+
text-align: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
}
16+
17+
.content h1 {
18+
font-size: 3.6rem;
19+
font-weight: 700;
20+
}
21+
22+
.content p {
23+
font-size: 1.2rem;
24+
font-weight: 400;
25+
opacity: 0.5;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import './App.css';
2+
3+
const App = () => {
4+
return (
5+
<div className="content">
6+
<h1>Rsbuild with React</h1>
7+
<p>Start building amazing things with Rsbuild.</p>
8+
</div>
9+
);
10+
};
11+
12+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import App from './App';
4+
5+
const root = ReactDOM.createRoot(document.getElementById('root'));
6+
root.render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "rsbuild-react18-ts",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "rsbuild build",
8+
"dev": "rsbuild dev --open",
9+
"preview": "rsbuild preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.3.1",
13+
"react-dom": "^18.3.1"
14+
},
15+
"devDependencies": {
16+
"@rsbuild/core": "^1.2.8",
17+
"@rsbuild/plugin-react": "^1.1.0",
18+
"@types/react": "^18.3.18",
19+
"@types/react-dom": "^18.3.5",
20+
"typescript": "^5.7.3"
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginReact } from '@rsbuild/plugin-react';
3+
4+
export default defineConfig({
5+
plugins: [pluginReact()],
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}
7+
8+
.content {
9+
display: flex;
10+
min-height: 100vh;
11+
line-height: 1.1;
12+
text-align: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
}
16+
17+
.content h1 {
18+
font-size: 3.6rem;
19+
font-weight: 700;
20+
}
21+
22+
.content p {
23+
font-size: 1.2rem;
24+
font-weight: 400;
25+
opacity: 0.5;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import './App.css';
2+
3+
const App = () => {
4+
return (
5+
<div className="content">
6+
<h1>Rsbuild with React</h1>
7+
<p>Start building amazing things with Rsbuild.</p>
8+
</div>
9+
);
10+
};
11+
12+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rsbuild/core/types" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import App from './App';
4+
5+
const rootEl = document.getElementById('root');
6+
if (rootEl) {
7+
const root = ReactDOM.createRoot(rootEl);
8+
root.render(
9+
<React.StrictMode>
10+
<App />
11+
</React.StrictMode>,
12+
);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["DOM", "ES2020"],
4+
"jsx": "react-jsx",
5+
"target": "ES2020",
6+
"noEmit": true,
7+
"skipLibCheck": true,
8+
"useDefineForClassFields": true,
9+
10+
/* modules */
11+
"module": "ESNext",
12+
"isolatedModules": true,
13+
"resolveJsonModule": true,
14+
"moduleResolution": "Bundler",
15+
"allowImportingTsExtensions": true,
16+
17+
/* type checking */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true
21+
},
22+
"include": ["src"]
23+
}

website/docs/en/guide/start/quick-start.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ When creating a project, you can choose from the following templates provided by
5656
| -------- | ------------------------------- | ----------------- |
5757
| vanilla | Vanilla JavaScript | TypeScript |
5858
| react | [React 19](https://react.dev/) | TypeScript |
59-
| vue3 | [Vue 3](https://vuejs.org/) | TypeScript |
59+
| react18 | [React 18](https://react.dev/) | TypeScript |
60+
| vue | [Vue 3](https://vuejs.org/) | TypeScript |
6061
| vue2 | [Vue 2](https://v2.vuejs.org/) | TypeScript |
6162
| lit | [Lit](https://lit.dev/) | TypeScript |
6263
| preact | [Preact](https://preactjs.com/) | TypeScript |

website/docs/zh/guide/start/quick-start.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ import { PackageManagerTabs } from '@theme';
6161
| ------- | ------------------------------- | ---------- |
6262
| vanilla | 原生 JavaScript | TypeScript |
6363
| react | [React 19](https://react.dev/) | TypeScript |
64-
| vue3 | [Vue 3](https://vuejs.org/) | TypeScript |
64+
| react18 | [React 18](https://react.dev/) | TypeScript |
65+
| vue | [Vue 3](https://vuejs.org/) | TypeScript |
6566
| vue2 | [Vue 2](https://v2.vuejs.org/) | TypeScript |
6667
| lit | [Lit](https://lit.dev/) | TypeScript |
6768
| preact | [Preact](https://preactjs.com/) | TypeScript |

0 commit comments

Comments
 (0)