How to make imports in transpiled file point to external folder #18939
Replies: 3 comments
-
Assuming this is only for vite build, you can probably try using plugins: [
{
name: "test",
resolveId(source) {
if (source.startsWith("@electron")) {
return { external: "relative", id: source.replace("@electron", path.resolve(__dirname, "dist-electron")) }
}
}
}
] |
Beta Was this translation helpful? Give feedback.
-
Thanks for the idea but before using a plugin i decided to check again the documentation. But i still dont understand why if i have this alias:
the output files have imports like this: import { I18nService, Lang } from "@electron/services"; instead of import { I18nService, Lang } from "../../dist-electron/services"; Aren't aliases supposed to be replaced by their values during transpilation? |
Beta Was this translation helpful? Give feedback.
-
Apparently, when you mark a module as 'external' , Vite no longer allows you to configure anything about the paths related to that module. So if you're working on an electron app, you either duplicate the code by including it inside the Vite bundle ( removing external option), or you have to create a plugin to manipulate manually the imports path. |
Beta Was this translation helpful? Give feedback.
-
I have an Electron application using TypeScript, Vite, and React.
Inside the app the code is divided into two folders.
In the
src/electron
folder, I have all the Electron-related code, and it is transpiled directly by TypeScript to thedist-electron
folder. ( some code like classes, interfaces,etc are shared with thesrc/ui
folder).In the
src/ui
folder i have the renderer part (React) and Vite transpile it to thedist-react
folder.Vite is configured to use the Electron code as external, but when i transpile my project, the imports path in the
dist-react
folder that points to thedist-electron
folder are like that:When I launch my Electron app, I get an error because it expects an import like that:
This is the error:
How can I configure Vite to fix those imports to point to the correct external folder?
Structure of my project:
This is my Vite config:
tsconfig.app.json (React):
src/electron/tsconfig.electron.json:
tsconfig.json:
package.json:
Beta Was this translation helpful? Give feedback.
All reactions