From f9d92e5e0d14a9355ad316fe500dc919f28ae7e4 Mon Sep 17 00:00:00 2001 From: JongHak Seo Date: Wed, 11 Oct 2023 04:53:29 +0900 Subject: [PATCH] change custom dynamic import plugin for fix import issue This solution was suggested by https://github.com/lookis --- utils/plugins/custom-dynamic-import.ts | 33 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/utils/plugins/custom-dynamic-import.ts b/utils/plugins/custom-dynamic-import.ts index fbf9ae8ad..d80c56559 100644 --- a/utils/plugins/custom-dynamic-import.ts +++ b/utils/plugins/custom-dynamic-import.ts @@ -3,24 +3,31 @@ import type { PluginOption } from "vite"; export default function customDynamicImport(): PluginOption { return { name: "custom-dynamic-import", - renderDynamicImport() { - if (process.env.__FIREFOX__) { + renderDynamicImport({ moduleId }) { + if (!moduleId.includes("node_modules")) { + // ↑ dont modify any import from node_modules + if (process.env.__FIREFOX__) { + return { + left: ` + { + const dynamicImport = (path) => import(path); + dynamicImport(browser.runtime.getURL('./') + + `, + right: ".split('../').join(''))}", + }; + } return { left: ` - { - const dynamicImport = (path) => import(path); - dynamicImport(browser.runtime.getURL('./') + - `, - right: ".split('../').join(''))}", + { + const dynamicImport = (path) => import(path); + dynamicImport( + `, + right: ")}", }; } return { - left: ` - { - const dynamicImport = (path) => import(path); - dynamicImport( - `, - right: ")}", + left: "import(", + right: ")", }; }, };