1
1
import type { SFCDescriptor } from 'vue/compiler-sfc'
2
- import type { TransformPluginContext } from 'rollup'
2
+ import type { ExistingRawSourceMap , TransformPluginContext } from 'rollup'
3
3
import type { ResolvedOptions } from '.'
4
+ import type { RawSourceMap } from 'source-map'
5
+ import { formatPostcssSourceMap } from 'vite'
4
6
5
7
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6
8
export async function transformStyle (
7
9
code : string ,
8
10
descriptor : SFCDescriptor ,
9
11
index : number ,
10
12
options : ResolvedOptions ,
11
- pluginContext : TransformPluginContext
13
+ pluginContext : TransformPluginContext ,
14
+ filename : string
12
15
) {
13
16
const block = descriptor . styles [ index ]
14
17
// vite already handles pre-processors and CSS module so this is only
@@ -19,7 +22,14 @@ export async function transformStyle(
19
22
id : `data-v-${ descriptor . id } ` ,
20
23
isProd : options . isProduction ,
21
24
source : code ,
22
- scoped : block . scoped
25
+ scoped : block . scoped ,
26
+ postcssOptions : {
27
+ map : {
28
+ from : filename ,
29
+ inline : false ,
30
+ annotation : false
31
+ }
32
+ }
23
33
} )
24
34
25
35
if ( result . errors . length ) {
@@ -36,8 +46,17 @@ export async function transformStyle(
36
46
return null
37
47
}
38
48
49
+ const map = result . map
50
+ ? formatPostcssSourceMap (
51
+ // version property of result.map is declared as string
52
+ // but actually it is a number
53
+ result . map as Omit < RawSourceMap , 'version' > as ExistingRawSourceMap ,
54
+ filename
55
+ )
56
+ : ( { mappings : '' } as any )
57
+
39
58
return {
40
59
code : result . code ,
41
- map : result . map || ( { mappings : '' } as any )
60
+ map : map
42
61
}
43
62
}
0 commit comments