-
-
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
Dependency Pre-Bundling does not bundle styles #7719
Comments
After some tinkering, I was able to achieve the desired outcome here using the following configuration. Took a while to figure out since optimizeDeps: {
extensions: [".scss", ".sass"],
esbuildOptions: {
plugins: [
(await import("esbuild-sass-plugin")).sassPlugin({
type: "style",
// Setting `logger.warn` to no-op is a workaround for
// https://github.com/sass/sass/issues/3065#issuecomment-868302160.
// Since `optimizeDeps` is only processing third party dependencies and only during dev,
// we don't care about *any* deprecation warnings. The `quietDeps` SASS option doesn't work.
logger: { warn() {} },
}),
],
},
}, Would there ever be consideration to making this functionality baseline? Since build mode supports popular CSS preprocessors, I think it would make sense to also support them here in serve. I realize that different "glue" would have to be built to plug them into esbuild rather than rollup (as to not add third-party dependencies like I did in my config here). Is this something that would be worth my while to start a PR for? |
The |
@ascott18 thanks for the workaround. One more precision vuetify 2 is limited to sass v1.32, see discussion vuetifyjs/vuetify#13694 (comment) To satisfy this dependencie, need to have |
Is there any news on this? @ascott18 When i add your code to my vite.config.ts i'm getting the following error:
What am i doing wrong? |
@ricardovanlaarhoven I assume an object is passed to your defineConfig instead of an async function. export default defineConifg(async () => ({ |
@ricardovanlaarhoven It's the same for me and on huge projects is very time consuming. |
I've had the same issue. It's nodes and you need to edit your package.json to set type
It fix all my problem and vite/vue(2.7)/vuetify(2) perform well and fast at each request even on cold start. |
vite.config
added to the package.json:
and result is still the same, with often a reload of the complete site. |
@ricardovanlaarhoven Now Vue VLS 1.8.8 reports incompatible type for esbuild-sass-plugin inside the vite.config.ts Vue: Type import("/path/to/project/node_modules/esbuild/lib/main").Plugin is not assignable to type import("/path/to/project/node_modules/vite/node_modules/esbuild/lib/main").Plugin Types of property optimizeDeps: {
extensions: [".scss", ".sass"],
esbuildOptions: {
plugins: [
sassPlugin({ //
type: "style",
logger: { warn() {} },
}),
],
},
} The current workaround I found: optimizeDeps: {
extensions: [".scss", ".sass"],
esbuildOptions: {
plugins: [
sassPlugin({ //
type: "style",
logger: { warn() {} },
}),
],
} as DepOptimizationConfig['esbuildOptions']
} |
@ascott18 It's work but it's breaks the next settings:
|
Vuetify does only seem to have this problem when you use the config file option in the vite config.
This option is needed when doing component specific sass variable overrides. (which i need..) Also
The optimize deps doesn't seem to really speed thing up. It looks like its 7s where it was 10s pending, in a failry fresh project |
With vuetify this specific time issue happens when you use vuetifys sass variables file AND use component specific sass variables. So once you add this to the vite config:
and change I guess because every sass file vuetify imports needs to be recompiled to add the settings.scss above it. I've had contact with the founder from vuetify, but they don't know how to resolve it and if they are doing something the wrong way, they like to know it. Hopefully anyone knows how to handle this, in any way. |
I remove the option styles: {
configFile: "src/styles/settings.scss",
}, and i observe the web load near instant, my guess is include this scss file make Vite have to run sass compile all the sass file of vuetify thus make loading feel like century, another reason to have a nonstyle component like PrimeVue so we can swap to use more performance css system like tailwindcss or unocss |
This option is necessary for component-specific SASS variable overrides. Webpack does not have this issue. I tried adding all components and SASS from Vuetify to the Vite server warmup configuration (https://vitejs.dev/config/server-options.html#server-warmup), but that doesn't seem to work either. I'm wondering if this is a Vite issue or a Vuetify issue. I've spoken to @johnleider from Vuetify, and they are unsure what to do differently with the Vuetify loader. It would be great if someone from Vite could let us know if Vuetify needs to make any changes or if this is a Vite issue that we need to wait for a fix on. And perhaps the label "has workaround" should be removed, or could anyone tell me what the workaround is, i've tried everything. |
OP's reproduction is quite old (vite 2.9 and vuetify 2.4.8), so it would be great if someone can prepare a reproduction based on latest version of dependencies. Also orthogonal to this pre-bundling issue (which is about reducing the number of css requests from browser), there is an effort to improve sass processing in general by using latest feature of sass (and sass-embedded) package. It's not merged yet but hopefully this will be available soon (see performance comparison in the PR #17728 (comment)). |
Hello @hi-ogawa, I forked the repro here and tried to upgrade it without changing it too much. From what I see we still have a request per For the example I only used a few components from vuetify, but on a real project it can quickly go up |
I've created a new vuetify project, added some sass variables and this is the result: https://github.com/ricardovanlaarhoven/vuetify-vite-sass-speed-issues Vuetify with vite speed issuerun Keep in mind that this is a really really small project, just the starter of vuetify with 3 simple components on the test page. You could add some more pages and components to see the difference in speed. For exmaple adding VDataTable adds makes it go up to 11 seconds |
Thanks for providing a reproduction. I had a look and it appears that there are a few intertwined issues, so try to comment on them separately. First of all, pre-bundling scss/sass files using import { defineConfig } from 'vite'
import { sassPlugin } from "esbuild-sass-plugin";
export default defineConfig({
optimizeDeps: {
extensions: [".scss", ".sass"],
esbuildOptions: {
plugins: [
sassPlugin({
// default `type: "css"` doesn't work since it emits separate css files
// and removes css import from js files.
// https://esbuild.github.io/content-types/#css-from-js
// https://github.com/glromeo/esbuild-sass-plugin#type-style
type: "style",
}),
]
}
}
}) The reason why this approach is not working specifically for vuetify is that because it relies on vite plugin to rewrite original 2nd issue is that current Vite's default sass setup is not best for speed performance. As I mentioned in #7719 (comment), it's planned to integrate improved sass compilation API inside Vite. Before this feature is available, there are already two ways you might be able to improve performance by using 3rd issue is that you are likely experiencing frequent full-reload on navigation due to deps optimization triggered when discovering new dependencies in new pages. This is a different issue on its own and it happens when Vite's default heuristics is not able to discover dependencies used in user source code. For example, you can find a similar issue and potential solutions discussed on nuxt/nuxt#26783 (I also remember other Vite frameworks like Sveltekit, Remix etc... experienced a similar issue). From what I can see, this issue having "has workaround" status seems right. I think it's still possible to improve vuetify (+ custom sass configFile) experience by figuring out 2nd and 3rd issues. |
Thnx @hi-ogawa I've tested it in my real-life project.
it takes 9 seconds When doing it takes 9 seconds But i do still use the optimizeDeps and preprocessorMaxWorkers. I'm grateful for the impressive time-cut. a few points/questions:
|
Figuring this out requires more domain knowledge of framework/library side and app specifics. I'm not familiar with Vue in general, so probably it's better to seek a help elsewhere.
When using
Hopefully the improvement will be available in v5.4. One PR is merged #17728 and next one #17754 is also hopefully merged for 5.4. |
Tried it a couple of times, results in about 12 seconds. Which is also a huge time decrease. But less then the preprocessorMaxWorkers: true option. |
@ricardovanlaarhoven can you update your repro to use latest vite 5.4.0-beta.0 and switch sass api to modern? I guess there is some sass cache, starting dev server and navigating takes only 3/4 seconds first time, next dev server restarts is faster: define: { 'process.env': {} },
optimizeDeps: { exclude: ["vuetify"] },
css: {
preprocessorOptions: {
sass: {
api: 'modern'
},
},
preprocessorMaxWorkers: true
}, EDIT: removing |
In my real life project, going to a second page just like my comment before #7719 (comment)
perhaps it has something to do with caching building up?? The start of the project itself seems better to, i just didnt measure it before and don't mind the startup being a bit slow, thats just once or twice a day. |
I'm curious if this PR addresses your the issues mentioned here: #14467 I filed it over a year ago and there are some conflicts that need to be resolved, but I'm happy to revive it if it seems like other people would benefit. I wasn't very successful in getting any of the project owners to respond on the PR though and eventually just gave up on it. The PR I believe only handles .css files directly and not sass, but it could presumably be extended if needed. |
I'm no vite expert, but i think when css/sass/scss is getting pre compiled and not optimized on the fly. I would benefit from it. What i saw is that on starting the dev server, there are a lot of css files loaded, and then when they are completed, the next batch of css files is loaded. And those loads are showing in my cli's log as optimize deps as i remember correctly. for me it helped by raising this issue on vite's discord. Perhaps that could also help for your PR. |
Describe the bug
Dependency pre-bundling does not bundle CSS (or other css langs; in this case, SASS) imports within dependencies.
The result of this is that in serve mode when using component frameworks like Vuetify with per-component imports, each individual CSS file for each individual component is loaded with an independent HTTP request, even though all the scripts for these components are bundled into a single file.
This results in 100+ extra HTTP requests in serve mode.
Reproduction
https://github.com/ascott18/repro-vite-css-prebundling
System Info
Used Package Manager
npm
Logs
(including image because I can't capture Chrome network tools output in a reasonable text format)
Validations
The text was updated successfully, but these errors were encountered: