Skip to content

Commit 90fa3ae

Browse files
committed
feat: add with-react examples
1 parent ba3c345 commit 90fa3ae

File tree

15 files changed

+3480
-2618
lines changed

15 files changed

+3480
-2618
lines changed

examples/with-react/manifest.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from "fs";
2+
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf8"));
3+
4+
const manifest: chrome.runtime.ManifestV3 = {
5+
manifest_version: 3,
6+
name: packageJson.name,
7+
version: packageJson.version,
8+
description: packageJson.description || "",
9+
action: {
10+
default_popup: "./src/popup/index.html",
11+
},
12+
background: {
13+
service_worker: "./src/background/index.ts",
14+
type: "module",
15+
},
16+
devtools_page: "./src/devtools/index.html",
17+
};
18+
19+
export default manifest;

examples/with-react/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "rsbuild-chrome-extension-boilerplate-react",
3+
"description": "A boilerplate for building Chrome extensions with rsbuild and React",
4+
"private": true,
5+
"version": "1.0.0",
6+
"scripts": {
7+
"dev": "rsbuild dev --open",
8+
"build:watch": "rsbuild build --watch",
9+
"build": "rsbuild build",
10+
"preview": "rsbuild preview"
11+
},
12+
"type": "module",
13+
"dependencies": {
14+
"react": "^19.0.0",
15+
"react-dom": "^19.0.0"
16+
},
17+
"devDependencies": {
18+
"rsbuild-plugin-web-extension": "0.0.10",
19+
"@rsbuild/core": "^1.0.16",
20+
"@rsbuild/plugin-react": "^1.0.5",
21+
"@types/chrome": "^0.0.263",
22+
"@types/node": "^20.11.28",
23+
"@types/react": "^18.2.47",
24+
"@types/react-dom": "^18.2.18",
25+
"typescript": "^5.4.2"
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from "@rsbuild/core";
2+
import { pluginReact } from "@rsbuild/plugin-react";
3+
import { pluginWebExtension } from "rsbuild-plugin-web-extension";
4+
import manifest from "./manifest";
5+
6+
export default defineConfig({
7+
plugins: [
8+
pluginReact(),
9+
pluginWebExtension({
10+
manifest,
11+
}),
12+
],
13+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("background script");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useState } from "react";
2+
3+
export const DevTools = () => {
4+
const [count, setCount] = useState(0);
5+
6+
return (
7+
<div>
8+
<p>Count: {count}</p>
9+
<button onClick={() => setCount(count + 1)}>Increment</button>
10+
</div>
11+
);
12+
};
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+
<title>DevTools</title>
6+
</head>
7+
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
<script type="module" src="./index.tsx"></script>
12+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createRoot } from "react-dom/client";
2+
import { DevTools } from "./devtools";
3+
4+
const root = createRoot(document.querySelector("#root")!);
5+
6+
root.render(<DevTools />);

examples/with-react/src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rsbuild/core/types" />
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+
<title>Popup</title>
6+
</head>
7+
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
<script type="module" src="./index.tsx"></script>
12+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createRoot } from "react-dom/client";
2+
import { Popup } from "./popup";
3+
4+
const root = createRoot(document.querySelector("#root")!);
5+
6+
root.render(<Popup />);

0 commit comments

Comments
 (0)