/*
 * @Author: zengzhe
 * @Date: 2024-12-27 11:54:24
 * @LastEditors: xiejiang
 * @LastEditTime: 2025-03-04 10:57:39
 * @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 { pluginModuleFederation } from '@module-federation/rsbuild-plugin'
import { TDesignResolver } from 'unplugin-vue-components/resolvers'
import { join } from 'path'
export const createPlugins = () => {
  return {
    plugins: [
      pluginBabel({
        include: /\.(?:jsx|tsx)$/
      }),
      pluginModuleFederation({
        name: 'master',
        remotes: {
          remote: 'remote@http://localhost:5174/mf-manifest.json'
        },
        shared: {
          lodash: {
            singleton: true,
            eager: true
          }
        }
      }),
      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'
          })
        ]
      }
    }
    // moduleFederation: {
    //   options: {
    //     name: 'web-',
    //     remotes: {
    //       remote: 'remote@http://localhost:5174/remoteEntry.js'
    //     },
    //     shared: {
    //       vue: {
    //         eager: true,
    //         singleton: true
    //       }
    //     }
    //   }
    // }
  }
}
