create-packer 1.38.2 → 1.39.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.
Files changed (125) hide show
  1. package/package.json +4 -5
  2. package/template/docusaurus/package.json +1 -1
  3. package/template/{web-app/react-vite/.eslintignore → lib/workspace/.stylelintignore} +2 -0
  4. package/template/lib/workspace/.stylelintrc +4 -9
  5. package/template/lib/workspace/eslint.config.mjs +116 -0
  6. package/template/lib/workspace/package.json +81 -73
  7. package/template/lib/workspace/packages/react/package.json +41 -41
  8. package/template/lib/workspace/packages/react/tsconfig.json +3 -8
  9. package/template/lib/workspace/packages/react/tsconfig.lint.json +21 -0
  10. package/template/lib/workspace/packages/ts/package.json +29 -29
  11. package/template/lib/workspace/packages/ts/tsconfig.json +9 -6
  12. package/template/lib/workspace/packages/ts/tsconfig.lint.json +21 -0
  13. package/template/nest/package.json +82 -84
  14. package/template/web-app/react-rsbuild/domain/app/components/app-context.tsx +17 -17
  15. package/template/web-app/react-rsbuild/domain/router/components/index.ts +2 -0
  16. package/template/web-app/react-rsbuild/domain/router/components/route-layout.tsx +19 -0
  17. package/template/web-app/react-rsbuild/domain/router/components/sub-route-outlet.tsx +22 -0
  18. package/template/web-app/react-rsbuild/domain/router/index.ts +4 -3
  19. package/template/web-app/react-rsbuild/eslint.config.js +104 -0
  20. package/template/web-app/react-rsbuild/package.json +78 -79
  21. package/template/web-app/react-rsbuild/pages/home/index.ts +1 -1
  22. package/template/web-app/react-rsbuild/pages/home/{home.styled.ts → view.styled.ts} +7 -7
  23. package/template/web-app/react-rsbuild/pages/home/{home.tsx → view.tsx} +10 -10
  24. package/template/web-app/{react-vite/shared/tools → react-rsbuild/shared/components}/componentInstance.tsx +80 -80
  25. package/template/web-app/react-rsbuild/shared/components/index.ts +1 -0
  26. package/template/web-app/react-rsbuild/shared/service/home.ts +8 -8
  27. package/template/web-app/react-rsbuild/shared/theme/theme.styled.ts +56 -56
  28. package/template/web-app/react-rsbuild/shared/tools/index.ts +0 -1
  29. package/template/web-app/react-vite/domain/router/components/index.ts +2 -0
  30. package/template/web-app/react-vite/domain/router/components/route-layout.tsx +19 -0
  31. package/template/web-app/react-vite/domain/router/components/sub-route-outlet.tsx +22 -0
  32. package/template/web-app/react-vite/domain/router/index.ts +4 -3
  33. package/template/web-app/react-vite/eslint.config.js +104 -0
  34. package/template/web-app/react-vite/package.json +79 -79
  35. package/template/web-app/react-vite/pages/home/index.ts +1 -1
  36. package/template/web-app/react-vite/pages/home/{home.mock.ts → view.mock.ts} +19 -19
  37. package/template/web-app/{react-webpack/pages/home/home.styled.ts → react-vite/pages/home/view.styled.ts} +7 -7
  38. package/template/web-app/react-vite/pages/home/{home.tsx → view.tsx} +10 -10
  39. package/template/web-app/{react-rsbuild/shared/tools → react-vite/shared/components}/componentInstance.tsx +80 -80
  40. package/template/web-app/react-vite/shared/components/index.ts +1 -0
  41. package/template/web-app/react-vite/shared/service/home.ts +10 -10
  42. package/template/web-app/react-vite/shared/theme/theme.styled.ts +55 -56
  43. package/template/web-app/react-vite/shared/tools/index.ts +0 -1
  44. package/template/web-app/react-vite/vite.config.ts +80 -76
  45. package/template/web-app/react-webpack/domain/router/components/index.ts +2 -0
  46. package/template/web-app/react-webpack/domain/router/components/route-layout.tsx +19 -0
  47. package/template/web-app/react-webpack/domain/router/components/sub-route-outlet.tsx +22 -0
  48. package/template/web-app/react-webpack/domain/router/index.ts +4 -3
  49. package/template/web-app/react-webpack/eslint.config.js +104 -0
  50. package/template/web-app/react-webpack/package.json +84 -87
  51. package/template/web-app/react-webpack/pages/home/index.ts +1 -1
  52. package/template/web-app/{react-vite/pages/home/home.styled.ts → react-webpack/pages/home/view.styled.ts} +7 -7
  53. package/template/web-app/react-webpack/pages/home/{home.tsx → view.tsx} +10 -10
  54. package/template/web-app/react-webpack/shared/{tools → components}/componentInstance.tsx +78 -78
  55. package/template/web-app/react-webpack/shared/components/index.ts +1 -0
  56. package/template/web-app/react-webpack/shared/theme/theme.styled.ts +56 -56
  57. package/template/web-app/react-webpack/shared/tools/index.ts +0 -1
  58. package/template/web-app/solid/package.json +53 -51
  59. package/template/web-app/solid/src/pages/home/index.ts +1 -1
  60. package/template/web-app/solid/src/pages/home/{home.container.tsx → view.tsx} +5 -5
  61. package/template/web-app/solid/src/pages/notFound/index.ts +1 -1
  62. package/template/web-app/solid/src/pages/notFound/{notFound.container.tsx → view.tsx} +3 -3
  63. package/template/web-app/svelte/.prettierrc +21 -14
  64. package/template/web-app/svelte/.svelte-kit/ambient.d.ts +181 -177
  65. package/template/web-app/svelte/.svelte-kit/generated/client/app.js +28 -23
  66. package/template/web-app/svelte/.svelte-kit/generated/client/matchers.js +1 -1
  67. package/template/web-app/svelte/.svelte-kit/generated/client/nodes/0.js +1 -1
  68. package/template/web-app/svelte/.svelte-kit/generated/client/nodes/1.js +1 -1
  69. package/template/web-app/svelte/.svelte-kit/generated/client/nodes/2.js +1 -1
  70. package/template/web-app/svelte/.svelte-kit/generated/root.js +3 -0
  71. package/template/web-app/svelte/.svelte-kit/generated/root.svelte +66 -62
  72. package/template/web-app/svelte/.svelte-kit/generated/server/internal.js +49 -61
  73. package/template/web-app/svelte/.svelte-kit/non-ambient.d.ts +25 -23
  74. package/template/web-app/svelte/.svelte-kit/tsconfig.json +49 -32
  75. package/template/web-app/svelte/.svelte-kit/types/route_meta_data.json +3 -3
  76. package/template/web-app/svelte/.svelte-kit/types/src/routes/$types.d.ts +22 -35
  77. package/template/web-app/svelte/eslint.config.js +95 -0
  78. package/template/web-app/svelte/package.json +55 -55
  79. package/template/web-app/svelte/src/app.d.ts +13 -12
  80. package/template/web-app/svelte/src/app.html +2 -2
  81. package/template/web-app/svelte/src/lib/index.ts +1 -0
  82. package/template/web-app/svelte/src/routes/+page.svelte +2 -2
  83. package/template/web-app/svelte/vite.config.ts +59 -55
  84. package/template/web-app/vue/eslint.config.js +109 -0
  85. package/template/web-app/vue/package.json +70 -70
  86. package/template/web-app/vue/pages/home/index.ts +1 -1
  87. package/template/web-app/vue/pages/home/{home.mock.ts → view.mock.ts} +19 -19
  88. package/template/web-app/vue/pages/home/{home.vue → view.vue} +16 -16
  89. package/template/web-app/vue/vite.config.ts +69 -65
  90. package/template/web-extension/.wxt/eslint-auto-imports.mjs +28 -0
  91. package/template/web-extension/.wxt/tsconfig.json +28 -25
  92. package/template/web-extension/.wxt/types/globals.d.ts +15 -15
  93. package/template/web-extension/.wxt/types/i18n.d.ts +81 -87
  94. package/template/web-extension/.wxt/types/imports.d.ts +22 -21
  95. package/template/web-extension/.wxt/types/paths.d.ts +16 -15
  96. package/template/web-extension/.wxt/wxt.d.ts +7 -6
  97. package/template/web-extension/entrypoints/content/domain/app/tools/insertApp.tsx +2 -3
  98. package/template/web-extension/entrypoints/content/index.tsx +10 -12
  99. package/template/web-extension/entrypoints/popup/main.tsx +14 -14
  100. package/template/web-extension/entrypoints/popup/{popup.container.tsx → popup.tsx} +3 -3
  101. package/template/web-extension/eslint.config.js +106 -0
  102. package/template/web-extension/package.json +84 -86
  103. package/template/web-extension/shared/content/constant.ts +1 -0
  104. package/template/web-extension/shared/content/index.ts +2 -1
  105. package/template/web-extension/shared/content/message.ts +25 -15
  106. package/template/web-extension/shared/styles/theme.styled.ts +56 -56
  107. package/template/web-extension/shared/tools/message.ts +70 -80
  108. package/template/web-extension/tsconfig.json +32 -32
  109. package/template/web-extension/vite-env.d.ts +20 -19
  110. package/template/web-extension/wxt.config.ts +43 -50
  111. package/template/lib/workspace/.eslintrc +0 -111
  112. package/template/lib/workspace/packages/react/.eslintrc +0 -111
  113. package/template/lib/workspace/packages/react/.stylelintrc +0 -29
  114. package/template/web-app/react-rsbuild/.eslintignore +0 -4
  115. package/template/web-app/react-rsbuild/.eslintrc +0 -111
  116. package/template/web-app/react-vite/.eslintrc +0 -110
  117. package/template/web-app/react-webpack/.eslintignore +0 -4
  118. package/template/web-app/react-webpack/.eslintrc +0 -110
  119. package/template/web-app/svelte/.eslintignore +0 -13
  120. package/template/web-app/svelte/.eslintrc +0 -76
  121. package/template/web-app/vue/.eslintignore +0 -4
  122. package/template/web-app/vue/.eslintrc +0 -97
  123. package/template/web-extension/.eslintignore +0 -4
  124. package/template/web-extension/.eslintrc +0 -110
  125. /package/template/web-app/solid/src/pages/home/{home.css → view.css} +0 -0
