fix(build): remove leading underscore from chunks

pull/1479/head
Divyansh Singh 2 years ago
parent 3fd20fedb8
commit 41a519cc77

@ -30,21 +30,24 @@ export function pathToFile(path: string): string {
// always force re-fetch content in dev // always force re-fetch content in dev
pagePath += `.md?t=${Date.now()}` pagePath += `.md?t=${Date.now()}`
} else { } else {
pagePath = sanitizeFileName(pagePath)
// in production, each .md file is built into a .md.js file following // in production, each .md file is built into a .md.js file following
// the path conversion scheme. // the path conversion scheme.
// /foo/bar.html -> ./foo_bar.md // /foo/bar.html -> ./foo_bar.md
if (inBrowser) { if (inBrowser) {
const base = import.meta.env.BASE_URL const base = import.meta.env.BASE_URL
pagePath = pagePath =
(pagePath.slice(base.length).replace(/\//g, '_') || 'index') + '.md' sanitizeFileName(
pagePath.slice(base.length).replace(/\//g, '_') || 'index'
) + '.md'
// client production build needs to account for page hash, which is // client production build needs to account for page hash, which is
// injected directly in the page's html // injected directly in the page's html
const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()]
pagePath = `${base}assets/${pagePath}.${pageHash}.js` pagePath = `${base}assets/${pagePath}.${pageHash}.js`
} else { } else {
// ssr build uses much simpler name mapping // ssr build uses much simpler name mapping
pagePath = `./${pagePath.slice(1).replace(/\//g, '_')}.md.js` pagePath = `./${sanitizeFileName(
pagePath.slice(1).replace(/\//g, '_')
)}.md.js`
} }
} }

@ -173,6 +173,9 @@ export function sanitizeFileName(name: string): string {
return ( return (
driveLetter + driveLetter +
name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, '_') name
.slice(driveLetter.length)
.replace(INVALID_CHAR_REGEX, '_')
.replace(/(?<=^|\/)_+(?=[^/]*$)/, '')
) )
} }

Loading…
Cancel
Save