Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 13, 2019
1 parent 108c1c1 commit 958d55a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const VueLoaderPlugin = require('../dist/plugin')
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, './main.js'),
devtool: 'cheap-module-eval-source-map',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
Expand Down
9 changes: 5 additions & 4 deletions src/hotReload.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// __VUE_HMR_RUNTIME__ is injected to global scope by @vue/runtime-core

export function genHotReloadCode(id: string, templateRequest?: string): string {
export function genHotReloadCode(
id: string,
templateRequest: string | undefined
): string {
return `
/* hot reload */
if (module.hot) {
const api = __VUE_HMR_RUNTIME__
module.hot.accept()
if (!api.isRecorded('${id}')) {
api.createRecord('${id}', script)
} else {
if (!api.createRecord('${id}', script)) {
api.reload('${id}', script)
}
${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ const loader: webpack.loader.Loader = function(source) {
const scopedQuery = hasScoped ? `&scoped=true` : ``
const attrsQuery = attrsToQuery(descriptor.template.attrs)
const query = `?vue&type=template${idQuery}${scopedQuery}${attrsQuery}${inheritQuery}`
const request = (templateRequest = stringifyRequest(src + query))
templateImport = `import render from ${request}`
templateRequest = stringifyRequest(src + query)
templateImport = `import render from ${templateRequest}`
}

// script
Expand All @@ -125,9 +125,10 @@ const loader: webpack.loader.Loader = function(source) {
const src = descriptor.script.src || resourcePath
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
const query = `?vue&type=script${attrsQuery}${inheritQuery}`
const request = stringifyRequest(src + query)
const scriptRequest = stringifyRequest(src + query)
scriptImport =
`import script from ${request}\n` + `export * from ${request}` // support named exports
`import script from ${scriptRequest}\n` +
`export * from ${scriptRequest}` // support named exports
}

// styles
Expand Down

0 comments on commit 958d55a

Please # to comment.