File tree 7 files changed +49
-8
lines changed
7 files changed +49
-8
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <Button />
3
+ <Button />
4
+ <Button />
5
+ </template >
6
+
7
+ <script >
8
+ import Button from ' ./Button.vue'
9
+
10
+ export default {
11
+ components: {
12
+ Button
13
+ }
14
+ }
15
+ </script >
Original file line number Diff line number Diff line change 1
1
<template >
2
- <button @click =" inc" >{{ count }}</button >
2
+ <button @click =" inc" >{{ count }}! </button >
3
3
</template >
4
4
5
5
<script >
Original file line number Diff line number Diff line change 1
- import App from './source .vue'
1
+ import App from './App .vue'
2
2
import { createApp } from 'vue'
3
3
4
4
createApp ( ) . mount ( App , '#app' )
Original file line number Diff line number Diff line change 10
10
],
11
11
"scripts" : {
12
12
"build" : " tsc" ,
13
- "dev" : " webpack-dev-server --config example/webpack.config.js --inline --hot"
13
+ "dev" : " webpack-dev-server --config example/webpack.config.js --inline --hot" ,
14
+ "build-example" : " webpack --config example/webpack.config.js --mode=production"
14
15
},
15
16
"peerDependencies" : {
16
17
"@vue/compiler-sfc" : " ^3.0.0-alpha.0"
Original file line number Diff line number Diff line change
1
+ // __VUE_HMR_RUNTIME__ is injected to global scope by @vue /runtime-core
2
+
3
+ export function genHotReloadCode ( id : string , templateRequest ?: string ) : string {
4
+ return `
5
+ /* hot reload */
6
+ if (module.hot) {
7
+ const api = __VUE_HMR_RUNTIME__
8
+ module.hot.accept()
9
+ if (!api.isRecorded('${ id } ')) {
10
+ api.createRecord('${ id } ', script)
11
+ } else {
12
+ api.reload('${ id } ', script)
13
+ }
14
+ ${ templateRequest ? genTemplateHotReloadCode ( id , templateRequest ) : '' }
15
+ }
16
+ `
17
+ }
18
+
19
+ function genTemplateHotReloadCode ( id : string , request : string ) {
20
+ return `
21
+ module.hot.accept(${ request } , () => {
22
+ api.rerender('${ id } ', render)
23
+ })
24
+ `
25
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
TemplateCompileOptions
12
12
} from '@vue/compiler-sfc'
13
13
import { selectBlock } from './select'
14
+ import { genHotReloadCode } from './hotReload'
14
15
15
16
const VueLoaderPlugin = require ( './plugin' )
16
17
@@ -147,8 +148,8 @@ const loader: webpack.loader.Loader = function(source) {
147
148
}
148
149
149
150
if ( needsHotReload ) {
150
- // TODO hot reload
151
- templateRequest
151
+ code += `\nscript.__hmrId = " ${ id } "`
152
+ code += genHotReloadCode ( id , templateRequest )
152
153
}
153
154
154
155
// Expose filename. This is used by the devtools and Vue runtime warnings.
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import loaderUtils from 'loader-utils'
4
4
import hash from 'hash-sum'
5
5
import { VueLoaderOptions } from 'src'
6
6
7
- const selfPath = require . resolve ( '.. /index' )
7
+ const selfPath = require . resolve ( './index' )
8
8
const templateLoaderPath = require . resolve ( './templateLoader' )
9
9
const stylePostLoaderPath = require . resolve ( './stylePostLoader' )
10
10
@@ -163,8 +163,7 @@ pitcher.pitch = function() {
163
163
...preLoaders
164
164
] )
165
165
// console.log(request)
166
- // the template compiler uses esm exports
167
- return `export * from ${ request } `
166
+ return `import mod from ${ request } ; export default mod;`
168
167
}
169
168
170
169
// if a custom block has no other matching loader other than vue-loader itself
You can’t perform that action at this time.
0 commit comments