Skip to content

Commit d584ee3

Browse files
committedApr 21, 2024·
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

+2-2
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

+1
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'
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, '_'))

1 commit comments

Comments
 (1)

Mister-Hope commented on Apr 22, 2024

@Mister-Hope
Member

This implementation probably works, but not sure if the chunkname is good to use. Maybe it would be a little long I guess?

Please sign in to comment.