-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support split page chunk in cjs format (#6843)
* feat: support spilt page chunk in cjs format * fix: escape route path * fix: multipile entry for server compile * chore: changelog
- Loading branch information
Showing
13 changed files
with
143 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ice/app': patch | ||
--- | ||
|
||
feat: support spilt page chunk in cjs format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as path from 'path'; | ||
import { RUNTIME_TMP_DIR } from '../constant.js'; | ||
import getServerEntry from './getServerEntry.js'; | ||
import { formatServerEntry } from './multipleEntry.js'; | ||
|
||
function getEntryPoints(rootDir: string, routes: string[], mainEntry: string) { | ||
const serverEntry: Record<string, string> = {}; | ||
routes.forEach((route) => { | ||
serverEntry[`pages${route === '/' ? '/index' : route}`] = | ||
path.join(rootDir, RUNTIME_TMP_DIR, formatServerEntry(route)); | ||
}); | ||
serverEntry.index = getServerEntry(rootDir, mainEntry); | ||
|
||
return serverEntry; | ||
} | ||
|
||
export default getEntryPoints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import matchRoutes from '@ice/runtime/matchRoutes'; | ||
import type { NestedRouteManifest } from '@ice/route-manifest'; | ||
import type { CommandName } from 'build-scripts'; | ||
import { getRoutesDefinition } from '../routes.js'; | ||
import type Generator from '../service/runtimeGenerator.js'; | ||
import type { UserConfig } from '../types/userConfig.js'; | ||
import { escapeRoutePath } from './generateEntry.js'; | ||
|
||
interface Options { | ||
renderRoutes: string[]; | ||
routesManifest: NestedRouteManifest[]; | ||
generator: Generator; | ||
lazy: boolean; | ||
} | ||
|
||
export const multipleServerEntry = (userConfig: UserConfig, command: CommandName): boolean => { | ||
return userConfig?.server?.bundle === 'page' && | ||
userConfig.server.format === 'cjs' && | ||
command === 'build'; | ||
}; | ||
|
||
export const formatRoutePath = (route: string) => { | ||
return escapeRoutePath(route) | ||
.replace(/^\//, '').replace(/\//g, '_'); | ||
}; | ||
|
||
export const formatServerEntry = (route: string) => { | ||
return `server.entry.${formatRoutePath(route) || 'index'}.ts`; | ||
}; | ||
|
||
export function renderMultiEntry(options: Options) { | ||
const { renderRoutes, routesManifest, generator, lazy } = options; | ||
renderRoutes.forEach((route) => { | ||
const routeId = formatRoutePath(route); | ||
generator.addRenderFile( | ||
'core/entry.server.ts.ejs', | ||
formatServerEntry(route), | ||
{ | ||
routesFile: `./routes.${routeId}`, | ||
}, | ||
); | ||
// Generate route file for each route. | ||
const matches = matchRoutes(routesManifest, route); | ||
const { routeImports, routeDefinition } = getRoutesDefinition({ | ||
manifest: routesManifest, | ||
lazy, | ||
matchRoute: (routeItem) => { | ||
return matches.some((match) => match.route.id === routeItem.id); | ||
}, | ||
}); | ||
generator.addRenderFile('core/routes.tsx.ejs', `routes.${routeId}.tsx`, { | ||
routeImports, | ||
routeDefinition, | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters