Skip to content

Commit

Permalink
perf: only perform hmr rewrite if import from client has hot
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 20, 2020
1 parent c553de2 commit 02e2d94
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/node/server/serverPluginModuleRewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function rewriteImports(
importeeMap.set(importer, currentImportees)

for (let i = 0; i < imports.length; i++) {
const { s: start, e: end, d: dynamicIndex } = imports[i]
const { s: start, e: end, ss, se, d: dynamicIndex } = imports[i]
let id = source.substring(start, end)
let hasLiteralDynamicId = false
if (dynamicIndex >= 0) {
Expand All @@ -199,7 +199,10 @@ export function rewriteImports(
let resolved
if (id === hmrClientId) {
resolved = hmrClientPublicPath
if (!/.vue$|.vue\?type=/.test(importer)) {
if (
/\bhot\b/.test(source.substring(ss, se)) &&
!/.vue$|.vue\?type=/.test(importer)
) {
// the user explicit imports the HMR API in a js file
// making the module hot.
rewriteFileWithHMR(root, source, importer, resolver, s)
Expand Down

0 comments on commit 02e2d94

Please sign in to comment.