| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import { defineConfig,loadEnv } from '@rsbuild/core';
- import { pluginVue } from '@rsbuild/plugin-vue';
- import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
- import { generateRoutesInfoPlugin } from './plugins/generateRoutesInfoPlugin';
- import { generateExposesFromRoutes } from './plugins/generateExposesPlugin';
- import { zipDistPlugin } from './plugins/zipDistPlugin';
- import { routes } from './src/router/routes';
- import pkg from './package.json';
- // Docs: https://rsbuild.rs/config/
- export default defineConfig((env:any) => {
- // 生成 Module Federation exposes 配置(只展示叶子节点)
- const { exposes } = generateExposesFromRoutes(routes, { onlyLeafNodes: true });
- const nodeEnv = env?.env || 'development';
- // 加载环境变量
- const envVars = loadEnv(nodeEnv) as any;
- const distDir = nodeEnv === 'production' ? pkg.name : 'dist';
- return {
- source: {
- // 配置路径别名
- alias: {
- '@': './src',
- },
- },
- server: {
- port: 3000,
- },
- dev: {
- assetPrefix: 'http://localhost:3000',
- writeToDisk: true,
- },
- output: {
- assetPrefix: 'auto',
- injectStyles: true, // ← 新增:将 CSS 内联到 JS 中
- // 🚀 使用 VITE_API_BASE_NAME 作为输出目录名称
- distPath: {
- root: distDir,
- },
- },
- plugins: [
- pluginVue(),
- pluginModuleFederation({
- name: pkg.name,
- getPublicPath: `function() { try { if (window.__MF_REMOTE_BASE_URL__ && window.__MF_REMOTE_BASE_URL__["${pkg.name}"]) { return window.__MF_REMOTE_BASE_URL__["${pkg.name}"]; } console.warn("__MF_REMOTE_BASE_URL__ not found, using fallback"); } catch (e) { console.warn("Failed to get publicPath from global variable:", e); } return window.location.origin + "/"; }`,
- // 🚀 根据路由自动生成 exposes 配置(只展示叶子节点)
- exposes: exposes,
- // ⭐ 完全禁用 DTS 插件
- dts: false,
- shared: {
- vue: {
- singleton: true,
- requiredVersion: '^3.5.26',
- },
- 'vue-router': {
- singleton: true,
- requiredVersion: '^4.6.4',
- },
- pinia: {
- singleton: true,
- requiredVersion: '^3.0.4',
- },
- 'ant-design-vue': {
- singleton: true,
- requiredVersion: '^4.2.6',
- },
- },
- }),
- // 自动生成 routes-info.json 插件
- generateRoutesInfoPlugin(),
- // 📦 最后执行:打包成 zip 并删除原始目录
- zipDistPlugin(distDir),
- ],
- };
- });
|