Comments (3)
👋 Hey! @shellscape nice to meet you here.
I'm not sure what your source code looks like, but this plugin will only fix some edge cases that Vite/Rollup can't handle (that would definitely have // [vite-plugin-dynamic-import] runtime -S-
).
If the importee
part of import()
in the source code can be correctly processed by Vite/Rollup, then // [vite-plugin-dynamic-import] runtime -S-
will not be generated.
from vite-plugin-dynamic-import.
Ah that's interesting. That would be a nice bit of info for the readme!
from vite-plugin-dynamic-import.
In Vite, only if importee
can be resolved normally by resolve()
, it can be regarded as a valid import()
statement. However, resolve()
has many internal restrictions, which leads to the inability to handle many edge scenarios. .
source code is here 👉 https://github.com/vitejs/vite/blob/v4.4.11/packages/vite/src/node/plugins/dynamicImportVars.ts#L106-L109
I list some examples of what are considered "edge cases" that need to be handled by vite-plugin-dynamic-import
.
// 1. Absolute path are confused with alias, `/root/src` is an alias.
import(`/root/src/views/${id}`)
// 2. Missing slash after `./views`
import(`./views${id}.tsx`)
// 3. Contains both aliases and operations
import('@/views/' + 'foo.js')
// 4. Only aliases and no file extension
import(`@/${id}`)
You can see them in the test files. 👉 test/fixtures/src/main.ts, and output is here 👉 test/fixtures/snapshots/main.ts
from vite-plugin-dynamic-import.
Related Issues (20)
- Bare imports do not work in monorepos HOT 8
- Cannot find module 'vite-plugin-utils' or its corresponding type declarations. HOT 2
- Build error when using the plugin in Vite.config HOT 1
- How can I import from some package?
- when this method in node_modules HOT 8
- Internal server error: Cannot use 'import.meta' outside a module HOT 3
- when i use node_modules error will occur when starting HOT 3
- Source Maps and Line Numbers are not correct HOT 1
- Please add a LICENSE if you are okay with people using this plugin HOT 1
- Not working in Vue project HOT 1
- Massive import size HOT 2
- [vite-plugin-dynamic-import] Generated runtime code has redundant judgment rules in some cases HOT 1
- The above dynamic import cannot be analyzed by Vite. HOT 5
- Dynamic import not working Windows HOT 1
- Failed to parse vite-plugin-federation HOT 1
- Imports don't work within defineAsyncComponent() in Vue 2/3 HOT 2
- [Feature Request] Import map support HOT 5
- dynamic import not include subfolder HOT 1
- re Disable dynamic import detection for one line or for whole project HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-dynamic-import.