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.

Tree shaking not working

See original GitHub issue

I have a minimal bootstrap-vue application. I basically just used the Vue CLI to create a new project, and added bootstrap-vue as follows:

import BootstrapVue from "bootstrap-vue";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";
Vue.use(BootstrapVue);

I also added font-awesome but that doesn’t appear to take up that much space…

When I perform a build using the Vue UI the build size seems enormous:

File                                   Size              Gzipped

  dist/js/chunk-vendors.efb23010.js      422.49 KiB        131.86 KiB
  dist/js/app.7c82e299.js                7.65 KiB          2.82 KiB
  dist/js/about.3a94e576.js              0.44 KiB          0.31 KiB
  dist/css/chunk-vendors.f1000a76.css    171.00 KiB        24.30 KiB
  dist/css/app.03795e02.css              0.53 KiB          0.31 KiB

I found another thread mentioning build size and it mentioned something about “esm” builds and I tried using a different import, but barely any difference:

//import BootstrapVue from "bootstrap-vue/dist/bootstrap-vue.esm.min";

Any suggestions? Thanks.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
tmorehousecommented, Feb 18, 2019

Try this:

import Vue from 'vue'

import Badge from 'bootstrap-vue/es/components/badge'
import Breadcrumb from 'bootstrap-vue/es/components/breadcrumb'
import Button from 'bootstrap-vue/es/components/button'
// ...
import Tabs from 'bootstrap-vue/es/components/tabs'

Vue.use(Badge)
Vue.use(Breadcrumb)
Vue.use(Button)
// ...
Vue.use(Tabs)

This should treeshake better.

Also note that Webpack 4 typically only treeshakes in production mode (https://webpack.js.org/guides/tree-shaking/#conclusion)

1reaction
pimliecommented, Feb 18, 2019

@tmorehouse Thank you, you are my hero of the day! 💋

Now its only 163KB image

(I create the webpack analyzer reports with nuxt build -a, quick and easy and in production mode by default)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack Tree Shaking not working when importing from a file ...
If I remove the moment import from module.js tree shaking works fine and i only see square in my bundle. Is this how...
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 not working in v3 beta · Issue #8713 · vitejs/vite
I upgraded Vite to 3.0.0-beta.0 to resolve this issue, which prevents me from using v2.9 right now. However, tree-shaking fails for every ...
Read more >
Tree-Shaking: A Reference Guide - Smashing Magazine
There's one specific issue that is unfortunately rather common and can be devastating for tree-shaking. In short, it happens when you're working ......
Read more >
How I fixed webpack tree shaking in 3 easy steps
Tree shaking is an important step in Webpack bundling to get rid of unused stuff. This should help describe how to easily get...
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