rsbuild.config.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
  2. import { defineConfig, loadEnv } from '@rsbuild/core';
  3. import { pluginBabel } from '@rsbuild/plugin-babel';
  4. import { pluginLess } from '@rsbuild/plugin-less';
  5. import { pluginSass } from '@rsbuild/plugin-sass';
  6. import { pluginVue } from '@rsbuild/plugin-vue';
  7. import pkg from './package.json';
  8. import { generateExposesFromRoutes } from './plugins/generateExposesPlugin';
  9. import { zipDistPlugin } from './plugins/zipDistPlugin';
  10. import { routes } from './src/router/routes';
  11. export default defineConfig((env: any) => {
  12. const nodeEnv = env?.env || 'development';
  13. const envVars = loadEnv(nodeEnv) as any;
  14. const distDir = 'dist';
  15. const isDev = nodeEnv !== 'production';
  16. const { exposes } = generateExposesFromRoutes(routes, {
  17. onlyLeafNodes: true,
  18. });
  19. const backendHost =
  20. envVars.parsed?.VITE_API_BASE_HOST || 'http://10.15.0.138:26278';
  21. const plugins: any[] = [
  22. pluginVue({
  23. vueLoaderOptions: {
  24. compilerOptions: {
  25. expressionPlugins: ['typescript'],
  26. },
  27. },
  28. }),
  29. pluginLess({
  30. lessLoaderOptions: {
  31. lessOptions: {
  32. javascriptEnabled: true,
  33. },
  34. },
  35. }),
  36. pluginSass(),
  37. pluginBabel({
  38. include: /\.(?:vue|jsx|tsx)$/,
  39. babelLoaderOptions: {
  40. plugins: ['@vue/babel-plugin-jsx'],
  41. },
  42. }),
  43. ];
  44. if (!isDev) {
  45. plugins.push(
  46. pluginModuleFederation({
  47. name: pkg.name,
  48. 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 + "/"; }`,
  49. exposes: exposes,
  50. dts: false,
  51. shared: {
  52. vue: { singleton: true, requiredVersion: '^3.5.26' },
  53. 'vue-router': { singleton: true, requiredVersion: '^4.6.4' },
  54. pinia: { singleton: true, eager: true, requiredVersion: '^3.0.4' },
  55. 'ant-design-vue': { singleton: true, requiredVersion: '^4.2.6' },
  56. },
  57. }),
  58. // routes-info.json 改为构建后由 script/generateRoutesInfo.mjs 生成
  59. // zipDistPlugin is now called separately via npm run zip
  60. );
  61. }
  62. return {
  63. resolve: {
  64. alias: {
  65. '@': './src',
  66. '@widget': './src/widgets',
  67. 'vue-video-player': './src/compat/VideoPlayer.vue',
  68. 'vue-video-player/src/custom-theme.css':
  69. './src/compat/custom-theme.css',
  70. },
  71. },
  72. server: {
  73. port: 3000,
  74. proxy: {
  75. '/pdcApi': {
  76. target: 'http://z6e64c54.natappfree.cc',
  77. changeOrigin: true,
  78. pathRewrite: {
  79. '^/pdcApi': '',
  80. },
  81. },
  82. },
  83. },
  84. dev: {},
  85. output: {
  86. assetPrefix: 'auto',
  87. distPath: { root: distDir },
  88. },
  89. plugins,
  90. };
  91. });