rsbuild.config.ts 3.0 KB

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