From 59c4e7f824a7d7db689215568b66d68570e3f3da Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 29 Jan 2021 10:55:28 -0500 Subject: [PATCH] fix(plugin-react-refresh): fix react refresh with base option close #1787 --- packages/plugin-react-refresh/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/plugin-react-refresh/index.js b/packages/plugin-react-refresh/index.js index 9982ded1df1645..f35b0d528aea16 100644 --- a/packages/plugin-react-refresh/index.js +++ b/packages/plugin-react-refresh/index.js @@ -22,7 +22,7 @@ export default exports ` const preambleCode = ` -import RefreshRuntime from "${runtimePublicPath}" +import RefreshRuntime from "__BASE__${runtimePublicPath.slice(1)}" RefreshRuntime.injectIntoGlobalHook(window) window.$RefreshReg$ = () => {} window.$RefreshSig$ = () => (type) => type @@ -36,12 +36,14 @@ window.__vite_plugin_react_preamble_installed__ = true */ module.exports = function reactRefreshPlugin() { let shouldSkip = false + let base = '/' return { name: 'react-refresh', configResolved(config) { shouldSkip = config.command === 'build' || config.isProduction + base = config.base }, resolveId(id) { @@ -142,7 +144,7 @@ module.exports = function reactRefreshPlugin() { { tag: 'script', attrs: { type: 'module' }, - children: preambleCode + children: preambleCode.replace(`__BASE__`, base) } ] }