-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Glob support in optimizeDeps.include #5419
Comments
Chinese: 在某些库中,需要频繁地加载不同路径下的文件。每次预编译都会刷新页面。所以需要把可能要用到的所有文件都在启动时预编译。因此我想应该支持 glob 来更便捷地添加可能需要的文件。 |
I have a need of this before for packages with many sub-exports, e.g. I think globbing would be tricky to work with |
We have non-blocking optimization #8280, and it seems that this feature becomes unimportant. |
Interesting. I think we could try Blu's proposal here, or maybe to avoid surprises only support something like |
I think this feature is still needed. Kapture.2022-06-24.at.21.01.40.mp4Reproduction repo: https://github.com/sxzz/vite-optimize-deps (cannot work on stackblitz) Reproduction steps:
|
@sxzz I found that Setting Also for your specific case, |
I think we should add support for glob imports, at least document that @sxzz let us know if this works for you, better to wait to beta.3 though to test as there are a few other PRs to improve dev server perf about to be merged |
@sapphi-red do you have a repro of this working with that |
@sapphi-red Hmmmm seems that it can't work for me. |
It worked for me with npm and yarn(non pnp). But it didn't work with pnpm. |
This worked with pnpm. So symlinks does not work well. import { defineConfig, normalizePath } from 'vite'
import vue from '@vitejs/plugin-vue'
import fs from 'fs/promises'
import path from 'path'
import url from 'url'
const exclude = './' + normalizePath(
path.relative(
url.fileURLToPath(new URL('./', import.meta.url)),
path.join(
await fs.realpath('./node_modules/element-plus/'),
'es/components/*/style/css2.mjs'
)
)
)
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
optimizeDeps: {
exclude: [exclude]
}
}) |
The first reload is expected. Does it reload two times? |
Something odd is going on. I'll check it out. The first reload shouldnt be there either |
@sapphi-red Yes, |
@sxzz Your screenshot shows reloading is happening once and pre-bundle is happening twice. |
Oh, just found it can avoid to refresh page now, and I had a better experience now as the same as 2.x. But it seems to be complicated for users to write such a config. Actually, I wrote a config to pre-optimize deps to fix this issue before. optimizeDeps: {
include: await glob(['element-plus/es/components/*/style/css.mjs'], {
cwd: $r('node_modules'),
onlyFiles: true,
}),
}, Suggestion: Third-party dep can provide a metafile to help Vite consider which files should be included or excluded to be optimized. Out of the box for Vite users. By the way, I have a question: Why some times it is possible to optimize dep without refreshing the page, and sometimes it is necessary to refresh the page. |
@sxzz see this comment #8721 (comment) |
@sxzz as a summary of the new strategy:
optimizeDeps: {
entries: ['src/App.vue', 'src/components/Footer.vue'],
...
We need more data to see if not crawling dynamic routes is the best default here. An alternative could be to crawl by default leading to no reloads but slower cold start and let the user opt-out of certain dynamic imports: optimizeDeps: {
scanDynamicImports: string | Regex | (string | Regex)[] | boolean By default it would be |
@patak-dev I see. Thanks for your answer. |
@sxzz the idea above is now implemented in: I think that This for out-of-the-box cold start, the best possible perf is still Let me know if you test the PR. |
Repo: https://github.com/sxzz/vite3-optimize-deps
optimizeDeps: {
devStrategy: 'dynamic-scan',
esbuildOptions: {
plugins: [
Transform({
plugins: [
VueEsbuild(),
ComponentsEsbuild({
resolvers: [ElementPlusResolver()],
}),
],
}),
],
},
},
|
Clear and concise description of the problem
In some libraries, files in different paths need to be loaded frequently. The page will be refreshed every pre-build. So it is necessary to pre-build all the files that may be used at startup.
So I think glob should be supported to easily add files that may be needed.
Suggested solution
support glob in optimizeDeps.include/exclude
Alternative
No response
Additional context
Related issue #699 #1545
Related pr #1571
Validations
The text was updated successfully, but these errors were encountered: