vite.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import path from 'path'
  2. import fs from 'fs'
  3. import react from '@vitejs/plugin-react'
  4. import commonjs from 'vite-plugin-commonjs'
  5. import { defineConfig } from 'vite'
  6. import ViteRequireContext from '@originjs/vite-plugin-require-context'
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. plugins: [
  10. ViteRequireContext(),
  11. commonjs(),
  12. react({
  13. babel: {
  14. plugins: [
  15. // js中写jsx的语法支持
  16. '@babel/plugin-transform-react-jsx',
  17. // 使用commonjs的语法导入导出支持
  18. '@babel/plugin-transform-modules-commonjs',
  19. ],
  20. },
  21. }),
  22. ],
  23. esbuild: {
  24. loader: 'jsx',
  25. include: /src\/.*\.jsx?$/,
  26. exclude: []
  27. },
  28. optimizeDeps: {
  29. esbuildOptions: {
  30. loader: { '.js': 'jsx' },
  31. plugins: [
  32. {
  33. name: 'load-js-files-as-jsx',
  34. setup (build) {
  35. build.onLoad({ filter: /src\/.*\.js$/ }, async (args) => ({
  36. loader: 'jsx',
  37. contents: await fs.readFile(args.path, () => {})
  38. }))
  39. }
  40. }
  41. ]
  42. }
  43. },
  44. extensions: ['.js', '.jsx', '.json', '.png'],
  45. resolve: {
  46. alias: {
  47. // https://github.com/alloc/vite-react-jsx/issues/4
  48. 'react/jsx-runtime': 'react/cjs/react-jsx-runtime.production.min.js',
  49. 'components': path.resolve(__dirname, './src/components'),
  50. 'pages': path.resolve(__dirname, './src/pages'),
  51. 'containers': path.resolve(__dirname, './src/containers'),
  52. 'store': path.resolve(__dirname, './src/store'),
  53. 'assets': path.resolve(__dirname, './src/assets'),
  54. 'tools': path.resolve(__dirname, './src/tools'),
  55. '~antd': path.resolve(__dirname, './node_modules/antd'),
  56. 'routers': path.resolve(__dirname, './src/routers'),
  57. },
  58. },
  59. css:{
  60. // 是对css模块化的默认行为进行覆盖
  61. modules:{
  62. // 是否开启模块化
  63. scopeBehaviour: 'local',
  64. // 修改生成的配置对象的key的展示形式(驼峰还是中划线形式)
  65. localsConvention: "camelCase",
  66. }
  67. },
  68. server: {
  69. port: 4003, // 默认启动端口
  70. // hmr: {
  71. // // 禁用开发服务器错误的屏蔽
  72. // overlay: false,
  73. // },
  74. hmr: false,
  75. proxy: {
  76. "/wsdl": {
  77. target: "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl",
  78. changeOrigin: true,
  79. rewrite: (path) => path.replace(/^\/wsdl/, ""),
  80. },
  81. "/bdhealth": {
  82. target: "https://xnetkf-hlwyy.hydproject.com",
  83. secure: false,
  84. ws: true,
  85. changeOrigin: true,
  86. },
  87. },
  88. }
  89. })