-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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. |
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)
![image](https://user-images.githubusercontent.com/5017521/163251784-53856286-1a50-41e6-babc-3ba8a50850dc.png)
Validations
The text was updated successfully, but these errors were encountered: