Skip to content

Commit

Permalink
feat: parse fetch file suppory dynamic option
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Aug 5, 2024
1 parent 7c6d441 commit fb308ac
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/utils/src/server/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,16 @@ const parseFeRoutes = async () => {
`
routes = routes.replace(/"component":("(.+?)")/g, (global, m1, m2) => {
const currentWebpackChunkName = re.exec(routes)![2]
if (dynamic) {
return `"component": function dynamicComponent () {
return dynamic ? `"component": function dynamicComponent () {
return import(/* webpackChunkName: "${currentWebpackChunkName}" */ '${m2.replace(/\^/g, '"')}')
}
`
} else {
return `"component": require('${m2.replace(/\^/g, '"')}').default`
}
` : `"component": require('${m2.replace(/\^/g, '"')}').default`
})
re.lastIndex = 0
routes = routes.replace(/"fetch":("(.+?)")/g, (global, m1, m2) => {
const currentWebpackChunkName = re.exec(routes)![2]
return `"fetch": () => import(/* webpackChunkName: "${currentWebpackChunkName}-fetch" */ '${m2.replace(/\^/g, '"')}')`
return dynamic ? `"fetch": () => import(/* webpackChunkName: "${currentWebpackChunkName}-fetch" */ '${m2.replace(/\^/g, '"')}')`
: `"fetch": () => require('${m2.replace(/\^/g, '"')}')`
})
await writeRoutes(routes, 'ssr-declare-routes.js')
await transformManualRoutes()
Expand Down

0 comments on commit fb308ac

Please sign in to comment.