File tree 3 files changed +18
-30
lines changed
3 files changed +18
-30
lines changed Original file line number Diff line number Diff line change 1
1
const hotReloadAPIPath = JSON . stringify ( require . resolve ( 'vue-hot-reload-api' ) )
2
2
3
- exports . genHotReloadCode = ( id , functional ) => {
4
- return wrap ( `
5
- if (!module.hot.data) {
6
- api.createRecord('${ id } ', component.options)
7
- } else {
8
- api.${ functional ? `rerender` : `reload` } ('${ id } ', component.options)
9
- }
10
- ` )
11
- }
12
-
13
- exports . genTemplateHotReloadCode = id => {
14
- return wrap ( `
15
- if (module.hot.data) {
16
- require(${ hotReloadAPIPath } ).rerender('${ id } ', {
3
+ const genTemplateHotReloadCode = ( id , request ) => {
4
+ return `
5
+ module.hot.accept(${ request } , function () {
6
+ api.rerender('${ id } ', {
17
7
render: render,
18
8
staticRenderFns: staticRenderFns
19
9
})
20
- }
21
- ` )
10
+ })
11
+ ` . trim ( )
22
12
}
23
13
24
- function wrap ( inner ) {
14
+ exports . genHotReloadCode = ( id , functional , templateRequest ) => {
25
15
return `
26
16
/* hot reload */
27
17
if (module.hot) {
28
18
var api = require(${ hotReloadAPIPath } )
29
19
api.install(require('vue'))
30
20
if (api.compatible) {
31
21
module.hot.accept()
32
- ${ inner . trim ( ) }
22
+ if (!module.hot.data) {
23
+ api.createRecord('${ id } ', component.options)
24
+ } else {
25
+ api.${ functional ? `rerender` : `reload` } ('${ id } ', component.options)
26
+ }
27
+ ${ templateRequest ? genTemplateHotReloadCode ( id , templateRequest ) : `` }
33
28
}
34
29
}
35
30
` . trim ( )
Original file line number Diff line number Diff line change @@ -80,13 +80,14 @@ module.exports = function (source) {
80
80
81
81
// template
82
82
let templateImport = `var render, staticRenderFns`
83
+ let templateRequest
83
84
if ( descriptor . template ) {
84
85
const src = descriptor . template . src || resourcePath
85
86
const idQuery = `&id=${ id } `
86
87
const scopedQuery = hasScoped ? `&scoped=true` : ``
87
88
const attrsQuery = attrsToQuery ( descriptor . template . attrs )
88
89
const query = `?vue&type=template${ idQuery } ${ scopedQuery } ${ attrsQuery } `
89
- const request = stringifyRequest ( src + query )
90
+ const request = templateRequest = stringifyRequest ( src + query )
90
91
templateImport = `import { render, staticRenderFns } from ${ request } `
91
92
}
92
93
@@ -145,7 +146,7 @@ var component = normalizer(
145
146
}
146
147
147
148
if ( needsHotReload ) {
148
- code += `\n` + genHotReloadCode ( id , hasFunctional )
149
+ code += `\n` + genHotReloadCode ( id , hasFunctional , templateRequest )
149
150
}
150
151
151
152
// Expose filename. This is used by the devtools and vue runtime warnings.
Original file line number Diff line number Diff line change 1
1
const qs = require ( 'querystring' )
2
2
const loaderUtils = require ( 'loader-utils' )
3
3
const { compileTemplate } = require ( '@vue/component-compiler-utils' )
4
- const { genTemplateHotReloadCode } = require ( '../codegen/hotReload' )
5
4
6
5
// Loader that compiles raw template into JavaScript functions.
7
6
// This is injected by the global pitcher (../pitch) for template
@@ -18,7 +17,6 @@ module.exports = function (source) {
18
17
const isServer = loaderContext . target === 'node'
19
18
const isProduction = loaderContext . minimize || process . env . NODE_ENV === 'production'
20
19
const isFunctional = query . functional
21
- const needsHotReload = ! isServer && ! isProduction && options . hotReload !== false
22
20
23
21
// allow using custom compiler via options
24
22
const compiler = options . compiler || require ( 'vue-template-compiler' )
@@ -59,16 +57,10 @@ module.exports = function (source) {
59
57
)
60
58
}
61
59
62
- let { code } = compiled
63
-
64
- // hot-reload
65
- if ( needsHotReload ) {
66
- code += genTemplateHotReloadCode ( id )
67
- }
60
+ const { code } = compiled
68
61
69
62
// finish with ESM exports
70
- code += `export { render, staticRenderFns }`
71
- return code
63
+ return code + `\nexport { render, staticRenderFns }`
72
64
}
73
65
74
66
function pad ( source ) {
You can’t perform that action at this time.
0 commit comments