Skip to content

Commit

Permalink
fix(build): remove leading underscore from chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Oct 13, 2022
1 parent 3fd20fe commit 41a519c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/client/app/utils.ts
Expand Up @@ -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`
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/shared/shared.ts
Expand Up @@ -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(/(?<=^|\/)_+(?=[^/]*$)/, '')
)
}

0 comments on commit 41a519c

Please sign in to comment.