vue.jsvitequasar-framework

is there any way to use unplugin-vue-components with quasar-cli vite version?


I had used this pakage with the vite plugin of quasar but I need to migrate to its vite cli and I tried to do what is suggested like this this:

//quasar.conf.js
vitePlugins: [
    [
      "unplugin-auto-import/vite",
      {
        // targets to transform
        include: [
          /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
          /\.vue$/,
          /\.vue\?vue/, // .vue
          /\.md$/, // .md
        ],
        imports: [
          // presets
          "vue",
          "vue-router",
          "@vueuse/core",
        ],
        dirs: [
          // './hooks',
          "src/composables", // only root modules
          "src/components/**", // all nested modules
        ],
      },
      "unplugin-vue-components/vite",
      {
        // relative paths to the directory to search for components.
        dirs: ["src/components"],
      },
    ],
  ],

but components not working and there are import warns and errors even though components.d.ts is generated and Imports inside those files are correct.


Solution

  • With ESM imports it looks like this (and also globs to match a modular architecture and moving the generated dts to the src folder):

    import Components from 'unplugin-vue-components/vite'
    //...
          vitePlugins: [
            //...
            Components({ 
              // https://github.com/unplugin/unplugin-vue-components#usage
              globs: [
                // To debug: DEBUG=unplugin-vue-components:glob pnpm dev
                `src/components/**/*.vue`,
                `src/modules/**/components/**/*.vue`,
              ],
              dts: `src/components.d.ts`,
            }),