@@ -5,38 +5,25 @@ const plugin = require('./plugin')
5
5
const selectBlock = require ( './select' )
6
6
const loaderUtils = require ( 'loader-utils' )
7
7
const { attrsToQuery } = require ( './codegen/utils' )
8
- const { parse } = require ( '@vue/component-compiler-utils' )
9
8
const genStylesCode = require ( './codegen/styleInjection' )
10
9
const { genHotReloadCode } = require ( './codegen/hotReload' )
11
10
const genCustomBlocksCode = require ( './codegen/customBlocks' )
12
11
const componentNormalizerPath = require . resolve ( './runtime/componentNormalizer' )
13
12
const { NS } = require ( './plugin' )
13
+ const { resolveCompiler } = require ( './compiler' )
14
14
15
15
let errorEmitted = false
16
16
17
- function loadTemplateCompiler ( loaderContext ) {
18
- try {
19
- return require ( 'vue-template-compiler' )
20
- } catch ( e ) {
21
- if ( / v e r s i o n m i s m a t c h / . test ( e . toString ( ) ) ) {
22
- loaderContext . emitError ( e )
23
- } else {
24
- loaderContext . emitError ( new Error (
25
- `[vue-loader] vue-template-compiler must be installed as a peer dependency, ` +
26
- `or a compatible compiler implementation must be passed via options.`
27
- ) )
28
- }
29
- }
30
- }
31
-
32
17
module . exports = function ( source ) {
33
18
const loaderContext = this
34
19
35
20
if ( ! errorEmitted && ! loaderContext [ 'thread-loader' ] && ! loaderContext [ NS ] ) {
36
- loaderContext . emitError ( new Error (
37
- `vue-loader was used without the corresponding plugin. ` +
38
- `Make sure to include VueLoaderPlugin in your webpack config.`
39
- ) )
21
+ loaderContext . emitError (
22
+ new Error (
23
+ `vue-loader was used without the corresponding plugin. ` +
24
+ `Make sure to include VueLoaderPlugin in your webpack config.`
25
+ )
26
+ )
40
27
errorEmitted = true
41
28
}
42
29
@@ -59,14 +46,17 @@ module.exports = function (source) {
59
46
60
47
const isServer = target === 'node'
61
48
const isShadow = ! ! options . shadowMode
62
- const isProduction = options . productionMode || minimize || process . env . NODE_ENV === 'production'
49
+ const isProduction =
50
+ options . productionMode || minimize || process . env . NODE_ENV === 'production'
63
51
const filename = path . basename ( resourcePath )
64
52
const context = rootContext || process . cwd ( )
65
53
const sourceRoot = path . dirname ( path . relative ( context , resourcePath ) )
66
54
67
- const descriptor = parse ( {
55
+ const { compiler, templateCompiler } = resolveCompiler ( loaderContext )
56
+
57
+ const descriptor = compiler . parse ( {
68
58
source,
69
- compiler : options . compiler || loadTemplateCompiler ( loaderContext ) ,
59
+ compiler : options . compiler || templateCompiler ,
70
60
filename,
71
61
sourceRoot,
72
62
needMap : sourceMap
@@ -78,6 +68,7 @@ module.exports = function (source) {
78
68
if ( incomingQuery . type ) {
79
69
return selectBlock (
80
70
descriptor ,
71
+ options ,
81
72
loaderContext ,
82
73
incomingQuery ,
83
74
! ! options . appendExtension
@@ -93,19 +84,19 @@ module.exports = function (source) {
93
84
94
85
const id = hash (
95
86
isProduction
96
- ? ( shortFilePath + '\n' + source . replace ( / \r \n / g, '\n' ) )
87
+ ? shortFilePath + '\n' + source . replace ( / \r \n / g, '\n' )
97
88
: shortFilePath
98
89
)
99
90
100
91
// feature information
101
92
const hasScoped = descriptor . styles . some ( s => s . scoped )
102
- const hasFunctional = descriptor . template && descriptor . template . attrs . functional
103
- const needsHotReload = (
93
+ const hasFunctional =
94
+ descriptor . template && descriptor . template . attrs . functional
95
+ const needsHotReload =
104
96
! isServer &&
105
97
! isProduction &&
106
- ( descriptor . script || descriptor . template ) &&
98
+ ( descriptor . script || descriptor . scriptSetup || descriptor . template ) &&
107
99
options . hotReload !== false
108
- )
109
100
110
101
// template
111
102
let templateImport = `var render, staticRenderFns`
@@ -116,21 +107,20 @@ module.exports = function (source) {
116
107
const scopedQuery = hasScoped ? `&scoped=true` : ``
117
108
const attrsQuery = attrsToQuery ( descriptor . template . attrs )
118
109
const query = `?vue&type=template${ idQuery } ${ scopedQuery } ${ attrsQuery } ${ inheritQuery } `
119
- const request = templateRequest = stringifyRequest ( src + query )
110
+ const request = ( templateRequest = stringifyRequest ( src + query ) )
120
111
templateImport = `import { render, staticRenderFns } from ${ request } `
121
112
}
122
113
123
114
// script
124
115
let scriptImport = `var script = {}`
125
- if ( descriptor . script ) {
126
- const src = descriptor . script . src || resourcePath
127
- const attrsQuery = attrsToQuery ( descriptor . script . attrs , 'js' )
116
+ const { script, scriptSetup } = descriptor
117
+ if ( script || scriptSetup ) {
118
+ const src = ( script && ! scriptSetup && script . src ) || resourcePath
119
+ const attrsQuery = attrsToQuery ( ( scriptSetup || script ) . attrs , 'js' )
128
120
const query = `?vue&type=script${ attrsQuery } ${ inheritQuery } `
129
121
const request = stringifyRequest ( src + query )
130
- scriptImport = (
131
- `import script from ${ request } \n` +
132
- `export * from ${ request } ` // support named exports
133
- )
122
+ scriptImport =
123
+ `import script from ${ request } \n` + `export * from ${ request } ` // support named exports
134
124
}
135
125
136
126
// styles
@@ -147,7 +137,8 @@ module.exports = function (source) {
147
137
)
148
138
}
149
139
150
- let code = `
140
+ let code =
141
+ `
151
142
${ templateImport }
152
143
${ scriptImport }
153
144
${ stylesCode }
@@ -183,7 +174,9 @@ var component = normalizer(
183
174
if ( ! isProduction ) {
184
175
// Expose the file's full path in development, so that it can be opened
185
176
// from the devtools.
186
- code += `\ncomponent.options.__file = ${ JSON . stringify ( rawShortFilePath . replace ( / \\ / g, '/' ) ) } `
177
+ code += `\ncomponent.options.__file = ${ JSON . stringify (
178
+ rawShortFilePath . replace ( / \\ / g, '/' )
179
+ ) } `
187
180
} else if ( options . exposeFilename ) {
188
181
// Libraries can opt-in to expose their components' filenames in production builds.
189
182
// For security reasons, only expose the file's basename in production.
0 commit comments