07akioni / naive-ui-nuxt-demo

52 stars 23 forks source link

autoImport support for nuxt3 #15

Open jdgjxxchy opened 1 year ago

jdgjxxchy commented 1 year ago

I have tried several ways to add autoImport support for nuxt3 and all failed. Will it be possible to add autoImport support for nuxt3 in futrue? I'm tired in writing so many import {} from 'naive-ui'

image

Did not work

mrcointreau commented 1 year ago

In my tsconfig.json I had

  "compilerOptions": {
    "types": ["naive-ui/volar"]
  }

After removing it auto import works like a charm

AlisaAkiron commented 1 year ago

Try unplugin-vue-components

nuxt.config.ts

import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'

export default defineNuxtConfig({
  build: {
    transpile:
      process.env.NODE_ENV === 'production'
        ? [
            'naive-ui',
            'vueuc',
            '@css-render/vue3-ssr',
            '@juggle/resize-observer',
          ]
        : ['@juggle/resize-observer'],
  },
  vite: {
    plugins: [
      Components({
        resolvers: [NaiveUiResolver()],
      }),
    ],
    optimizeDeps: {
      include:
        process.env.NODE_ENV === 'development'
          ? ['naive-ui', 'vueuc', 'date-fns-tz/esm/formatInTimeZone']
          : [],
    },
  },
})