Use sideEffects flag in package.json to enable tree shaking in other bundlers
See original GitHub issueIs your feature request related to a problem? Please describe.
Right now quasar relies on its CLI to perform tree shaking on unused components (from a custom webpack hook?). Other bundlers (vite, esbuild, snowpack etc.) have to load everything from the compiled bundle dist/quasar.esm.prod.js
which results in larger bundles than necessary.
Describe the solution you’d like
- Use the
sideEffects: false
flag (orsideEffects: [files that do have side effects]
) in the distributedpackage.json
- Export another
Quasar
object insrc/index.all.js
that does not referencecomponents
:
export const QuasarBasic = {
version: __QUASAR_VERSION__,
install (app, opts, ssrContext) {
installQuasar(
app,
{ ...opts }, // No reference to components and directives
ssrContext
)
},
lang,
iconSet
}
- Advanced users will need to alias
quasar
toquasar/src/index.all
and add the necessary build configs:
resolve: {
alias: {
quasar: 'quasar/src/index.all',
}
},
plugins: [
new DefinePlugin({
__QUASAR_VERSION__: JSON.stringify('Custom v2'),
__QUASAR_SSR__: JSON.stringify(false),
__QUASAR_SSR_CLIENT__: JSON.stringify(false),
__QUASAR_SSR_SERVER__: JSON.stringify(false),
__QUASAR_SSR_PWA__: JSON.stringify(false),
}),
]
Doing this results in noticeably smaller bundles for me
Before:
After:
Alternative to step 3:
Instead of requiring users to set up a custom build config, separate dist/quasar.esm.prod.js
into their original modules so that tree shaking can be performed.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:9 (5 by maintainers)
Top Results From Across the Web
false flag to package.json to allow tree shaking · Issue #16059 ...
Consider adding "sideEffects": false to package.json so that bundlers like webpack are able to tree shake three.js.
Read more >Tree Shaking - webpack
A "side effect" is defined as code that performs a special behavior when imported, other than exposing one or more exports. An example...
Read more >Everything you never wanted to know about side effects
Most modern bundlers implement tree-shaking, where unused code is removed from the final bundles, as it's not necessary. This becomes important ...
Read more >Reduce JavaScript payloads with tree shaking - web.dev
While both bundles shrank, it's really the main bundle that benefits most. By shaking off the unused parts of the utils module, the...
Read more >Tree-Shaking: A Reference Guide - Smashing Magazine
Simply put, tree-shaking means removing unreachable code (also known as dead code) from a bundle. As Webpack version 3's documentation states: “ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks Razvan,
It would be nice to have better support for e.g. unplugin-vue-components, but if that breaks existing setups that’s obviously a no-go. Maybe it can be added to the road map for a a future version.
The vite plugin has its limitations at the moment (no SSR) so unfortunately that’s not a solution for everyone that wants to use their own vite configuration. (which understandingly has a lower priority than official supported methods such as the CLI). I’m working on a solution but it requires some workarounds such as in the previous post.
Hi,
Like I said, this is a non-issue. Tree-shaking is handled automatically, unless you are doing something that we don’t officially support anyway (like totally custom build system etc).
If using Quasar CLI, our Vite plugin or our Vue CLI plugin and it does not works, please post a repo with minimal reproduction, or directly attach a .zip file here.
Can’t change to sideEffects because it will break most people’s setups.