rsbuild.config.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { defineConfig, loadEnv } from '@rsbuild/core'
  2. import { pluginVue } from '@rsbuild/plugin-vue'
  3. import { pluginSass } from '@rsbuild/plugin-sass'
  4. import AutoImport from 'unplugin-auto-import/rspack'
  5. import Components from 'unplugin-vue-components/rspack'
  6. import { VantResolver } from '@vant/auto-import-resolver'
  7. import postcssPluginPxToViewport from 'postcss-px-to-viewport-8-plugin'
  8. import path from 'path'
  9. import { fileURLToPath } from 'url'
  10. import { dirname } from 'path'
  11. const __filename = fileURLToPath(import.meta.url) // 获取当前文件绝对路径
  12. const __dirname = dirname(__filename) // 获取当前目录路径
  13. const { publicVars } = loadEnv({ prefixes: ['APP_'] })
  14. export default defineConfig(() => {
  15. return {
  16. plugins: [
  17. pluginVue(),
  18. pluginSass({
  19. sassLoaderOptions: {
  20. additionalData: `@use '@/assets/style/variables.scss' as *;`
  21. }
  22. })
  23. ],
  24. source: {
  25. define: publicVars,
  26. entry: {
  27. index: './src/main.js'
  28. },
  29. alias: {
  30. '@': path.resolve(__dirname, './src')
  31. }
  32. },
  33. server: {
  34. host: '0.0.0.0',
  35. open: true,
  36. proxy: {
  37. [process.env.APP_BASE_API]: {
  38. target: process.env.APP_BASE_SERVER_URL,
  39. changeOrigin: true
  40. }
  41. }
  42. },
  43. tools: {
  44. postcss: {
  45. plugins: [
  46. postcssPluginPxToViewport({
  47. unitToConvert: 'px',
  48. viewportWidth: 375,
  49. unitPrecision: 6,
  50. viewportUnit: 'vw',
  51. fontViewportUnit: 'vw',
  52. propList: ['*'],
  53. selectorBlackList: ['van-'],
  54. minPixelValue: 1,
  55. mediaQuery: false,
  56. replace: true,
  57. exclude: [/node_modules/],
  58. include: [],
  59. landscape: false
  60. })
  61. ]
  62. },
  63. htmlPlugin: {
  64. template: './index.html'
  65. },
  66. rspack: {
  67. plugins: [
  68. AutoImport({
  69. resolvers: [VantResolver()]
  70. }),
  71. Components({
  72. resolvers: [VantResolver()]
  73. })
  74. ]
  75. }
  76. },
  77. output: {
  78. cleanDistPath: true,
  79. legalComments: 'none',
  80. overrideBrowserslist: ['iOS >= 9', 'Android >= 4.4', 'last 2 versions', '> 0.2%', 'not dead']
  81. },
  82. performance: {
  83. removeConsole: true
  84. }
  85. }
  86. })