-
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.
fix: get route assets by route manifest (#6083)
- Loading branch information
Showing
9 changed files
with
59 additions
and
21 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,6 @@ | ||
--- | ||
'@ice/route-manifest': patch | ||
'@ice/app': patch | ||
--- | ||
|
||
fix: get route assets by route manifest |
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,7 @@ | ||
export default function Dashboard() { | ||
return ( | ||
<div> | ||
<h2>dashboard</h2> | ||
</div> | ||
); | ||
} |
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,35 @@ | ||
import path from 'path'; | ||
import fse from 'fs-extra'; | ||
import type { RouteItem } from '@ice/runtime/types'; | ||
import matchRoutes from '@ice/runtime/matchRoutes'; | ||
import { logger } from './logger.js'; | ||
import type RouteManifest from './routeManifest.js'; | ||
|
||
function getRouteAsset(routeManifest: RouteItem[], routePath: string): string { | ||
const matches = matchRoutes(routeManifest, routePath); | ||
// Ingnore layout assets and return leaf route. | ||
const routeMatch = matches[matches.length - 1]; | ||
const componentName = routeMatch?.route?.componentName; | ||
return componentName ? `p_${componentName}.js` : ''; | ||
} | ||
|
||
function injectInitialEntry(routeManifest: RouteManifest, outputDir: string) { | ||
// Read the latest routes info. | ||
const routePaths = routeManifest.getFlattenRoute(); | ||
const routeItems = routeManifest.getNestedRoute(); | ||
routePaths.forEach((routePath) => { | ||
const routeAsset = getRouteAsset(routeItems, routePath); | ||
// Inject `initialPath` when router type is memory. | ||
const routeAssetPath = path.join(outputDir, 'js', routeAsset); | ||
if (fse.existsSync(routeAssetPath)) { | ||
fse.writeFileSync(routeAssetPath, | ||
`window.__ICE_APP_CONTEXT__=Object.assign(window.__ICE_APP_CONTEXT__||{}, {routePath: '${routePath}'});${ | ||
fse.readFileSync(routeAssetPath, 'utf-8')}`); | ||
} else { | ||
logger.warn(`Can not find ${routeAssetPath} when inject initial path.`); | ||
} | ||
}); | ||
} | ||
|
||
export default injectInitialEntry; | ||
|
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,3 @@ | ||
import matchRoutes from './esm/matchRoutes'; | ||
|
||
export default matchRoutes; |
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