Skip to content

Commit

Permalink
change custom dynamic import plugin for fix import issue
Browse files Browse the repository at this point in the history
This solution was suggested by https://github.com/lookis
  • Loading branch information
Jonghakseo authored and Jonghakseo committed Oct 10, 2023
1 parent db500fa commit f9d92e5
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions utils/plugins/custom-dynamic-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")",
};
},
};
Expand Down

0 comments on commit f9d92e5

Please sign in to comment.