Skip to content

Commit d584ee3

Browse files
committed
fix(core): transform file path to chunk name (close #1531)
1 parent 0333627 commit d584ee3

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/core/src/page/resolvePageChunkInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { path, sanitizeFileName } from '@vuepress/utils'
1+
import { path, transformPathToFileName } from '@vuepress/utils'
22
import type { App } from '../types/index.js'
33

44
/**
@@ -17,7 +17,7 @@ export const resolvePageChunkInfo = ({
1717
} => {
1818
const chunkFilePathRelative = path.join('pages', `${htmlFilePathRelative}.js`)
1919
const chunkFilePath = app.dir.temp(chunkFilePathRelative)
20-
const chunkName = sanitizeFileName(path.basename(htmlFilePathRelative))
20+
const chunkName = transformPathToFileName(htmlFilePathRelative)
2121

2222
return {
2323
chunkFilePath,

packages/utils/src/module/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './getDirname.js'
22
export * from './importFile.js'
33
export * from './isChildPath.js'
44
export * from './sanitizeFileName.js'
5+
export * from './transformPathToFileName.js'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sanitizeFileName } from './sanitizeFileName.js'
2+
3+
/**
4+
* Transforms a path to a file name, replacing slashes with underscores
5+
*/
6+
export const transformPathToFileName = (rawPath: string): string =>
7+
sanitizeFileName(rawPath.replace(/\//g, '_'))

0 commit comments

Comments
 (0)