Skip to content

Commit 21c1d8f

Browse files
committed
fix: sourcemap when neccessary
1 parent 7597cf0 commit 21c1d8f

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/transforms/vue2.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Debug from 'debug'
22
import MagicString from 'magic-string'
3+
import { TransformResult } from 'rollup'
34
import { Transformer } from '../types'
45
import { Context } from '../context'
56
import { pascalCase, stringifyComponentImport } from '../utils'
@@ -47,9 +48,9 @@ export function Vue2Transformer(ctx: Context): Transformer {
4748

4849
s.prepend(`${head.join('\n')}\n`)
4950

50-
return {
51-
code: s.toString(),
52-
map: s.generateMap(),
53-
}
51+
const result: TransformResult = { code: s.toString() }
52+
if (ctx.viteConfig.build.sourcemap)
53+
result.map = s.generateMap({ hires: true })
54+
return result
5455
}
5556
}

src/transforms/vue3.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Debug from 'debug'
22
import MagicString from 'magic-string'
3+
import type { TransformResult } from 'rollup'
34
import { Transformer } from '../types'
45
import { Context } from '../context'
56
import { pascalCase, stringifyComponentImport } from '../utils'
@@ -46,9 +47,9 @@ export function Vue3Transformer(ctx: Context): Transformer {
4647

4748
s.prepend(`${head.join('\n')}\n`)
4849

49-
return {
50-
code: s.toString(),
51-
map: s.generateMap(),
52-
}
50+
const result: TransformResult = { code: s.toString() }
51+
if (ctx.viteConfig.build.sourcemap)
52+
result.map = s.generateMap({ hires: true })
53+
return result
5354
}
5455
}

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TransformResult } from 'rollup'
2+
13
export interface ImportInfo {
24
name?: string
35
importName?: string
@@ -20,7 +22,7 @@ export interface UILibraryOptions {
2022

2123
export type Matcher = (id: string) => boolean | null | undefined
2224

23-
export type Transformer = (code: string, id: string, path: string, query: Record<string, string>) => null | {code: string; map: any}
25+
export type Transformer = (code: string, id: string, path: string, query: Record<string, string>) => null | TransformResult
2426

2527
/**
2628
* Plugin options.

0 commit comments

Comments
 (0)