Skip to content

Commit

Permalink
fix: just return content with devFlag + html content
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed May 16, 2020
1 parent bdc7e70 commit 71cfbfe
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/node/server/serverPluginModuleRewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,34 @@ export const moduleRewritePlugin: ServerPlugin = ({
await initLexer
let hasInjectedDevFlag = false
const importer = '/index.html'
return html!.replace(scriptRE, (matched, openTag, script) => {
const devFlag = hasInjectedDevFlag ? `` : devInjectionCode
hasInjectedDevFlag = true
if (script) {
return `${devFlag}${openTag}${rewriteImports(
root,
script,
importer,
resolver
)}</script>`
} else {
const srcAttr = openTag.match(srcRE)
if (srcAttr) {
// register script as a import dep for hmr
const importee = cleanUrl(
slash(path.resolve('/', srcAttr[1] || srcAttr[2]))
)
debugHmr(` ${importer} imports ${importee}`)
ensureMapEntry(importerMap, importee).add(importer)
const devFlag = hasInjectedDevFlag ? `` : devInjectionCode
return (
devFlag +
html!.replace(scriptRE, (matched, openTag, script) => {
debugHmr(matched, openTag, script)

hasInjectedDevFlag = true
if (script) {
return `${openTag}${rewriteImports(
root,
script,
importer,
resolver
)}</script>`
} else {
const srcAttr = openTag.match(srcRE)
if (srcAttr) {
// register script as a import dep for hmr
const importee = cleanUrl(
slash(path.resolve('/', srcAttr[1] || srcAttr[2]))
)
debugHmr(` ${importer} imports ${importee}`)
ensureMapEntry(importerMap, importee).add(importer)
}
return `${matched}`
}
return `${devFlag}${matched}`
}
})
})
)
}

app.use(async (ctx, next) => {
Expand Down

0 comments on commit 71cfbfe

Please sign in to comment.