Skip to content

Commit

Permalink
fix(plugin-react-refresh): fix react refresh with base option
Browse files Browse the repository at this point in the history
close #1787
  • Loading branch information
yyx990803 committed Jan 29, 2021
1 parent d216da0 commit 59c4e7f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/plugin-react-refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -142,7 +144,7 @@ module.exports = function reactRefreshPlugin() {
{
tag: 'script',
attrs: { type: 'module' },
children: preambleCode
children: preambleCode.replace(`__BASE__`, base)
}
]
}
Expand Down

0 comments on commit 59c4e7f

Please sign in to comment.