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.

Use sideEffects flag in package.json to enable tree shaking in other bundlers

See original GitHub issue

Is 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.

before2

Describe the solution you’d like

  1. Use the sideEffects: false flag (or sideEffects: [files that do have side effects]) in the distributed package.json
  2. Export another Quasar object in src/index.all.js that does not reference components:
export const QuasarBasic = {
  version: __QUASAR_VERSION__,
  install (app, opts, ssrContext) {
    installQuasar(
      app,
      { ...opts }, // No reference to components and directives
      ssrContext
    )
  },
  lang,
  iconSet
}
  1. Advanced users will need to alias quasar to quasar/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: before

After: 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:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stefanvanherwijnencommented, Apr 7, 2022

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.

0reactions
rstoenescucommented, Apr 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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