@@ -1,19 +1,19 @@
1
- import { faker } from '@faker-js/faker'
2
- import { defineMock } from '@/mockUtils'
3
- import { API } from '@/shared/service'
4
-
5
- export default defineMock([
6
- {
7
- url: API.HOME_DATA,
8
- body: faker.helpers.multiple(
9
- () => ({
10
- id: faker.string.uuid(),
11
- name: faker.person.fullName(),
12
- age: faker.number.int({ max: 110 })
13
- }),
14
- {
15
- count: 10
16
- }
17
- )
18
- }
19
- ])
1
+ import { faker } from '@faker-js/faker'
2
+ import { defineMock } from '@/mockUtils'
3
+ import { API } from '@/shared/service'
4
+
5
+ export default defineMock([
6
+ {
7
+ url: API.HOME_DATA,
8
+ body: faker.helpers.multiple(
9
+ () => ({
10
+ id: faker.string.uuid(),
11
+ name: faker.person.fullName(),
12
+ age: faker.number.int({ max: 110 })
13
+ }),
14
+ {
15
+ count: 10
16
+ }
17
+ )
18
+ }
19
+ ])
@@ -1,7 +1,7 @@
1
- import styled, { css } from 'styled-components'
2
-
3
- export const StyledRoot = styled.div(({ theme }) => {
4
- return css`
5
- ${theme.tools.flex('center', 'center')};
6
- `
7
- })
1
+ import styled, { css } from 'styled-components'
2
+
3
+ export const StyledRoot = styled.div(({ theme }) => {
4
+ return css`
5
+ ${theme.tools.flex('center', 'center')};
6
+ `
7
+ })
@@ -1,10 +1,10 @@
1
- import { useHomeQuery } from '@/shared/service'
2
- import { StyledRoot } from './home.styled'
3
-
4
- export default function Home() {
5
- const query = useHomeQuery()
6
-
7
- console.log('data', query.data)
8
-
9
- return <StyledRoot>sdfs</StyledRoot>
10
- }
1
+ import { useHomeQuery } from '@/shared/service'
2
+ import { StyledRoot } from './view.styled'
3
+
4
+ export default function Home() {
5
+ const query = useHomeQuery()
6
+
7
+ console.log('data', query.data)
8
+
9
+ return <StyledRoot>sdfs</StyledRoot>
10
+ }
@@ -1,80 +1,80 @@
1
- import {
2
- forwardRef,
3
- ForwardRefExoticComponent,
4
- FunctionComponent,
5
- PropsWithChildren,
6
- PropsWithoutRef,
7
- RefAttributes,
8
- useImperativeHandle,
9
- useRef,
10
- useState
11
- } from 'react'
12
- import { createRoot } from 'react-dom/client'
13
-
14
- const instanceMap: Record<string, { pending: Promise<any>; instance: any }> = {}
15
-
16
- export interface refsType<P> {
17
- $setProps: (newProps: P) => void
18
- $updateProps: (newProps: Partial<P>) => void
19
- }
20
-
21
- export function create(Context?: FunctionComponent<PropsWithChildren<any>>) {
22
- return async function <P extends Record<string, any>, Refs extends Record<string, any>>(
23
- key: string,
24
- Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
25
- props?: P
26
- ) {
27
- let current = instanceMap[key]
28
- if (!current) {
29
- const div = document.createElement('div')
30
- document.body.appendChild(div)
31
- const ApiComponent = forwardRef<Refs & refsType<P>>((__, refs) => {
32
- const ref = useRef<Refs>(null)
33
- const [state, setState] = useState<Partial<P>>(props || {})
34
-
35
- useImperativeHandle(refs, () => {
36
- return {
37
- $setProps: newProps => {
38
- setState(() => newProps)
39
- },
40
- $updateProps: newProps => {
41
- if (newProps) {
42
- setState(state => ({ ...state, ...newProps }))
43
- }
44
- },
45
- ...ref.current
46
- } as Refs & refsType<P>
47
- })
48
- if (Context) {
49
- return (
50
- <Context>
51
- <Component ref={ref} {...(state as any)} />
52
- </Context>
53
- )
54
- }
55
- return <Component ref={ref} {...(state as any)} />
56
- })
57
- current = instanceMap[key] = {
58
- instance: void 0,
59
- pending: new Promise<void>(resolve => {
60
- createRoot(div).render(
61
- (
62
- <ApiComponent
63
- ref={instance => {
64
- current.instance = instanceMap[key].instance = instance!
65
- resolve()
66
- }}
67
- />
68
- ) as never
69
- )
70
- })
71
- }
72
- }
73
- await current.pending
74
- props && current.instance.$setProps(props)
75
- // Delay return to avoid sync issue
76
- // ------------------------------------------------------------------------
77
- await new Promise(resolve => setTimeout(resolve))
78
- return current.instance as Refs & refsType<P>
79
- }
80
- }
1
+ import {
2
+ forwardRef,
3
+ ForwardRefExoticComponent,
4
+ FunctionComponent,
5
+ PropsWithChildren,
6
+ PropsWithoutRef,
7
+ RefAttributes,
8
+ useImperativeHandle,
9
+ useRef,
10
+ useState
11
+ } from 'react'
12
+ import { createRoot } from 'react-dom/client'
13
+
14
+ const instanceMap: Record<string, { pending: Promise<any>; instance: any }> = {}
15
+
16
+ export interface refsType<P> {
17
+ $setProps: (newProps: P) => void
18
+ $updateProps: (newProps: Partial<P>) => void
19
+ }
20
+
21
+ export function create(Context?: FunctionComponent<PropsWithChildren<any>>) {
22
+ return async function <P extends Record<string, any>, Refs extends Record<string, any>>(
23
+ key: string,
24
+ Component: ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Refs>>,
25
+ props?: P
26
+ ) {
27
+ let current = instanceMap[key]
28
+ if (!current) {
29
+ const div = document.createElement('div')
30
+ document.body.appendChild(div)
31
+ const ApiComponent = forwardRef<Refs & refsType<P>>((__, refs) => {
32
+ const ref = useRef<Refs>(null)
33
+ const [state, setState] = useState<Partial<P>>(props || {})
34
+
35
+ useImperativeHandle(refs, () => {
36
+ return {
37
+ $setProps: newProps => {
38
+ setState(() => newProps)
39
+ },
40
+ $updateProps: newProps => {
41
+ if (newProps) {
42
+ setState(state => ({ ...state, ...newProps }))
43
+ }
44
+ },
45
+ ...ref.current
46
+ } as Refs & refsType<P>
47
+ })
48
+ if (Context) {
49
+ return (
50
+ <Context>
51
+ <Component ref={ref} {...(state as any)} />
52
+ </Context>
53
+ )
54
+ }
55
+ return <Component ref={ref} {...(state as any)} />
56
+ })
57
+ current = instanceMap[key] = {
58
+ instance: void 0,
59
+ pending: new Promise<void>(resolve => {
60
+ createRoot(div).render(
61
+ (
62
+ <ApiComponent
63
+ ref={instance => {
64
+ current.instance = instanceMap[key].instance = instance!
65
+ resolve()
66
+ }}
67
+ />
68
+ ) as never
69
+ )
70
+ })
71
+ }
72
+ }
73
+ await current.pending
74
+ current.instance.$setProps(props)
75
+ // Delay return to avoid sync issue
76
+ // ------------------------------------------------------------------------
77
+ await new Promise(resolve => setTimeout(resolve))
78
+ return current.instance as Refs & refsType<P>
79
+ }
80
+ }
@@ -0,0 +1 @@
1
+ export * as componentInstance from './componentInstance'
@@ -1,10 +1,10 @@
1
- import { useQuery } from '@tanstack/react-query'
2
- import { request } from './request'
3
- import { HOME_DATA } from './api'
4
-
5
- export function useHomeQuery() {
6
- return useQuery({
7
- queryKey: ['home_data'],
8
- queryFn: () => request.post(HOME_DATA)
9
- })
10
- }
1
+ import { useQuery } from '@tanstack/react-query'
2
+ import { request } from './request'
3
+ import { HOME_DATA } from './api'
4
+
5
+ export function useHomeQuery() {
6
+ return useQuery({
7
+ queryKey: ['home_data'],
8
+ queryFn: () => request.post(HOME_DATA)
9
+ })
10
+ }
@@ -1,56 +1,55 @@
1
- import { CSSProperties } from 'react'
2
- import { AnyFunc } from '1k-types'
3
- import { isString } from 'lodash-es'
4
-
5
- export const theme = {
6
- tools: {
7
- ellipsis: () => ({
8
- overflow: 'hidden',
9
- textOverflow: 'ellipsis',
10
- whiteSpace: 'nowrap'
11
- }),
12
- lineClamp: (n: number) => ({
13
- '-webkit-line-clamp': `${n}`,
14
- '-webkit-box-orient': 'vertical',
15
- overflow: 'hidden',
16
- display: '-webkit-box'
17
- }),
18
- size: (s: string) => ({ width: s, height: s }),
19
- py: (s: string) => ({ paddingTop: s, paddingBottom: s }),
20
- px: (s: string) => ({ paddingLeft: s, paddingRight: s }),
21
- my: (s: string) => ({ marginTop: s, marginBottom: s }),
22
- mx: (s: string) => ({ marginLeft: s, marginRight: s }),
23
- flex: (
24
- align: CSSProperties['alignItems'],
25
- justify: CSSProperties['justifyContent'],
26
- vertical?: boolean
27
- ) => {
28
- return {
29
- display: 'flex',
30
- alignItems: align,
31
- justifyContent: justify,
32
- flexDirection: vertical ? 'column' : 'row'
33
- } satisfies CSSProperties
34
- },
35
- /** 数字为元素数量,字符串为对应css的值 */
36
- grid: {
37
- grid: (rows: number | string, cols: number | string, gap?: number) => ({
38
- display: 'grid',
39
- gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
40
- gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
41
- gap: gap ? `${gap}px` : void 0
42
- }),
43
- rows: (rows: number | string, gap?: number) => ({
44
- display: 'grid',
45
- gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
46
- rowGap: gap ? `${gap}px` : void 0
47
- }),
48
- cols: (cols: number | string, gap?: number) => ({
49
- display: 'grid',
50
- gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
51
- columnGap: gap ? `${gap}px` : void 0
52
- })
53
- } satisfies Record<string, AnyFunc<CSSProperties>>
54
- }
55
- }
56
- export type themeType = typeof theme
1
+ import { CSSProperties } from 'react'
2
+ import { isString } from 'lodash-es'
3
+
4
+ export const theme = {
5
+ tools: {
6
+ ellipsis: () => ({
7
+ overflow: 'hidden',
8
+ textOverflow: 'ellipsis',
9
+ whiteSpace: 'nowrap'
10
+ }),
11
+ lineClamp: (n: number) => ({
12
+ '-webkit-line-clamp': `${n}`,
13
+ '-webkit-box-orient': 'vertical',
14
+ overflow: 'hidden',
15
+ display: '-webkit-box'
16
+ }),
17
+ size: (s: string) => ({ width: s, height: s }),
18
+ py: (s: string) => ({ paddingTop: s, paddingBottom: s }),
19
+ px: (s: string) => ({ paddingLeft: s, paddingRight: s }),
20
+ my: (s: string) => ({ marginTop: s, marginBottom: s }),
21
+ mx: (s: string) => ({ marginLeft: s, marginRight: s }),
22
+ flex: (
23
+ align: CSSProperties['alignItems'],
24
+ justify: CSSProperties['justifyContent'],
25
+ vertical?: boolean
26
+ ) => {
27
+ return {
28
+ display: 'flex',
29
+ alignItems: align,
30
+ justifyContent: justify,
31
+ flexDirection: vertical ? 'column' : 'row'
32
+ } satisfies CSSProperties
33
+ },
34
+ /** 数字为元素数量,字符串为对应css的值 */
35
+ grid: {
36
+ grid: (rows: number | string, cols: number | string, gap?: number) => ({
37
+ display: 'grid',
38
+ gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
39
+ gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
40
+ gap: gap ? `${gap}px` : void 0
41
+ }),
42
+ rows: (rows: number | string, gap?: number) => ({
43
+ display: 'grid',
44
+ gridTemplateRows: isString(rows) ? rows : `repeat(${rows}, minmax(0, 1fr))`,
45
+ rowGap: gap ? `${gap}px` : void 0
46
+ }),
47
+ cols: (cols: number | string, gap?: number) => ({
48
+ display: 'grid',
49
+ gridTemplateColumns: isString(cols) ? cols : `repeat(${cols}, minmax(0, 1fr))`,
50
+ columnGap: gap ? `${gap}px` : void 0
51
+ })
52
+ } satisfies Record<string, (...args: any) => CSSProperties>
53
+ }
54
+ }
55
+ export type themeType = typeof theme
@@ -1 +0,0 @@
1
- export * as componentInstance from './componentInstance'
@@ -1,76 +1,80 @@
1
- import { defineConfig, loadEnv } from 'vite'
2
- import react from '@vitejs/plugin-react'
3
- import svgr from 'vite-plugin-svgr'
4
- import mockDevServer from 'vite-plugin-mock-dev-server'
5
- import stylelint from 'vite-plugin-stylelint'
6
- import eslint from '@rollup/plugin-eslint'
7
- import { visualizer } from 'rollup-plugin-visualizer'
8
- import { includes } from 'lodash-es'
9
- import { createChunks } from './scripts'
10
-
11
- // https://vitejs.dev/config/
12
- export default defineConfig(({ mode }) => {
13
- const env = loadEnv(mode, process.cwd(), '')
14
- const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
15
- const plugins: any[] = [
16
- svgr(),
17
- stylelint({ cache: false, include: ['**/*.{css,scss,sass,less,styl,ts,tsx}'] }),
18
- eslint({ include: ['**/*.{ts,tsx,js,jsx}'] }),
19
- react({
20
- babel: {
21
- plugins: [
22
- [
23
- 'babel-plugin-styled-components',
24
- {
25
- ssr: false,
26
- displayName: false,
27
- fileName: false,
28
- transpileTemplateLiterals: false
29
- }
30
- ]
31
- ]
32
- }
33
- }),
34
- mockDevServer({
35
- include: ['**/*.mock.{ts,js}']
36
- })
37
- ]
38
-
39
- if (mode === 'analyse') {
40
- plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
41
- }
42
-
43
- return {
44
- base: env.VITE_BASE_URL,
45
- plugins,
46
- resolve: {
47
- alias: {
48
- '@': __dirname
49
- }
50
- },
51
- esbuild: {
52
- drop: includes(['production', 'analyse'], mode) ? ['console', 'debugger'] : []
53
- },
54
- build: {
55
- sourcemap: mode === 'analyse',
56
- reportCompressedSize: mode === 'analyse',
57
- rollupOptions: {
58
- output: {
59
- manualChunks: createChunks({
60
- react: ['react', 'react-dom']
61
- })
62
- }
63
- }
64
- },
65
- server: {
66
- host: '0.0.0.0',
67
- proxy: {
68
- [proxyBaseUrl]: {
69
- target: 'http://127.0.0.1',
70
- changeOrigin: true,
71
- rewrite: path => path.replace(proxyBaseUrl, '')
72
- }
73
- }
74
- }
75
- }
76
- })
1
+ import { defineConfig, loadEnv } from 'vite'
2
+ import react from '@vitejs/plugin-react'
3
+ import svgr from 'vite-plugin-svgr'
4
+ import mockDevServer from 'vite-plugin-mock-dev-server'
5
+ import checker from 'vite-plugin-checker'
6
+ import stylelint from 'vite-plugin-stylelint'
7
+ import { visualizer } from 'rollup-plugin-visualizer'
8
+ import { includes } from 'lodash-es'
9
+ import { createChunks } from './scripts'
10
+
11
+ // https://vitejs.dev/config/
12
+ export default defineConfig(({ mode }) => {
13
+ const env = loadEnv(mode, process.cwd(), '')
14
+ const proxyBaseUrl = env.VITE_BASE_URL + env.VITE_API_HOST
15
+ const plugins: any[] = [
16
+ svgr(),
17
+ stylelint({ cache: false, include: ['**/*.{css,scss,less,ts,tsx}'] }),
18
+ checker({
19
+ enableBuild: false,
20
+ typescript: true,
21
+ eslint: { useFlatConfig: true, lintCommand: 'eslint', dev: { logLevel: ['error'] } }
22
+ }),
23
+ react({
24
+ babel: {
25
+ plugins: [
26
+ [
27
+ 'babel-plugin-styled-components',
28
+ {
29
+ ssr: false,
30
+ displayName: false,
31
+ fileName: false,
32
+ transpileTemplateLiterals: false
33
+ }
34
+ ]
35
+ ]
36
+ }
37
+ }),
38
+ mockDevServer({
39
+ include: ['**/*.mock.{ts,js}']
40
+ })
41
+ ]
42
+
43
+ if (mode === 'analyse') {
44
+ plugins.push(visualizer({ open: true, sourcemap: true, brotliSize: true, gzipSize: true }))
45
+ }
46
+
47
+ return {
48
+ base: env.VITE_BASE_URL,
49
+ plugins,
50
+ resolve: {
51
+ alias: {
52
+ '@': __dirname
53
+ }
54
+ },
55
+ esbuild: {
56
+ drop: includes(['production', 'analyse'], mode) ? ['console', 'debugger'] : []
57
+ },
58
+ build: {
59
+ sourcemap: mode === 'analyse',
60
+ reportCompressedSize: mode === 'analyse',
61
+ rollupOptions: {
62
+ output: {
63
+ manualChunks: createChunks({
64
+ react: ['react', 'react-dom']
65
+ })
66
+ }
67
+ }
68
+ },
69
+ server: {
70
+ host: '0.0.0.0',
71
+ proxy: {
72
+ [proxyBaseUrl]: {
73
+ target: 'http://127.0.0.1',
74
+ changeOrigin: true,
75
+ rewrite: path => path.replace(proxyBaseUrl, '')
76
+ }
77
+ }
78
+ }
79
+ }
80
+ })
@@ -0,0 +1,2 @@
1
+ export * as SubRouteOutlet from './sub-route-outlet'
2
+ export * as RouteLayout from './route-layout'
@@ -0,0 +1,19 @@
1
+ import { FunctionComponent } from 'react'
2
+ import { Outlet } from 'react-router-dom'
3
+ import { last } from 'lodash-es'
4
+ import { routeType, useMatchRoutes } from '@/domain/router'
5
+
6
+ export interface propsType {
7
+ Index: FunctionComponent
8
+ rootId: routeType['id']
9
+ }
10
+
11
+ export const Root: FunctionComponent<propsType> = ({ Index, rootId }) => {
12
+ const matchRoutes = useMatchRoutes()
13
+
14
+ if (last(matchRoutes)?.id === rootId) {
15
+ return <Index />
16
+ }
17
+
18
+ return <Outlet />
19
+ }
@@ -0,0 +1,22 @@
1
+ import { FunctionComponent } from 'react'
2
+ import { Outlet } from 'react-router-dom'
3
+ import { useMount } from 'react-use'
4
+ import { last } from 'lodash-es'
5
+ import { useMatchRoutes, useRouter, routeType } from '@/domain/router'
6
+
7
+ export interface propsType {
8
+ rootId: routeType['id']
9
+ homeId: routeType['id']
10
+ }
11
+ export const Root: FunctionComponent<propsType> = props => {
12
+ const matchRoutes = useMatchRoutes()
13
+ const navigate = useRouter(state => state.navigate)
14
+
15
+ useMount(() => {
16
+ if (last(matchRoutes)?.id === props.rootId) {
17
+ navigate({ id: props.homeId })
18
+ }
19
+ })
20
+
21
+ return <Outlet />
22
+ }
@@ -1,3 +1,4 @@
1
- export { default as routerIds } from './ids'
2
- export * from './router'
3
- export * from './router.types'
1
+ export { default as routerIds } from './ids'
2
+ export * from './router'
3
+ export * from './router.types'
4
+ export * from './components'