create-lve 0.6.12 → 0.6.13
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/package.json +1 -1
- package/template-react/src/app/providers.tsx +5 -2
- package/template-react/src/app/types.ts +15 -0
- package/template-react/src/features/home/routes.ts +2 -11
- package/template-react/src/features/not-found/routes.ts +2 -10
- package/template-react/src/features/settings/routes.ts +6 -28
- package/template-react/vite.config.ts +10 -7
- package/template-vue/vite.config.ts +8 -7
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider as JotaiProvider } from 'jotai'
|
|
1
|
+
import { createStore, Provider as JotaiProvider } from 'jotai'
|
|
2
2
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
3
3
|
import { Toaster } from 'sonner'
|
|
4
4
|
|
|
@@ -11,9 +11,12 @@ const queryClient = new QueryClient({
|
|
|
11
11
|
},
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
/** Jotai store — 在 React 外创建,生命周期不绑定组件树 */
|
|
15
|
+
export const jotaiStore = createStore()
|
|
16
|
+
|
|
14
17
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
15
18
|
return (
|
|
16
|
-
<JotaiProvider>
|
|
19
|
+
<JotaiProvider store={jotaiStore}>
|
|
17
20
|
<QueryClientProvider client={queryClient}>
|
|
18
21
|
{children}
|
|
19
22
|
<Toaster position="bottom-right" richColors visibleToasts={1} />
|
|
@@ -10,6 +10,21 @@ export interface FeatureRoute extends Omit<RouteObject, 'children' | 'handle'> {
|
|
|
10
10
|
handle?: Record<string, unknown>
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** 快捷创建 lazy 路由,减少重复模板代码 */
|
|
14
|
+
export function lazyRoute(
|
|
15
|
+
path: string,
|
|
16
|
+
factory: () => Promise<{ default: ComponentType }>,
|
|
17
|
+
index?: boolean,
|
|
18
|
+
): FeatureRoute {
|
|
19
|
+
return {
|
|
20
|
+
...(index ? { index: true } : { path }),
|
|
21
|
+
lazy: async () => {
|
|
22
|
+
const { default: Component } = await factory()
|
|
23
|
+
return { Component }
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
/** FeatureRoute → RouteObject 递归转换,去掉 hostRootLayout */
|
|
14
29
|
export function toRouteObjects(
|
|
15
30
|
routes: FeatureRoute[],
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { lazyRoute } from '@/app/types'
|
|
2
2
|
|
|
3
|
-
const routes
|
|
4
|
-
{
|
|
5
|
-
path: '/',
|
|
6
|
-
index: true,
|
|
7
|
-
lazy: async () => {
|
|
8
|
-
const { default: Component } = await import('./pages')
|
|
9
|
-
return { Component }
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
]
|
|
3
|
+
const routes = [lazyRoute('/', () => import('./pages'), true)]
|
|
13
4
|
|
|
14
5
|
export default routes
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { lazyRoute } from '@/app/types'
|
|
2
2
|
|
|
3
|
-
const routes
|
|
4
|
-
{
|
|
5
|
-
path: '*',
|
|
6
|
-
lazy: async () => {
|
|
7
|
-
const { default: Component } = await import('./pages')
|
|
8
|
-
return { Component }
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
]
|
|
3
|
+
const routes = [lazyRoute('*', () => import('./pages'))]
|
|
12
4
|
|
|
13
5
|
export default routes
|
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { lazyRoute } from '@/app/types'
|
|
2
2
|
|
|
3
|
-
const routes
|
|
3
|
+
const routes = [
|
|
4
4
|
{
|
|
5
|
-
|
|
5
|
+
...lazyRoute('/settings', () => import('./pages/settings')),
|
|
6
6
|
hostRootLayout: false,
|
|
7
|
-
lazy: async () => {
|
|
8
|
-
const { default: Component } = await import('./pages/settings')
|
|
9
|
-
return { Component }
|
|
10
|
-
},
|
|
11
7
|
children: [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { default: Component } = await import('./pages/overview')
|
|
16
|
-
return { Component }
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
path: 'profile',
|
|
21
|
-
lazy: async () => {
|
|
22
|
-
const { default: Component } = await import('./pages/profile')
|
|
23
|
-
return { Component }
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
path: 'account',
|
|
28
|
-
lazy: async () => {
|
|
29
|
-
const { default: Component } = await import('./pages/account')
|
|
30
|
-
return { Component }
|
|
31
|
-
},
|
|
32
|
-
},
|
|
8
|
+
lazyRoute('/', () => import('./pages/overview'), true),
|
|
9
|
+
lazyRoute('profile', () => import('./pages/profile')),
|
|
10
|
+
lazyRoute('account', () => import('./pages/account')),
|
|
33
11
|
],
|
|
34
12
|
},
|
|
35
13
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineConfig, loadEnv, lazyPlugins } from 'vite-plus'
|
|
1
|
+
import { defineConfig, loadEnv, lazyPlugins, type Plugin } from 'vite-plus'
|
|
2
2
|
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
|
3
3
|
|
|
4
4
|
const mode = process.env.NODE_ENV || 'development'
|
|
@@ -24,7 +24,7 @@ export default defineConfig({
|
|
|
24
24
|
presets: [reactCompilerPreset()],
|
|
25
25
|
}),
|
|
26
26
|
]
|
|
27
|
-
}) as
|
|
27
|
+
}) as Plugin[],
|
|
28
28
|
],
|
|
29
29
|
resolve: {
|
|
30
30
|
tsconfigPaths: true,
|
|
@@ -34,11 +34,14 @@ export default defineConfig({
|
|
|
34
34
|
output: {
|
|
35
35
|
codeSplitting: {
|
|
36
36
|
groups: [
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
37
|
+
{ name: 'vendor-react-dom', test: /node_modules.*react-dom/ },
|
|
38
|
+
{ name: 'vendor-react', test: /node_modules.*react(?!-dom|-router)/ },
|
|
39
|
+
{ name: 'vendor-router', test: /node_modules.*react-router/ },
|
|
40
|
+
{ name: 'vendor-query', test: /node_modules.*@tanstack/ },
|
|
41
|
+
{ name: 'vendor-radix', test: /node_modules.*radix-ui/ },
|
|
42
|
+
{ name: 'vendor-state', test: /node_modules.*zustand/ },
|
|
43
|
+
{ name: 'vendor-atom', test: /node_modules.*jotai/ },
|
|
44
|
+
{ name: 'vendor', test: /node_modules/, minSize: 100 * 1024 },
|
|
42
45
|
],
|
|
43
46
|
},
|
|
44
47
|
},
|
|
@@ -21,13 +21,14 @@ export default defineConfig({
|
|
|
21
21
|
build: {
|
|
22
22
|
rolldownOptions: {
|
|
23
23
|
output: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
codeSplitting: {
|
|
25
|
+
groups: [
|
|
26
|
+
{ name: 'vendor-vue', test: /node_modules.*vue(?!-router)/ },
|
|
27
|
+
{ name: 'vendor-router', test: /node_modules.*vue-router/ },
|
|
28
|
+
{ name: 'vendor-pinia', test: /node_modules.*pinia/ },
|
|
29
|
+
{ name: 'vendor-vueuse', test: /node_modules.*@vueuse/ },
|
|
30
|
+
{ name: 'vendor', test: /node_modules/, minSize: 100 * 1024 },
|
|
31
|
+
],
|
|
31
32
|
},
|
|
32
33
|
},
|
|
33
34
|
},
|