Skip to content

Commit

Permalink
remove need for compatVite option for Vite 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rixo committed Jan 21, 2021
1 parent 0b1be66 commit a5e0973
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/make-hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const defaultHotOptions = {
// Svelte Native mode
native: false,
// Vite mode
// NOTE probably not neede anymore with Vite2, kept for compatibility with
// existing Vite1 setups though
compatVite: false,
// name of the adapter import binding
importAdapterName: globalAdapterName,
Expand Down Expand Up @@ -97,8 +99,14 @@ const renderApplyHmr = ({
}) =>
// this silly formatting keeps all original characters in their position,
// thus saving us from having to provide a sourcemap
//
// NOTE the `if (false) accept()` line is for tools that wants to see the
// accept call in the actual accepted module to enable HMR (Vite and, I
// believe, Snowpack 3)
//
`${imports.join(';')};${`
if (${compatVite ? '' : `${meta} && `}${meta}.hot) {
if (false) import.meta.hot.accept();
$2 = ${globalName}.applyHmr({
m: ${meta},
id: ${quote(id)},
Expand All @@ -109,7 +117,6 @@ const renderApplyHmr = ({
cssId: ${quote(cssId)},
nonCssHash: ${quote(nonCssHash)},
});
${compatVite ? 'import.meta.hot.accept();' : ''}
}
`
.split('\n')
Expand Down

0 comments on commit a5e0973

Please sign in to comment.