From 41a519cc775551387093e1e18323b72bd1efe9ad Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:36:56 +0530 Subject: [PATCH] fix(build): remove leading underscore from chunks --- src/client/app/utils.ts | 9 ++++++--- src/shared/shared.ts | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 0c3c2ed101e..4e9687dbd84 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -30,21 +30,24 @@ export function pathToFile(path: string): string { // always force re-fetch content in dev pagePath += `.md?t=${Date.now()}` } else { - pagePath = sanitizeFileName(pagePath) // in production, each .md file is built into a .md.js file following // the path conversion scheme. // /foo/bar.html -> ./foo_bar.md if (inBrowser) { const base = import.meta.env.BASE_URL 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 // injected directly in the page's html const pageHash = __VP_HASH_MAP__[pagePath.toLowerCase()] pagePath = `${base}assets/${pagePath}.${pageHash}.js` } else { // ssr build uses much simpler name mapping - pagePath = `./${pagePath.slice(1).replace(/\//g, '_')}.md.js` + pagePath = `./${sanitizeFileName( + pagePath.slice(1).replace(/\//g, '_') + )}.md.js` } } diff --git a/src/shared/shared.ts b/src/shared/shared.ts index ce0052aae46..29d1e42493b 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -173,6 +173,9 @@ export function sanitizeFileName(name: string): string { return ( driveLetter + - name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, '_') + name + .slice(driveLetter.length) + .replace(INVALID_CHAR_REGEX, '_') + .replace(/(?<=^|\/)_+(?=[^/]*$)/, '') ) }