vite-plugin / vite-plugin-dynamic-import

Enhance Vite builtin dynamic import
https://www.npmjs.com/package/vite-plugin-dynamic-import
MIT License
193 stars 11 forks source link

Any chance for dynamic imports with absolute paths #37

Closed hassanzohdy closed 1 year ago

hassanzohdy commented 2 years ago

Hello,

I was wondering if there any chance to have this plugin work with dynamic import and absolute paths, that was really good to me when working with CRA, i suppose this is supported by webpack or so, but any idea of how getting this done.

Thanks in advance

caoxiemeihao commented 2 years ago

Could you be more specific

hassanzohdy commented 2 years ago

Yup, you can check this with all the info needed

https://github.com/vitejs/vite/issues/10460

hassanzohdy commented 2 years ago

@caoxiemeihao Any recommendations about it

caoxiemeihao commented 2 years ago
const aliases = {
- apps: "/src/apps",
+ apps: path.join(__dirname, "src/apps"),
};

vite-plugin-dynamic-import always based on file system paths, /src/apps will be treated as the absolute path to the file, nott the root directory of the Vite project.


apps: "/src/apps"

importer: /Users/atom/Desktop/issues/vite-plugin-dynamic-import-37/src/main.tsx
importee: /src/apps

↓↓↓↓ After calculation ↓↓↓

../../../../../../src/apps ❌

apps: path.join(__dirname, "src/apps")

importer: /Users/atom/Desktop/issues/vite-plugin-dynamic-import-37/src/main.tsx
importee: /Users/atom/Desktop/issues/vite-plugin-dynamic-import-37/src/apps

↓↓↓↓ After calculation ↓↓↓

./apps ✅