Skip to content

Commit a86133e

Browse files
authored
chore: setup example project (#80)
1 parent 39a0f52 commit a86133e

File tree

12 files changed

+782
-0
lines changed

12 files changed

+782
-0
lines changed

example/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Rspack project
2+
3+
## Get started
4+
5+
Start the dev server, and the app will be available at <http://localhost:8080>.
6+
7+
```bash
8+
pnpm run dev
9+
```
10+
11+
Build the app for production:
12+
13+
```bash
14+
pnpm run build
15+
```
16+
17+
Preview the production build locally:
18+
19+
```bash
20+
pnpm run preview
21+
```
22+
23+
## Learn more
24+
25+
To learn more about Rspack, check out the following resources:
26+
27+
- [Rspack documentation](https://rspack.rs) - explore Rspack features and APIs.
28+
- [Rspack GitHub repository](https://github.com/web-infra-dev/rspack) - your feedback and contributions are welcome!

example/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/react.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Rspack + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
</body>
12+
</html>

example/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "example",
3+
"private": true,
4+
"version": "1.0.0",
5+
"scripts": {
6+
"dev": "rspack dev",
7+
"build": "rspack build",
8+
"preview": "rspack preview"
9+
},
10+
"dependencies": {
11+
"react": "^19.2.4",
12+
"react-dom": "^19.2.4"
13+
},
14+
"devDependencies": {
15+
"@rspack/cli": "2.0.0-beta.6",
16+
"@rspack/core": "2.0.0-beta.6",
17+
"@rspack/dev-server": "2.0.0-beta.7",
18+
"@rspack/plugin-react-refresh": "workspace:*",
19+
"@types/react": "^19.2.14",
20+
"@types/react-dom": "^19.2.3",
21+
"react-refresh": "^0.18.0",
22+
"typescript": "^5.9.3"
23+
}
24+
}

example/rspack.config.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { defineConfig } from '@rspack/cli';
2+
import { type SwcLoaderOptions, rspack } from '@rspack/core';
3+
import { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';
4+
5+
const isDev = process.env.NODE_ENV === 'development';
6+
7+
export default defineConfig({
8+
entry: {
9+
main: './src/main.tsx',
10+
},
11+
target: ['browserslist:last 2 versions, > 0.2%, not dead, Firefox ESR'],
12+
resolve: {
13+
extensions: ['...', '.ts', '.tsx', '.jsx'],
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /\.svg$/,
19+
type: 'asset',
20+
},
21+
{
22+
test: /\.css$/,
23+
type: 'css/auto',
24+
},
25+
{
26+
test: /\.(jsx?|tsx?)$/,
27+
use: [
28+
{
29+
loader: 'builtin:swc-loader',
30+
options: {
31+
jsc: {
32+
parser: {
33+
syntax: 'typescript',
34+
tsx: true,
35+
},
36+
transform: {
37+
react: {
38+
runtime: 'automatic',
39+
development: isDev,
40+
refresh: isDev,
41+
},
42+
},
43+
},
44+
} satisfies SwcLoaderOptions,
45+
},
46+
],
47+
},
48+
],
49+
},
50+
plugins: [
51+
new rspack.HtmlRspackPlugin({
52+
template: './index.html',
53+
}),
54+
isDev
55+
? new ReactRefreshRspackPlugin({
56+
overlay: true,
57+
})
58+
: null,
59+
],
60+
});

example/src/App.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
}
13+
.logo:hover {
14+
filter: drop-shadow(0 0 2em #646cffaa);
15+
}
16+
.logo.react:hover {
17+
filter: drop-shadow(0 0 2em #61dafbaa);
18+
}
19+
20+
@keyframes logo-spin {
21+
from {
22+
transform: rotate(0deg);
23+
}
24+
to {
25+
transform: rotate(360deg);
26+
}
27+
}
28+
29+
@media (prefers-reduced-motion: no-preference) {
30+
a > .logo {
31+
animation: logo-spin infinite 20s linear;
32+
}
33+
}
34+
35+
.card {
36+
padding: 2em;
37+
}
38+
39+
.read-the-docs {
40+
color: #888;
41+
}

example/src/App.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useState } from 'react';
2+
import reactLogo from './assets/react.svg';
3+
import './App.css';
4+
5+
function App() {
6+
const [count, setCount] = useState(0);
7+
8+
return (
9+
<div className="App">
10+
<div>
11+
<a href="https://reactjs.org" target="_blank" rel="noreferrer">
12+
<img src={reactLogo} className="logo react" alt="React logo" />
13+
</a>
14+
</div>
15+
<h1>Rspack + React + TypeScript</h1>
16+
<div className="card">
17+
<button type="button" onClick={() => setCount((count) => count + 1)}>
18+
count is {count}
19+
</button>
20+
<p>
21+
Edit <code>src/App.tsx</code> and save to test HMR
22+
</p>
23+
</div>
24+
<p className="read-the-docs">
25+
Click on the Rspack and React logos to learn more
26+
</p>
27+
</div>
28+
);
29+
}
30+
31+
export default App;

example/src/assets/react.svg

Lines changed: 1 addition & 0 deletions
Loading

example/src/index.css

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
:root {
2+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
3+
font-size: 16px;
4+
line-height: 24px;
5+
font-weight: 400;
6+
7+
color-scheme: light dark;
8+
color: rgba(255, 255, 255, 0.87);
9+
background-color: #242424;
10+
11+
font-synthesis: none;
12+
text-rendering: optimizeLegibility;
13+
-webkit-font-smoothing: antialiased;
14+
-moz-osx-font-smoothing: grayscale;
15+
-webkit-text-size-adjust: 100%;
16+
}
17+
18+
a {
19+
font-weight: 500;
20+
color: #646cff;
21+
text-decoration: inherit;
22+
}
23+
a:hover {
24+
color: #535bf2;
25+
}
26+
27+
body {
28+
margin: 0;
29+
display: flex;
30+
place-items: center;
31+
min-width: 320px;
32+
min-height: 100vh;
33+
}
34+
35+
h1 {
36+
font-size: 3.2em;
37+
line-height: 1.1;
38+
}
39+
40+
button {
41+
border-radius: 8px;
42+
border: 1px solid transparent;
43+
padding: 0.6em 1.2em;
44+
font-size: 1em;
45+
font-weight: 500;
46+
font-family: inherit;
47+
background-color: #1a1a1a;
48+
cursor: pointer;
49+
transition: border-color 0.25s;
50+
}
51+
button:hover {
52+
border-color: #646cff;
53+
}
54+
button:focus,
55+
button:focus-visible {
56+
outline: 4px auto -webkit-focus-ring-color;
57+
}
58+
59+
@media (prefers-color-scheme: light) {
60+
:root {
61+
color: #213547;
62+
background-color: #ffffff;
63+
}
64+
a:hover {
65+
color: #747bff;
66+
}
67+
button {
68+
background-color: #f9f9f9;
69+
}
70+
}

example/src/main.tsx

Lines changed: 10 additions & 0 deletions
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.tsx';
4+
import './index.css';
5+
6+
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
);

example/tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
"resolveJsonModule": true,
13+
"moduleResolution": "bundler",
14+
"allowImportingTsExtensions": true,
15+
16+
/* type checking */
17+
"strict": true,
18+
"noUnusedLocals": true,
19+
"noUnusedParameters": true
20+
},
21+
"include": ["src"]
22+
}

0 commit comments

Comments
 (0)