Skip to content

Commit

Permalink
fix: use relative paths for sources in Vue compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeurer committed Feb 21, 2023
1 parent a78a724 commit c38109a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path'
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
import { resolveTemplateCompilerOptions } from './template'
import type { ResolvedOptions } from '.'
Expand Down Expand Up @@ -58,6 +59,16 @@ export function resolveScript(
sourceMap: options.sourceMap,
})

if (resolved.map && Array.isArray(resolved.map.sources)) {
const sourceFolder = path.dirname(descriptor.filename)
resolved.map.sources = resolved.map.sources.map((source) => {
if (path.isAbsolute(source)) {
source = path.relative(sourceFolder, source)
}
return source
})
}

cacheToUse.set(descriptor, resolved)
return resolved
}
10 changes: 10 additions & 0 deletions packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ export function compile(
)
}

if (result.map && Array.isArray(result.map.sources)) {
const sourceFolder = path.dirname(descriptor.filename)
result.map.sources = result.map.sources.map((source) => {
if (path.isAbsolute(source)) {
source = path.relative(sourceFolder, source)
}
return source
})
}

return result
}

Expand Down

0 comments on commit c38109a

Please sign in to comment.