-
-
Notifications
You must be signed in to change notification settings - Fork 69
Duplicated CSS rules in production #46
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
Comments
I have the same issue, do you find a solution ? |
Actually, the styles don't get added twice by the SSR plugin, but you get the styles delivered with the server side-rendered page and as soon as you mount the app on the client side on top of the pre-rendered dom, Vue adds the styles of the components again. |
The solution is really simple! The devs of vue-style-loader thought about this issue and already implemented a solution. To fix the duplicated style issue we simply need to configure the css loader to use the
To do this we simply need to add the loader config to our module.exports = {
//...
css: {
loaderOptions: {
css: {
ssrId: true
}
}
}
//...
} Hope it helps 😃 |
Hi So just to confirm when using SSR the csss file is created as expected and the same content is also added to <style ssr-id>? The ssrId:true does not stop this from happening. |
+1 |
I tried but does not work. It still renders duplicated CSS |
I have the same problem. vue-cli 3 + vue-cli-ssr-plugin (default config) + vue-apollo |
Those instructions that @p1n5u provided are perhaps a little bit misleading. vue-style-loader is not a supported loader for loaderOptions. See: https://cli.vuejs.org/config/#css-loaderoptions There may be a way to get it to work like that, but I couldn't get it to work. If you want to modify vue-style-loader options you can do so like this:
I was able to get the ssrIds working by doing this. If you are using SCSS or similar things, you may have to do this multiple times replacing 'css' with the appropriate language. You can see someone modifying the vue-style-loader config like this here: vuejs/vue-style-loader#40 |
@Sporradik I followed with SCSS this but I am getting an error.
Then if I initialize the options as shown on vuejs/vue-style-loader#40 I get:
And if I specify a loader my build fails. .use('vue-style-loader')
.loader('vue-style-loader')
...
|
Same issue with @enriqg9 :( I also try to add the cf https://github.com/vuejs/vue-style-loader#options |
you guys may want to take a look at this #158 |
@usedjimmy thanks, that is a separate issue, already implemented that solution to avoid duplicate JS files.
|
Same issue with me. For some strange reason, when I mixed some 3'rd party lib's this stopped happening in one of my projects. |
Just to follow up... same for me since a long time. I don't get why by default we cannot have CSS extracted into separate files, but also even if I succeed doing that with some patchy settings, why they are rendered twice as you described. It makes a pain to manage and to serve a proper website to visitors 😢 ... |
@enriqg9 We don't use SCSS, so I'm not sure if I can be of much support, but I have some ideas of what you could try: I would recommend taking a look at your built webpack config using Is it just throwing that error for scss or for css as well? Is it possible that one of the "types" is not relevant in your case, so that is causing an error? If so, you could try removing it. You could try only modifying options if they exist. If you can just prevent the error with an undefined check, then maybe it could work. You can put console.logs in your chainWebpack function and they will log in the terminal where you run vue-cli-service start. It's a bit hard to read, but you could use this to figure out which type or rule is causing the error. Webpack is very confusing to me, especially with vue-cli so I am sorry that I can't be of more help. |
When using this CLI plugin, there are duplicated CSS rules when using CSS modules and the "composes" feature. This seems to be caused by the critical CSS that's inlined into the
<head>
and is both happening in development and production (main issue).I've created the following test repo (https://github.com/mrksbnch/vue-ssr-css-issue) that I created using
vue create
(Vue router as the only feature) andvue add @akryum/vue-cli-plugin-ssr
. Afterwards, I added a test.css file in the folderassets
and composed (<style module>
) two style declarations from that file inHome.vue
andHelloWorld.vue
.You can see the duplicated rules after running
npm run ssr:serve
ornpm run ssr:build
andnpm run ssr:start
in the dev tools:Both CSS rules are inlined on the server side (
<style data-vue-ssr-id>
):This is just a simple test repo with only one CSS rule. In a proper app this will cause a lot (!) of duplicated CSS rules and increase the file size by quite a bit. I've tested it with a simple app and I noticed some rules being duplicated 5 or 6 times.
The text was updated successfully, but these errors were encountered: