Skip to content

Commit

Permalink
fix: Fix broken sourcemap comment generation for .css files (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jastor11 committed Dec 14, 2021
1 parent dbe9617 commit 39a3583
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/plugin.ts
Expand Up @@ -160,7 +160,7 @@ export class PluginContainer {
await outputFile(
info.path,
info.type === 'chunk'
? info.code + getSourcemapComment(!!info.map, info.path)
? info.code + getSourcemapComment(!!info.map, info.path, isCSS(file.path))
: info.contents,
{ mode: info.type === 'chunk' ? info.mode : undefined }
)
Expand All @@ -183,6 +183,9 @@ export class PluginContainer {
}
}

const getSourcemapComment = (hasMap: boolean, filepath: string) => {
return hasMap ? `//# sourceMappingURL=${path.basename(filepath)}.map` : ''
const getSourcemapComment = (hasMap: boolean, filepath: string, isCssFile: boolean) => {
if (!hasMap) return ''
const prefix = isCssFile ? '/*' : '//'
const suffix = isCssFile ? ' */' : ''
return `${prefix}# sourceMappingURL=${path.basename(filepath)}${suffix}`
}

1 comment on commit 39a3583

@vercel
Copy link

@vercel vercel bot commented on 39a3583 Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.