File tree Expand file tree Collapse file tree 14 files changed +454
-283
lines changed
Expand file tree Collapse file tree 14 files changed +454
-283
lines changed Original file line number Diff line number Diff line change 11import React from 'react'
2- import { Layout } from './Layout'
32import './App.css'
43
4+ // import { Layout } from './Layout'
5+
6+ const Layout = React . lazy ( ( ) => import ( './Layout' ) )
7+
58const pages = import . meta. glob < any > ( './pages/**/*.tsx' )
69console . log ( '🚀 ~ file: App.tsx:7 ~ pages:' , pages )
710
811const children = Object . entries ( pages ) . map ( ( [ filepath , component ] ) => {
912 let path = filepath . split ( '/pages' ) [ 1 ]
1013 path = path . split ( '.' ) [ 0 ] . replace ( 'index' , '' )
14+ const entry = `src${ filepath . slice ( 1 ) } `
1115
1216 if ( path . endsWith ( '/' ) ) {
1317 return {
1418 index : true ,
1519 Component : React . lazy ( component ) ,
20+ entry,
1621 }
1722 }
1823 return {
1924 path,
2025 Component : React . lazy ( component ) ,
26+ entry,
2127 }
2228} )
2329
@@ -26,6 +32,7 @@ export const routes = [
2632 path : '/' ,
2733 element : < Layout /> ,
2834 children,
35+ entry : 'src/Layout.tsx' ,
2936 } ,
3037]
3138
Original file line number Diff line number Diff line change 11import { Suspense } from 'react'
22import { Outlet } from 'react-router-dom'
3+ import './layout.css'
34
4- export function Layout ( ) {
5+ export default function Layout ( ) {
56 return (
67 < >
78 { /* <Head>
@@ -11,7 +12,7 @@ export function Layout() {
1112 <title>head test</title>
1213 </Head> */ }
1314 < main >
14- < h1 > Layout</ h1 >
15+ < h1 className = "layout" > Layout</ h1 >
1516 < Suspense >
1617 < Outlet />
1718 </ Suspense >
Original file line number Diff line number Diff line change 1+ .a-count {
2+ color : pink;
3+ }
Original file line number Diff line number Diff line change 1+ import { useState } from 'react'
2+ import './a-count.css'
3+
4+ export default function ACount ( ) {
5+ const [ count , setCount ] = useState ( 0 )
6+
7+ return (
8+ < button className = "a-count" onClick = { ( ) => setCount ( prev => ++ prev ) } > { count } </ button >
9+ )
10+ }
Original file line number Diff line number Diff line change 1+ .layout {
2+ color : # 333 ;
3+ }
Original file line number Diff line number Diff line change 1+ import { lazy } from 'react'
12import { useNavigate } from 'react-router-dom'
23import './a.css'
34
5+ const ACount = lazy ( ( ) => import ( '../components/a-count' ) )
6+
47export default function A ( ) {
58 const navigate = useNavigate ( )
69 return (
710 < >
811 < h1 className = "a" > Page A</ h1 >
912 < button onClick = { ( ) => navigate ( '/' ) } > to index</ button >
13+ < ACount />
1014 </ >
1115 )
1216}
Original file line number Diff line number Diff line change @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react-swc'
44// https://vitejs.dev/config/
55export default defineConfig ( {
66 plugins : [ react ( ) ] ,
7+ ssgOptions : {
8+ formatting : 'minify' ,
9+ } ,
710} )
Original file line number Diff line number Diff line change 8080 "html5parser" : " ^2.0.2" ,
8181 "jsdom" : " ^22.1.0" ,
8282 "kolorist" : " ^1.8.0" ,
83+ "prettier" : " ^3.0.0" ,
8384 "react-helmet-async" : " ^1.3.0" ,
8485 "yargs" : " ^17.7.2"
8586 },
8687 "devDependencies" : {
87- "@ririd/eslint-config" : " 0.5.1 " ,
88+ "@ririd/eslint-config" : " 0.6.0 " ,
8889 "@types/fs-extra" : " ^11.0.1" ,
8990 "@types/html-minifier" : " ^4.0.2" ,
9091 "@types/jsdom" : " ^21.1.1" ,
9192 "@types/node" : " ^18.15.11" ,
93+ "@types/prettier" : " ^2.7.3" ,
9294 "@types/react" : " ^18.2.14" ,
9395 "@types/react-dom" : " ^18.2.6" ,
94- "@types/react-helmet-async" : " ^1.0.3" ,
9596 "@types/yargs" : " ^17.0.24" ,
9697 "bumpp" : " ^9.1.0" ,
9798 "critters" : " ^0.0.19" ,
98- "eslint" : " ^8.40 .0" ,
99- "esno" : " ^0.16.3 " ,
99+ "eslint" : " ^8.45 .0" ,
100+ "esno" : " ^0.17.0 " ,
100101 "p-queue" : " ^7.3.4" ,
101102 "react" : " ^18.2.0" ,
102103 "react-dom" : " ^18.2.0" ,
You can’t perform that action at this time.
0 commit comments