TreeShaking using webpack
-
Hi!
I create App with Nuxt, and usingnuxt build
for building bundle.- install Quasar into project:
vue add quasar
- add code into app
import Vue from 'vue' import '../../assets/stylus/quasar.styl' import '@quasar/extras/material-icons/material-icons.css' import {default as Quasar} from 'quasar' import { QBtn } from 'quasar' Vue.use(Quasar, { config: {}, components: { QBtn, }, directives: { }, plugins: { } })
- create bundle
npm run build
- analyze bundle and see, that all quasar components is included, however i use unly one QBtn.
How can i minimize bundle size by treeshaking?
- install Quasar into project:
-
Make sure your in your
quasar.conf.js
thatframework.components
is not set toall
. This is where you add the components you are using and quasar will do the treeshaking for you. -
@Hawkeye64
I dont usequasar-cli
. For project building i usewebpack
(ver. 4.33) itself (npm run build
)."scripts": { "build": "webpack --mode=production --devtool source-map --progress" }
TreeShaking works perfectly with simple test modules, as described in manual https://webpack.js.org/guides/tree-shaking, but wont with Quasar.
I try remove
import {default as Quasar} from 'quasar'
then bundle size decreases, and contain only QBtn.Exactly
import {default as Quasar}
pulls along all quasar components. -
coz default installs all quasar options. you can see it if you print it in the logs.
-
I would think that
import {default as Quasar} from 'quasar'
would bring in exactly everything.
Why not be specific,import {QBtn} from 'quasar'
?