feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
5
common/_templates/rsbuild-web/.stylelintrc.js
Normal file
5
common/_templates/rsbuild-web/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
6
common/_templates/rsbuild-web/README.md
Normal file
6
common/_templates/rsbuild-web/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# [🦀️ Rsbuild](https://rsbuild.dev/zh/guide/start/index) & React App
|
||||
Web项目初始化模板,已包含功能:
|
||||
* react + react-router
|
||||
* slardar
|
||||
* less(module), [tailwindcss](https://tailwindcss.com/docs)
|
||||
* vitest
|
||||
0
common/_templates/rsbuild-web/__tests__/.gitkeep
Normal file
0
common/_templates/rsbuild-web/__tests__/.gitkeep
Normal file
17
common/_templates/rsbuild-web/config/rush-project.json
Normal file
17
common/_templates/rsbuild-web/config/rush-project.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-project.schema.json",
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "build",
|
||||
"outputFolderNames": ["output"]
|
||||
},
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
6
common/_templates/rsbuild-web/eslint.config.js
Normal file
6
common/_templates/rsbuild-web/eslint.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
preset: 'web',
|
||||
packageRoot: __dirname,
|
||||
});
|
||||
12
common/_templates/rsbuild-web/index.html
Normal file
12
common/_templates/rsbuild-web/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ packageName }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
12
common/_templates/rsbuild-web/init.config.ts
Normal file
12
common/_templates/rsbuild-web/init.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-4']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
45
common/_templates/rsbuild-web/package.json
Normal file
45
common/_templates/rsbuild-web/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"description": "{{ description }}",
|
||||
"keywords": [],
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "rsbuild build",
|
||||
"dev": "rsbuild dev",
|
||||
"lint": "eslint ./ --cache --quiet",
|
||||
"preview": "rsbuild preview",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "vitest --run --passWithNoTests --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/logger": "workspace:*",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"react-error-boundary": "^4.0.9",
|
||||
"react-router-dom": "^6.11.1",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@rsbuild/core": "^0.2.18",
|
||||
"@rsbuild/plugin-react": "^0.2.18",
|
||||
"@slardar/web": "1.7.0",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"postcss": "^8.4.32",
|
||||
"postcss-loader": "^7.3.3",
|
||||
"tailwindcss": "~3.3.3",
|
||||
|
||||
"vitest": "~3.0.5"
|
||||
}
|
||||
}
|
||||
15
common/_templates/rsbuild-web/rsbuild.config.ts
Normal file
15
common/_templates/rsbuild-web/rsbuild.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import tailwindcss from 'tailwindcss';
|
||||
import { pluginReact } from '@rsbuild/plugin-react';
|
||||
import { defineConfig } from '@rsbuild/core';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [pluginReact()],
|
||||
html: {
|
||||
template: './index.html',
|
||||
},
|
||||
tools: {
|
||||
postcss(config) {
|
||||
config.postcssOptions?.plugins?.push(tailwindcss);
|
||||
},
|
||||
},
|
||||
});
|
||||
24
common/_templates/rsbuild-web/scm_build.sh
Normal file
24
common/_templates/rsbuild-web/scm_build.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
# Switch cwd to the project folder
|
||||
cd $(dirname "$0")
|
||||
|
||||
# Import the utilities functions
|
||||
source ../../scripts/scm_base.sh
|
||||
|
||||
# Clean up the build directory
|
||||
rm -rf dist
|
||||
rm -rf "${ROOT_DIR}"/output
|
||||
|
||||
# Prepare
|
||||
prepare_environment
|
||||
|
||||
# Install the dependencies
|
||||
install_project_deps
|
||||
|
||||
build_project
|
||||
|
||||
mkdir -p ${ROOT_DIR}/output
|
||||
cp -r ./dist/* ${ROOT_DIR}/output/
|
||||
44
common/_templates/rsbuild-web/src/app.tsx
Normal file
44
common/_templates/rsbuild-web/src/app.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import slardar from '@slardar/web';
|
||||
import { reporter } from '@coze-arch/logger';
|
||||
|
||||
import { Page1 } from './pages/page1';
|
||||
import { MainPage } from './pages/main';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
children: [
|
||||
{ path: 'page1', element: <Page1 /> },
|
||||
{ path: '', element: <MainPage /> },
|
||||
{ path: '*', element: <div>404</div> },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export function App() {
|
||||
useEffect(() => {
|
||||
reporter.info({ message: 'Ok fine' });
|
||||
reporter.init(slardar);
|
||||
}, []);
|
||||
|
||||
return <RouterProvider router={router} />;
|
||||
}
|
||||
8
common/_templates/rsbuild-web/src/assets/react.svg
Normal file
8
common/_templates/rsbuild-web/src/assets/react.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg width="100%" height="100%" viewBox="-10.5 -9.45 21 18.9" fill="#357da1" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="0" cy="0" r="2" fill="#357da1"></circle>
|
||||
<g stroke="#357da1" stroke-width="1" fill="none">
|
||||
<ellipse rx="10" ry="4.5"></ellipse>
|
||||
<ellipse rx="10" ry="4.5" transform="rotate(60)"></ellipse>
|
||||
<ellipse rx="10" ry="4.5" transform="rotate(120)"></ellipse>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 404 B |
BIN
common/_templates/rsbuild-web/src/assets/rsbuild.png
Normal file
BIN
common/_templates/rsbuild-web/src/assets/rsbuild.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
1
common/_templates/rsbuild-web/src/global.d.ts
vendored
Normal file
1
common/_templates/rsbuild-web/src/global.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="@rsbuild/core/types" />
|
||||
8
common/_templates/rsbuild-web/src/index.css
Normal file
8
common/_templates/rsbuild-web/src/index.css
Normal file
@@ -0,0 +1,8 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
#root {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
24
common/_templates/rsbuild-web/src/index.tsx
Normal file
24
common/_templates/rsbuild-web/src/index.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createRoot } from 'react-dom/client';
|
||||
|
||||
import { App } from './app';
|
||||
import './index.css';
|
||||
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
|
||||
root.render(<App />);
|
||||
@@ -0,0 +1,4 @@
|
||||
.container {
|
||||
padding-top: 36px;
|
||||
text-align: center;
|
||||
}
|
||||
68
common/_templates/rsbuild-web/src/pages/main/index.tsx
Normal file
68
common/_templates/rsbuild-web/src/pages/main/index.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useState } from 'react';
|
||||
|
||||
import rsbuildLogo from '@/assets/rsbuild.png';
|
||||
import reactLogo from '@/assets/react.svg';
|
||||
|
||||
import s from './index.module.less';
|
||||
|
||||
export function MainPage() {
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
return (
|
||||
<div className={s.container}>
|
||||
<div className="flex items-center justify-center mb-12">
|
||||
<a href="https://www.rsbuild.dev" target="_blank" rel="noreferrer">
|
||||
<img
|
||||
src={rsbuildLogo}
|
||||
className="h-16 p-1.5 mr-12"
|
||||
alt="Rsbuild logo"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://reactjs.org" target="_blank" rel="noreferrer">
|
||||
<img
|
||||
src={reactLogo}
|
||||
className="h-16 p-1.5 animate-[spin_20s_linear_infinite]"
|
||||
alt="React logo"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
<h1 className="text-3xl">Rsbuild + React</h1>
|
||||
<div className="p-4">
|
||||
<button
|
||||
type="button"
|
||||
className="p-2 mb-4 bg-blue-500 rounded-md text-slate-50"
|
||||
onClick={() => setCount(c => c + 1)}
|
||||
>
|
||||
count is {count}
|
||||
</button>
|
||||
<p>
|
||||
Edit <code className="text-sm font-mono">src/App.tsx</code> and save
|
||||
to test HMR
|
||||
</p>
|
||||
</div>
|
||||
<Link to="page1" className="font-light underline text-blue-600">
|
||||
page1
|
||||
</Link>
|
||||
<p className="mt-8 text-gray-400 font-light">
|
||||
Click on the Rsbuild and React logos to learn more
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
19
common/_templates/rsbuild-web/src/pages/page1/index.tsx
Normal file
19
common/_templates/rsbuild-web/src/pages/page1/index.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function Page1() {
|
||||
return <div>page1</div>;
|
||||
}
|
||||
5
common/_templates/rsbuild-web/tailwind.config.ts
Normal file
5
common/_templates/rsbuild-web/tailwind.config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Config } from 'tailwindcss';
|
||||
|
||||
export default {
|
||||
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
||||
} satisfies Config;
|
||||
15
common/_templates/rsbuild-web/tsconfig.build.json
Normal file
15
common/_templates/rsbuild-web/tsconfig.build.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
15
common/_templates/rsbuild-web/tsconfig.json
Normal file
15
common/_templates/rsbuild-web/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
common/_templates/rsbuild-web/tsconfig.misc.json
Normal file
25
common/_templates/rsbuild-web/tsconfig.misc.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": [
|
||||
"__tests__",
|
||||
"vitest.config.ts",
|
||||
"tailwind.config.ts",
|
||||
"rsbuild.config.ts"
|
||||
],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
6
common/_templates/rsbuild-web/vitest.config.ts
Normal file
6
common/_templates/rsbuild-web/vitest.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user