@moluoxixi/create-app 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +129 -0
- package/dist/commands/create.d.ts +10 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +89 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/generators/index.d.ts +7 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +7 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/project.d.ts +11 -0
- package/dist/generators/project.d.ts.map +1 -0
- package/dist/generators/project.js +26 -0
- package/dist/generators/project.js.map +1 -0
- package/dist/generators/react.d.ts +10 -0
- package/dist/generators/react.d.ts.map +1 -0
- package/dist/generators/react.js +39 -0
- package/dist/generators/react.js.map +1 -0
- package/dist/generators/vue.d.ts +10 -0
- package/dist/generators/vue.d.ts.map +1 -0
- package/dist/generators/vue.js +40 -0
- package/dist/generators/vue.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/test.d.ts +6 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +364 -0
- package/dist/test.js.map +1 -0
- package/dist/types/ejs.d.ts +11 -0
- package/dist/types/ejs.d.ts.map +1 -0
- package/dist/types/ejs.js +5 -0
- package/dist/types/ejs.js.map +1 -0
- package/dist/types/features.d.ts +26 -0
- package/dist/types/features.d.ts.map +1 -0
- package/dist/types/features.js +41 -0
- package/dist/types/features.js.map +1 -0
- package/dist/types/index.d.ts +59 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/viteConfig.d.ts +17 -0
- package/dist/types/viteConfig.d.ts.map +1 -0
- package/dist/types/viteConfig.js +6 -0
- package/dist/types/viteConfig.js.map +1 -0
- package/dist/utils/deepMerge.d.ts +8 -0
- package/dist/utils/deepMerge.d.ts.map +1 -0
- package/dist/utils/deepMerge.js +33 -0
- package/dist/utils/deepMerge.js.map +1 -0
- package/dist/utils/ejs.d.ts +19 -0
- package/dist/utils/ejs.d.ts.map +1 -0
- package/dist/utils/ejs.js +30 -0
- package/dist/utils/ejs.js.map +1 -0
- package/dist/utils/file.d.ts +70 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +119 -0
- package/dist/utils/file.js.map +1 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/install.d.ts +17 -0
- package/dist/utils/install.d.ts.map +1 -0
- package/dist/utils/install.js +37 -0
- package/dist/utils/install.js.map +1 -0
- package/dist/utils/prompts.d.ts +16 -0
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/prompts.js +180 -0
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/renderFeatures.d.ts +18 -0
- package/dist/utils/renderFeatures.d.ts.map +1 -0
- package/dist/utils/renderFeatures.js +72 -0
- package/dist/utils/renderFeatures.js.map +1 -0
- package/dist/utils/renderTemplate.d.ts +6 -0
- package/dist/utils/renderTemplate.d.ts.map +1 -0
- package/dist/utils/renderTemplate.js +102 -0
- package/dist/utils/renderTemplate.js.map +1 -0
- package/dist/utils/sortDependencies.d.ts +6 -0
- package/dist/utils/sortDependencies.d.ts.map +1 -0
- package/dist/utils/sortDependencies.js +22 -0
- package/dist/utils/sortDependencies.js.map +1 -0
- package/dist/utils/viteConfigRender.d.ts +19 -0
- package/dist/utils/viteConfigRender.d.ts.map +1 -0
- package/dist/utils/viteConfigRender.js +180 -0
- package/dist/utils/viteConfigRender.js.map +1 -0
- package/package.json +93 -0
- package/templates/common/base/.env +7 -0
- package/templates/common/base/.env.development +5 -0
- package/templates/common/base/.env.production +5 -0
- package/templates/common/base/package.json +56 -0
- package/templates/common/base/pnpm-workspace.yaml +37 -0
- package/templates/common/base/scripts/build.mts +31 -0
- package/templates/common/base/src/apis/index.ts +8 -0
- package/templates/common/base/src/apis/request.ts +43 -0
- package/templates/common/base/src/apis/services/example.ts +40 -0
- package/templates/common/base/src/apis/services/user.ts +23 -0
- package/templates/common/base/src/apis/types/common.ts +28 -0
- package/templates/common/base/src/apis/types/example.ts +18 -0
- package/templates/common/base/src/apis/types/index.ts +7 -0
- package/templates/common/base/src/apis/types/user.ts +24 -0
- package/templates/common/base/src/assets/fonts/index.css +7 -0
- package/templates/common/base/src/assets/styles/base.scss +72 -0
- package/templates/common/base/src/assets/styles/custom.scss +7 -0
- package/templates/common/base/src/assets/styles/tailwind.scss +6 -0
- package/templates/common/base/src/constants/index.ts +29 -0
- package/templates/common/base/src/locales/lang/en.ts +30 -0
- package/templates/common/base/src/locales/lang/es.ts +30 -0
- package/templates/common/base/src/locales/lang/zh.ts +30 -0
- package/templates/common/base/src/utils/index.ts +83 -0
- package/templates/common/features/husky/.cz-config.cjs +35 -0
- package/templates/common/features/husky/.husky/commit-msg +9 -0
- package/templates/common/features/husky/.husky/install.mjs +6 -0
- package/templates/common/features/husky/.husky/pre-commit +4 -0
- package/templates/common/features/husky/commitlint.config.ts +32 -0
- package/templates/common/features/husky/package.json +28 -0
- package/templates/common/features/husky/pnpm-workspace.yaml +9 -0
- package/templates/react/base/env.d.ts +19 -0
- package/templates/react/base/index.html +14 -0
- package/templates/react/base/package.json +15 -0
- package/templates/react/base/pnpm-workspace.yaml +9 -0
- package/templates/react/base/src/App.tsx +18 -0
- package/templates/react/base/src/assets/styles/main.scss +8 -0
- package/templates/react/base/src/main.tsx.ejs +39 -0
- package/templates/react/base/src/pages/about/index.tsx +14 -0
- package/templates/react/base/src/pages/home/index.tsx +14 -0
- package/templates/react/base/src/router/index.tsx.ejs +28 -0
- package/templates/react/base/src/stores/user.ts +39 -0
- package/templates/react/base/tsconfig.app.json +17 -0
- package/templates/react/base/tsconfig.base.json +23 -0
- package/templates/react/base/tsconfig.json +12 -0
- package/templates/react/base/tsconfig.node.json +15 -0
- package/templates/react/base/vite.config.ts +52 -0
- package/templates/react/features/ant-design/package.json +7 -0
- package/templates/react/features/ant-design/pnpm-workspace.yaml +5 -0
- package/templates/react/features/eslint/eslint.config.ts +12 -0
- package/templates/react/features/eslint/package.json +7 -0
- package/templates/react/features/eslint/pnpm-workspace.yaml +6 -0
- package/templates/react/features/i18n/package.json +7 -0
- package/templates/react/features/i18n/pnpm-workspace.yaml +5 -0
- package/templates/react/features/i18n/src/locales/index.ts +20 -0
- package/templates/react/features/manualRoutes/src/router/routes.tsx +21 -0
- package/templates/react/features/pageRoutes/package.json +6 -0
- package/templates/react/features/pageRoutes/pnpm-workspace.yaml +4 -0
- package/templates/react/features/pageRoutes/vite.config.data.ts +10 -0
- package/templates/react/features/router/package.json +5 -0
- package/templates/react/features/router/pnpm-workspace.yaml +3 -0
- package/templates/react/features/sentry/package.json +7 -0
- package/templates/react/features/sentry/pnpm-workspace.yaml +5 -0
- package/templates/react/features/sentry/src/utils/sentry.ts +30 -0
- package/templates/react/features/sentry/vite.config.data.ts +23 -0
- package/templates/react/features/zustand/package.json +5 -0
- package/templates/react/features/zustand/pnpm-workspace.yaml +3 -0
- package/templates/react/features/zustand/src/stores/user.ts +19 -0
- package/templates/react/features/zustand/src/types/stores.ts +15 -0
- package/templates/vue/base/env.d.ts +27 -0
- package/templates/vue/base/index.html +14 -0
- package/templates/vue/base/package.json +13 -0
- package/templates/vue/base/pnpm-workspace.yaml +6 -0
- package/templates/vue/base/src/App.vue +13 -0
- package/templates/vue/base/src/assets/styles/element/index.scss +27 -0
- package/templates/vue/base/src/assets/styles/main.scss +9 -0
- package/templates/vue/base/src/components/SubMenu/index.ts +9 -0
- package/templates/vue/base/src/components/SubMenu/src/_types/index.ts +6 -0
- package/templates/vue/base/src/components/SubMenu/src/_types/props.ts +11 -0
- package/templates/vue/base/src/components/SubMenu/src/index.vue +24 -0
- package/templates/vue/base/src/directives/index.ts +36 -0
- package/templates/vue/base/src/layouts/AntDesign.vue +86 -0
- package/templates/vue/base/src/layouts/element.vue +81 -0
- package/templates/vue/base/src/layouts/index.ts +7 -0
- package/templates/vue/base/src/main.ts.ejs +100 -0
- package/templates/vue/base/src/pages/about/index.vue +31 -0
- package/templates/vue/base/src/pages/home/index.vue +31 -0
- package/templates/vue/base/src/router/index.ts.ejs +39 -0
- package/templates/vue/base/src/stores/index.ts +16 -0
- package/templates/vue/base/src/stores/modules/system.ts +52 -0
- package/templates/vue/base/src/stores/modules/user.ts +48 -0
- package/templates/vue/base/tsconfig.app.json +17 -0
- package/templates/vue/base/tsconfig.base.json +23 -0
- package/templates/vue/base/tsconfig.json +12 -0
- package/templates/vue/base/tsconfig.node.json +15 -0
- package/templates/vue/base/vite.config.ts +53 -0
- package/templates/vue/features/ant-design-vue/package.json +7 -0
- package/templates/vue/features/ant-design-vue/pnpm-workspace.yaml +5 -0
- package/templates/vue/features/element-plus/package.json +7 -0
- package/templates/vue/features/element-plus/pnpm-workspace.yaml +5 -0
- package/templates/vue/features/element-plus/vite.config.data.ts +15 -0
- package/templates/vue/features/eslint/eslint.config.ts +12 -0
- package/templates/vue/features/eslint/package.json +7 -0
- package/templates/vue/features/eslint/pnpm-workspace.yaml +6 -0
- package/templates/vue/features/i18n/package.json +5 -0
- package/templates/vue/features/i18n/pnpm-workspace.yaml +3 -0
- package/templates/vue/features/i18n/src/locales/index.ts +16 -0
- package/templates/vue/features/manualRoutes/src/router/layout.vue +10 -0
- package/templates/vue/features/manualRoutes/src/router/routes.ts +27 -0
- package/templates/vue/features/pageRoutes/package.json +5 -0
- package/templates/vue/features/pageRoutes/pnpm-workspace.yaml +4 -0
- package/templates/vue/features/pageRoutes/vite.config.data.ts +9 -0
- package/templates/vue/features/pinia/package.json +6 -0
- package/templates/vue/features/pinia/pnpm-workspace.yaml +4 -0
- package/templates/vue/features/pinia/src/stores/index.ts +8 -0
- package/templates/vue/features/pinia/src/stores/user.ts +36 -0
- package/templates/vue/features/qiankun/package.json +5 -0
- package/templates/vue/features/qiankun/pnpm-workspace.yaml +3 -0
- package/templates/vue/features/qiankun/src/qiankun/index.ts +56 -0
- package/templates/vue/features/router/package.json +5 -0
- package/templates/vue/features/router/pnpm-workspace.yaml +3 -0
- package/templates/vue/features/sentry/package.json +6 -0
- package/templates/vue/features/sentry/pnpm-workspace.yaml +4 -0
- package/templates/vue/features/sentry/src/utils/sentry.ts +33 -0
- package/templates/vue/features/sentry/vite.config.data.ts +23 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用入口文件
|
|
3
|
+
* 初始化 React 应用并挂载到 DOM
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react'
|
|
7
|
+
import ReactDOM from 'react-dom/client'
|
|
8
|
+
import { RouterProvider } from 'react-router-dom'
|
|
9
|
+
<% if (i18n) { -%>
|
|
10
|
+
import '@/locales'
|
|
11
|
+
<% } -%>
|
|
12
|
+
<% if (sentry) { -%>
|
|
13
|
+
import { initSentry } from '@/utils/sentry'
|
|
14
|
+
<% } -%>
|
|
15
|
+
import { createRouter } from '@/router'
|
|
16
|
+
|
|
17
|
+
// 导入样式文件
|
|
18
|
+
<% if (uiLibrary === 'ant-design') { -%>
|
|
19
|
+
import 'antd/dist/reset.css'
|
|
20
|
+
<% } -%>
|
|
21
|
+
import '@/assets/styles/main.scss'
|
|
22
|
+
import '@/assets/fonts/index.css'
|
|
23
|
+
|
|
24
|
+
<% if (sentry) { -%>
|
|
25
|
+
// 初始化 Sentry
|
|
26
|
+
initSentry({
|
|
27
|
+
dsn: import.meta.env.VITE_SENTRY_DSN,
|
|
28
|
+
environment: import.meta.env.MODE,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
<% } -%>
|
|
32
|
+
const router = createRouter()
|
|
33
|
+
|
|
34
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
35
|
+
<React.StrictMode>
|
|
36
|
+
<RouterProvider router={router} />
|
|
37
|
+
</React.StrictMode>,
|
|
38
|
+
)
|
|
39
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由配置
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createBrowserRouter, createHashRouter } from 'react-router-dom'
|
|
6
|
+
<% if (routeMode === 'file-system') { -%>
|
|
7
|
+
import routes from '~react-pages'
|
|
8
|
+
<% } else { -%>
|
|
9
|
+
import { routes } from './routes'
|
|
10
|
+
<% } -%>
|
|
11
|
+
|
|
12
|
+
interface RouterConfig {
|
|
13
|
+
historyMode?: 'hash' | 'history'
|
|
14
|
+
basename?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createRouter(config: RouterConfig = {}) {
|
|
18
|
+
const { historyMode = 'history', basename } = config
|
|
19
|
+
|
|
20
|
+
if (historyMode === 'hash') {
|
|
21
|
+
return createHashRouter(routes, { basename })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return createBrowserRouter(routes, { basename })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { routes }
|
|
28
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户状态管理
|
|
3
|
+
* 基于 Zustand
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { create } from 'zustand'
|
|
7
|
+
import { persist } from 'zustand/middleware'
|
|
8
|
+
|
|
9
|
+
interface UserInfo {
|
|
10
|
+
id: string
|
|
11
|
+
username: string
|
|
12
|
+
email: string
|
|
13
|
+
avatar?: string
|
|
14
|
+
roles: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface UserState {
|
|
18
|
+
userInfo: UserInfo | null
|
|
19
|
+
token: string
|
|
20
|
+
setUserInfo: (info: UserInfo | null) => void
|
|
21
|
+
setToken: (token: string) => void
|
|
22
|
+
clearUser: () => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const useUserStore = create<UserState>()(
|
|
26
|
+
persist(
|
|
27
|
+
set => ({
|
|
28
|
+
userInfo: null,
|
|
29
|
+
token: '',
|
|
30
|
+
setUserInfo: info => set({ userInfo: info }),
|
|
31
|
+
setToken: token => set({ token }),
|
|
32
|
+
clearUser: () => set({ userInfo: null, token: '' }),
|
|
33
|
+
}),
|
|
34
|
+
{
|
|
35
|
+
name: 'user-storage',
|
|
36
|
+
partialize: state => ({ token: state.token }),
|
|
37
|
+
},
|
|
38
|
+
),
|
|
39
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"composite": true,
|
|
5
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@/*": ["./src/*"]
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"env.d.ts",
|
|
13
|
+
"src/**/*",
|
|
14
|
+
"src/**/*.tsx"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"moduleDetection": "force",
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noUncheckedSideEffectImports": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"esModuleInterop": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"composite": true,
|
|
5
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
6
|
+
"types": ["node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"vite.config.*",
|
|
10
|
+
"eslint.config.*",
|
|
11
|
+
"commitlint.config.*",
|
|
12
|
+
"scripts/**/*"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite 配置文件
|
|
3
|
+
* 基于 @moluoxixi/vite-config 的配置
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import process from 'node:process'
|
|
8
|
+
import cssModuleGlobalRootPlugin from '@moluoxixi/css-module-global-root-plugin'
|
|
9
|
+
import { ViteConfig, wrapperEnv } from '@moluoxixi/vite-config'
|
|
10
|
+
import { loadEnv } from 'vite'
|
|
11
|
+
|
|
12
|
+
export default ViteConfig(
|
|
13
|
+
({ mode }) => {
|
|
14
|
+
const env = loadEnv(mode!, process.cwd())
|
|
15
|
+
const viteEnv = wrapperEnv(env)
|
|
16
|
+
const rootPath = path.resolve()
|
|
17
|
+
const appCode = viteEnv.VITE_APP_CODE
|
|
18
|
+
const appTitle = viteEnv.VITE_APP_TITLE
|
|
19
|
+
const port = viteEnv.VITE_APP_PORT
|
|
20
|
+
return {
|
|
21
|
+
rootPath,
|
|
22
|
+
appTitle,
|
|
23
|
+
appCode,
|
|
24
|
+
port,
|
|
25
|
+
react: true,
|
|
26
|
+
viteConfig: {
|
|
27
|
+
plugins: [],
|
|
28
|
+
server: {
|
|
29
|
+
proxy: {
|
|
30
|
+
'/api': {
|
|
31
|
+
changeOrigin: true,
|
|
32
|
+
target: 'http://localhost:3000',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
css: {
|
|
37
|
+
postcss: {
|
|
38
|
+
plugins: [
|
|
39
|
+
cssModuleGlobalRootPlugin,
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
preprocessorOptions: {
|
|
43
|
+
scss: {
|
|
44
|
+
silenceDeprecations: ['legacy-js-api'],
|
|
45
|
+
api: 'modern-compiler',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import i18n from 'i18next'
|
|
2
|
+
import { initReactI18next } from 'react-i18next'
|
|
3
|
+
|
|
4
|
+
import en from './lang/en'
|
|
5
|
+
import zh from './lang/zh'
|
|
6
|
+
|
|
7
|
+
i18n.use(initReactI18next).init({
|
|
8
|
+
resources: {
|
|
9
|
+
zh: { translation: zh },
|
|
10
|
+
en: { translation: en },
|
|
11
|
+
},
|
|
12
|
+
lng: localStorage.getItem('locale') || 'zh',
|
|
13
|
+
fallbackLng: 'zh',
|
|
14
|
+
interpolation: {
|
|
15
|
+
escapeValue: false,
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export default i18n
|
|
20
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RouteObject } from 'react-router-dom'
|
|
2
|
+
import { lazy, Suspense } from 'react'
|
|
3
|
+
|
|
4
|
+
const Home = lazy(() => import('@/pages/home'))
|
|
5
|
+
const About = lazy(() => import('@/pages/about'))
|
|
6
|
+
|
|
7
|
+
function LazyLoad({ children }: { children: React.ReactNode }) {
|
|
8
|
+
return <Suspense fallback={<div>Loading...</div>}>{children}</Suspense>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const routes: RouteObject[] = [
|
|
12
|
+
{
|
|
13
|
+
path: '/',
|
|
14
|
+
element: <LazyLoad><Home /></LazyLoad>,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
path: '/about',
|
|
18
|
+
element: <LazyLoad><About /></LazyLoad>,
|
|
19
|
+
},
|
|
20
|
+
]
|
|
21
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/react'
|
|
2
|
+
|
|
3
|
+
interface SentryConfig {
|
|
4
|
+
dsn: string
|
|
5
|
+
environment?: string
|
|
6
|
+
release?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function initSentry(config: SentryConfig): void {
|
|
10
|
+
const { dsn, environment = 'production', release } = config
|
|
11
|
+
|
|
12
|
+
if (!dsn) {
|
|
13
|
+
console.warn('[Sentry] DSN is not configured, skipping initialization')
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Sentry.init({
|
|
18
|
+
dsn,
|
|
19
|
+
environment,
|
|
20
|
+
release,
|
|
21
|
+
integrations: [
|
|
22
|
+
Sentry.browserTracingIntegration(),
|
|
23
|
+
Sentry.replayIntegration(),
|
|
24
|
+
],
|
|
25
|
+
tracesSampleRate: 1.0,
|
|
26
|
+
replaysSessionSampleRate: 0.1,
|
|
27
|
+
replaysOnErrorSampleRate: 1.0,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ViteConfigData } from '../../../../src/types/viteConfig'
|
|
2
|
+
|
|
3
|
+
const data: ViteConfigData = {
|
|
4
|
+
imports: [
|
|
5
|
+
'import { sentryVitePlugin } from \'@sentry/vite-plugin\'',
|
|
6
|
+
],
|
|
7
|
+
plugins: [
|
|
8
|
+
`viteEnv.VITE_SENTRY && mode === 'production' && sentryVitePlugin({
|
|
9
|
+
authToken: process.env.SENTRY_AUTH_TOKEN,
|
|
10
|
+
org: 'f1f562b9b82f',
|
|
11
|
+
project: 'javascript-react',
|
|
12
|
+
sourcemaps: {
|
|
13
|
+
assets: './dist/**',
|
|
14
|
+
ignore: ['node_modules'],
|
|
15
|
+
},
|
|
16
|
+
release: {
|
|
17
|
+
name: viteEnv.VITE_APP_VERSION || 'unknown',
|
|
18
|
+
},
|
|
19
|
+
})`,
|
|
20
|
+
],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default data
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UserStateType } from '@/types/stores'
|
|
2
|
+
|
|
3
|
+
import { create } from 'zustand'
|
|
4
|
+
import { persist } from 'zustand/middleware'
|
|
5
|
+
|
|
6
|
+
export const useUserStore = create<UserStateType>()(
|
|
7
|
+
persist(
|
|
8
|
+
set => ({
|
|
9
|
+
token: '',
|
|
10
|
+
userInfo: null,
|
|
11
|
+
setToken: (token: string) => set({ token }),
|
|
12
|
+
setUserInfo: (userInfo) => set({ userInfo }),
|
|
13
|
+
logout: () => set({ token: '', userInfo: null }),
|
|
14
|
+
}),
|
|
15
|
+
{
|
|
16
|
+
name: 'user-storage',
|
|
17
|
+
},
|
|
18
|
+
),
|
|
19
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store 类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { UserInfoType } from '@/apis/types/user'
|
|
6
|
+
|
|
7
|
+
/** 用户 Store 状态类型 */
|
|
8
|
+
export interface UserStateType {
|
|
9
|
+
token: string
|
|
10
|
+
userInfo: UserInfoType | null
|
|
11
|
+
setToken: (token: string) => void
|
|
12
|
+
setUserInfo: (info: UserInfoType) => void
|
|
13
|
+
logout: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 环境变量类型声明
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/// <reference types="vite/client" />
|
|
6
|
+
|
|
7
|
+
interface ImportMetaEnv {
|
|
8
|
+
readonly VITE_APP_CODE: string;
|
|
9
|
+
readonly VITE_APP_TITLE: string;
|
|
10
|
+
readonly VITE_APP_PORT: number;
|
|
11
|
+
readonly VITE_APP_VERSION: string;
|
|
12
|
+
readonly VITE_APP_ENV: string;
|
|
13
|
+
readonly VITE_API_BASE_URL: string;
|
|
14
|
+
readonly VITE_SENTRY: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface ImportMeta {
|
|
18
|
+
readonly env: ImportMetaEnv;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module '*.vue' {
|
|
22
|
+
import type { DefineComponent } from 'vue';
|
|
23
|
+
|
|
24
|
+
const component: DefineComponent<object, object, unknown>;
|
|
25
|
+
export default component;
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>%VITE_APP_TITLE%</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
14
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element Plus 样式定制
|
|
3
|
+
* 自定义 Element Plus 主题
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
|
|
7
|
+
$colors: (
|
|
8
|
+
'primary': (
|
|
9
|
+
'base': #409eff,
|
|
10
|
+
),
|
|
11
|
+
'success': (
|
|
12
|
+
'base': #67c23a,
|
|
13
|
+
),
|
|
14
|
+
'warning': (
|
|
15
|
+
'base': #e6a23c,
|
|
16
|
+
),
|
|
17
|
+
'danger': (
|
|
18
|
+
'base': #f56c6c,
|
|
19
|
+
),
|
|
20
|
+
'info': (
|
|
21
|
+
'base': #909399,
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
@use 'element-plus/theme-chalk/src/index.scss' as *;
|
|
27
|
+
|