1
- import hash from 'hash-sum'
2
- import path from 'path'
3
1
import qs from 'querystring'
4
- import {
5
- parse ,
6
- rewriteDefault ,
7
- SFCBlock ,
8
- SFCDescriptor
9
- } from '@vue/compiler-sfc'
2
+ import { rewriteDefault , SFCBlock , SFCDescriptor } from '@vue/compiler-sfc'
10
3
import { ResolvedOptions } from '.'
11
- import { getPrevDescriptor , setDescriptor } from './utils/descriptorCache'
4
+ import { createDescriptor , getPrevDescriptor } from './utils/descriptorCache'
12
5
import { PluginContext , TransformPluginContext } from 'rollup'
13
6
import { resolveScript } from './script'
14
7
import { transformTemplateInMain } from './template'
@@ -26,23 +19,13 @@ export async function transformMain(
26
19
27
20
// prev descriptor is only set and used for hmr
28
21
const prevDescriptor = getPrevDescriptor ( filename )
29
- const { descriptor, errors } = parse ( code , {
30
- sourceMap : true ,
31
- filename
32
- } )
33
-
34
- // set the id on the descriptor
35
- const shortFilePath = path
36
- . relative ( root , filename )
37
- . replace ( / ^ ( \. \. [ \/ \\ ] ) + / , '' )
38
- . replace ( / \\ / g, '/' )
39
-
40
- descriptor . id = hash (
41
- isProduction ? shortFilePath + '\n' + code : shortFilePath
22
+ const { descriptor, errors } = createDescriptor (
23
+ filename ,
24
+ code ,
25
+ root ,
26
+ isProduction
42
27
)
43
28
44
- setDescriptor ( filename , descriptor )
45
-
46
29
if ( errors . length ) {
47
30
errors . forEach ( ( error ) =>
48
31
pluginContext . error ( createRollupError ( filename , error ) )
@@ -100,13 +83,9 @@ export async function transformMain(
100
83
`_sfc_main.__scopeId = ${ JSON . stringify ( `data-v-${ descriptor . id } ` ) } `
101
84
)
102
85
}
103
- if ( ! isProduction ) {
104
- output . push ( `_sfc_main.__file = ${ JSON . stringify ( shortFilePath ) } ` )
105
- } else if ( devServer ) {
86
+ if ( devServer ) {
106
87
// expose filename during serve for devtools to pickup
107
- output . push (
108
- `_sfc_main.__file = ${ JSON . stringify ( path . basename ( shortFilePath ) ) } `
109
- )
88
+ output . push ( `_sfc_main.__file = ${ JSON . stringify ( filename ) } ` )
110
89
}
111
90
output . push ( 'export default _sfc_main' )
112
91
0 commit comments