-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Exclude some libraries' optimization in node_modules. #4533
Comments
Maybe we could add this feature by respect import map mentioned in #2483. Using the strategy yyx said, avoid rewriting anything listed in import map. |
It's useful when developers use it worked with some 3rd library like pyodide, currently, if developer downloaded the full version of pyodide library and want used it by following code, they will get an error about it: <script src="/src/lib/pyodide/pyodide.js"></script>
<script type="text/javascript">
async function main(){
let pyodide = await loadPyodide({
indexURL: "/src/lib/pyodide",
});
console.log(pyodide.runPython("1 + 2"));
}
main();
</script> error: and we can see the export default "/src/lib/pyodide/pyodide.js" but in fact, we only want the original content of it, so adding a exclude parameter is a must. |
Currently #5688 has more discussion about this I'm not really sure about the feature request to remove |
Yes, I can always reload the whole thing in these steps: 1) vite optimize --force 2) restart vite server 3) refresh browser with cache disabled. However that's too much steps and it fallbacks to work like webpack (making changes, bundle the whole thing, refreshing page), in which situation I would prefer to just use esbuild to do this. antfu's problem is different, he actually needs a strategy to dedup libraries instead of removing the optimization. That means you have to refactor the resolver in vite (or maybe esbuild through plugins) to handle vue-demi correctly. My problem can be treat in these 2 views:
|
Sorry for the late reply
Watching node_modules is really expensive considering the number of files in it. I won't scale quite well and takes a lot of RAM.
I'm not sure how this can be solved, but if you edit CJS code, they would always have to be prebundled through esbuild. IMO the |
optimizeDeps: {
exclude: ['@oku/i18n'],
},
server: {
watch: {
ignored: ['!../../**/node_modules/@oku/**'],
},
}, some problem, dont watch :/ |
Can provide to ignore the package in node_modules? like sourece code for monorepo . |
We're also running into this with our monorepo that uses Lerna, which sets up symlinks through If there is no plan to resolve this issue in the short term, does anyone know any workarounds we can consider? |
I've also arrived here trying to find a way to prevent caching of internal mono-repo packages. My workaround so far is to use |
So, there are 4 levels that we need to fix:
1 is fixed by 2 and 3 are harder, though. Here's workaround we've used for 2 and 3:
|
We recently encountered a similar situation within our team, and I applied the concepts from here to resolve the issue and crafted a compact plugin for it: https://github.com/kasra-r77/vite-plugin-dependency-watcher |
Clear and concise description of the problem
I need ability to exclude the optimization (bundling & caching) of some files in node_modules. The "exclude" means the module resolution should not append
?v=xxx
to the resolved file and it should always give me latest contents without restarting the vite server.One possible solution is creating symlinks. However when I created node_modules/x → node_modules/.skip_optimize/x, nothing has changed. After digging into the source code, I think vite made an assumption that all symlinks are out of node_modules:
vite/packages/vite/src/node/plugins/resolve.ts
Line 417 in bcb6d75
However, keeping files in node_modules has a benefit that it does not hurt node's resolution (see nodejs/node#3402 for more details). Even though vite implements custom resolver, I think it would be good to take this problem into consideration.
Read more context in #4429
Suggested solution
In the code above, add a check of
optimizeDeps.exclude
. If the requested module should be excluded, then don't return something like?v=xxx
.Validations
The text was updated successfully, but these errors were encountered: