rsbuild.config.ts 2.9 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 { 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. '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://fb6f5e96.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. });