Skip to content

Commit 57cf5a6

Browse files
committed
Fix HMR code not being treeshaken
1 parent 27384a6 commit 57cf5a6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
Binary file not shown.

src/plugins/external-plugin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ export const unplugin = createUnplugin((options: ExternalPluginOptions, meta) =>
143143
magic.appendLeft(insertPos, `${target}.fluent = ${target}.fluent || {};\n`)
144144
for (const dep of translations)
145145
magic.appendLeft(insertPos, `${target}.fluent['${dep.locale}'] = ${dep.importVariable}\n`)
146+
147+
const __HOT_API__ = meta.framework === 'webpack' ? 'import.meta.webpackHot' : 'import.meta.hot'
148+
146149
magic.appendLeft(insertPos, `
147-
const __HOT_API__ = import.meta.hot || import.meta.webpackHot
148-
if (__HOT_API__) {
149-
__HOT_API__.accept([${translations.map(dep => `'${dep.ftlPath}'`).join(', ')}], () => {
150+
if (${__HOT_API__}) {
151+
${__HOT_API__}.accept([${translations.map(dep => `'${dep.ftlPath}'`).join(', ')}], () => {
150152
${translations.map(({ locale, importVariable }) => `${target}.fluent['${locale}'] = ${importVariable}`).join('\n')}
151153
152154
delete ${target}._fluent

0 commit comments

Comments
 (0)