No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Disabling import strategy

    Useful Tips (NEW)
    1
    3
    760
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • beets
      beets last edited by beets

      Just thought I’d share this tip. Quasar/app v2+ by default uses importStrategy: 'auto' but doesn’t provide a way to disable it and manually specify what components to include like we used to be able to do pre v2.

      Today, I was checking out my bundle, and noticed a component I didn’t use was still in the bundle. Turns out quasar cli is searching with a regex for strings like q-select, q-btn, etc and including them if found. I had a comment such as // Use this instead of q-select and that caused q-select to be bundled even though I didn’t use it at all!

      Here’s how I disabled this behavior:

      // quasar.conf.js
      
      module.exports = function (ctx) {
        return {
        
          // ...
          
          framework: {
            
            // ...
            
            importStrategy: 'auto', // keep this as auto
              
            components: [ // manually specify components
              'QLayout',
              'QHeader',
              'QFooter',
              'QDrawer',
              'QPageContainer',
              'QPage',
              'QInnerLoading',
            ],
            directives: [ // manually specify directives
              'ClosePopup',
              'Ripple',
            ],
            plugins: [
            ],
          },
          
          // ...
          
          build: {
          
            // ...
      
            extendWebpack(cfg, { isServer, isClient }) {
              if(isClient) {
                // delete the auto import loader
                for(const rule of cfg.module.rules) {
                  if(rule.use.length && rule.use[0].loader.endsWith('loader.auto-import-client.js')) {
                    rule.use.splice(0, 1)
                    break
                  }
                }
              }
            },
          },
      
          // ...
      
        }
      }
      

      I hope it helps someone who is trying to reduce their bundle size.

      1 Reply Last reply Reply Quote 1
      • beets
        beets last edited by beets

        As another bundle-size tip, I also decided to only put the most used components / directives in quasar.conf.js, and import less used quasar components / directives directly into my components. For example:

        // MyComponent.vue
        
        import { QScrollObserver, QResizeObserver, TouchPan } from 'quasar'
        
        export default {
        
          // ...
        
          directives: {
            TouchPan,
          },
          components: {
            QScrollObserver, 
            QResizeObserver,
          }
        }
        

        Then in quasar.conf.js, I disabled the vendor chunk:

        vendor: {
          disable: true,
        }
        

        This resulted in many of my pages having about 25% less Javascript.

        1 Reply Last reply Reply Quote 1
        • beets
          beets last edited by

          And for visual people, here’s a before / after of webpack analyze:

          webpack

          1 Reply Last reply Reply Quote 2
          • First post
            Last post