/*
 * @Author: zengzhe
 * @Date: 2024-12-27 11:54:24
 * @LastEditors: zengzhe
 * @LastEditTime: 2024-12-27 17:00:00
 * @Description:
 */
import { pluginBabel } from '@rsbuild/plugin-babel'
import { pluginVue } from '@rsbuild/plugin-vue'
import { pluginVueJsx } from '@rsbuild/plugin-vue-jsx'
import { pluginLess } from '@rsbuild/plugin-less'
import { pluginTypeCheck } from '@rsbuild/plugin-type-check'
import { pluginSvgSpriteLoader } from 'rsbuild-plugin-svg-sprite-loader'
import AutoImport from 'unplugin-auto-import/rspack'
import Components from 'unplugin-vue-components/rspack'
import { TDesignResolver } from 'unplugin-vue-components/resolvers'
import { join } from 'path'
export const createPlugins = () => {
  return {
    plugins: [
      pluginBabel({
        include: /\.(?:jsx|tsx)$/
      }),
      pluginVue(),
      pluginVueJsx(),
      pluginLess(),
      pluginTypeCheck(),
      pluginSvgSpriteLoader({
        path: join(__dirname, '../src/assets/icons'),
        symbolId: 'icon-[name]'
      })
    ],
    tools: {
      rspack: {
        plugins: [
          AutoImport({
            imports: ['vue', 'vue-router'],
            resolvers: [
              TDesignResolver({
                library: 'vue-next'
              })
            ],
            dts: 'src/autoImport.d.ts'
          }),
          Components({
            // allow auto load markdown components under `./src/components/`
            extensions: ['vue', 'md'],
            // allow auto import and register components used in markdown
            include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
            resolvers: [
              TDesignResolver({
                library: 'vue-next'
              })
            ],
            dts: 'src/components.d.ts'
          })
        ]
      }
    }
  }
}
