question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuxt JS - Bootstrap Vue is adding unused CSS in production code even after tree shaking

See original GitHub issue

Describe the bug

I am use bootsrap vue in my nuxt js project and I always import the components that I have used on my project in order to ensure that no extra CSS gets added in my production code. But even after doing that when I created the production build of my site and went to view source I can still see many bootstrap css which are not being used anywhere in the project and also not added in the componentPlugins or in the directivePlugins.

Steps to reproduce the bug

I created my nuxt project using the CLI and selected bootstrap vue as the design system in the CLI so I have not installed them manually. In my package.json I have

"bootstrap": "^4.1.3",
"bootstrap-vue": "^2.0.0",

In my nuxt.config.js I have

modules: [
    // Doc: https://bootstrap-vue.js.org
    'bootstrap-vue/nuxt'
  ],

and here is my bodule settings:

bootstrapVue: {
    componentPlugins: [
      'NavbarPlugin',
      'LayoutPlugin',
      'ButtonPlugin',
      'FormPlugin',
      'ModalPlugin',
      'TabsPlugin'
    ],
    directivePlugins: ['VBTooltipPlugin']
  }

But in my view source I have css for .toast, for table and so much more.

Screenshots: Toast: https://i.imgur.com/wWwru8s.png Table: https://i.imgur.com/GIdGD1F.png and there is even more like these which I have no idea why they are there as technically only the components I am using, that CSS should be in the build output. Isn’t it?

Expected behavior

After building the project, only the component/plugins I am using, those CSS should be in the build.

Versions

Libraries:

  • BootstrapVue: 2.0.4
  • Bootstrap: 4.1.3
  • Nuxt: 2.10.1

Environment:

  • Device: Desktop (happening everywhere)
  • OS: Win 10
  • Browser: Chrome
  • Version: 77

Looking forward to your response.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vesper8commented, Jun 22, 2020

I am having this issue as well, it’s unrelated to tree-shaking and I understand tree-shaking only applies to JS, however I would have expected PurgeCSS to be removing the unused css but currently it appears the entire bootstrap 4.5 CSS file is pasted it into the source code when using universal mode with Nuxt. I will try disabling the CSS as suggested above but I wish the nuxt module made it easier to prevent the entire css file to just be dumped like it currently is

1reaction
isaumyacommented, Oct 25, 2019

@jackmu95 Thanks for your reply, but when what’s the point of Tree shaking with Nuxt.js? I do not understand. Maybe I am misunderstanding something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue and Webpack tree shaking, sideEffects and CSS
Since we have a quite a few Vue components this is leading to a lot of unused CSS being added to the page....
Read more >
Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Tree-Shaking Problems with Component Libraries - Medium
A way round this is to wrap your components in IIFEs. By wrapping them in this scope, Terser can know that, even with...
Read more >
How to improve the PageSpeed score of your Nuxt.js website ...
Thanks to HTTP/2, loading multiple smaller bundles is faster than loading one file. Try to add maxSize to your nuxt.config.js to force webpack ......
Read more >
Reduce Bundle Size of Your Single Page Application
Strip Out Unused CSS ... When you are building a website, you might decide to use a framework like Bootstrap but you will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found