File tree 4 files changed +695
-19
lines changed
4 files changed +695
-19
lines changed Original file line number Diff line number Diff line change
1
+ const hotReloadAPIPath = require . resolve ( 'vue-hot-reload-api' )
2
+
3
+ module . exports = function genHotReloadCode ( id , functional ) {
4
+ // TODO handle CSSModules and style injection disposal
5
+ return `
6
+ /* hot reload */
7
+ if (module.hot) {
8
+ var api = require('${ hotReloadAPIPath } ')
9
+ api.install(require('vue'))
10
+ if (api.compatible) {
11
+ module.hot.accept()
12
+ if (!module.hot.data) {
13
+ api.createRecord('${ id } ', component.options)
14
+ } else {
15
+ api.${ functional ? `rerender` : `reload` } ('${ id } ', component.options)
16
+ }
17
+ }
18
+ }
19
+ ` . trim ( )
20
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const qs = require('querystring')
5
5
const loaderUtils = require ( 'loader-utils' )
6
6
const selectBlock = require ( './selector' )
7
7
const plugin = require ( './plugin' )
8
+ const genHotReloadCode = require ( './hotReload' )
8
9
const componentNormalizerPath = require . resolve ( './runtime/componentNormalizer' )
9
10
10
11
module . exports = function ( source ) {
@@ -119,7 +120,7 @@ var component = normalizer(
119
120
${ isServer ? JSON . stringify ( hash ( request ) ) : `null` }
120
121
${ incomingQuery . shadow ? `,true` : `` }
121
122
)
122
- ` . trim ( )
123
+ `. trim ( )
123
124
124
125
if ( descriptor . customBlocks && descriptor . customBlocks . length ) {
125
126
// TODO custom blocks
@@ -130,7 +131,7 @@ var component = normalizer(
130
131
}
131
132
132
133
if ( needsHotReload ) {
133
- // TODO hot reload
134
+ code += genHotReloadCode ( id , hasFunctional )
134
135
}
135
136
136
137
code += `\nexport default component.exports`
Original file line number Diff line number Diff line change 54
54
"vue-template-compiler" : " ^2.5.16" ,
55
55
"webpack" : " ^4.1.0" ,
56
56
"webpack-cli" : " ^2.0.10" ,
57
+ "webpack-dev-server" : " ^3.1.1" ,
57
58
"webpack-merge" : " ^4.1.2" ,
58
59
"yorkie" : " ^1.0.3"
59
60
},
You can’t perform that action at this time.
0 commit comments