vite.config.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. // https://vitejs.dev/config/
  5. export default defineConfig({
  6. resolve: {
  7. alias: {
  8. /*
  9. 路径别名
  10. 若为文件系统路径必须是绝对路径的形式,否则将以别名原样呈现,不会解析为文件系统路径路径
  11. */
  12. //'@': process.cwd()+'/src'
  13. //'@':path.resolve('src')
  14. //'@':path.resolve(__dirname, 'src')
  15. '@': path.resolve(__dirname, './src'),
  16. },
  17. },
  18. plugins: [vue()],
  19. /*
  20. Project root directory/项目根目录(index.html所在位置),可以是绝对路径,也可以是相对于本配置文件的路径。
  21. default:process.cwd() 返回 Node.js 进程的当前工作目录
  22. */
  23. //root:process.cwd(),
  24. /*
  25. Default: /
  26. Base public path (应用基础请求路径) when served in development or production. Valid values include:
  27. Absolute URL pathname, e.g. /foo/
  28. Full URL, e.g. https://foo.com/
  29. Empty string or ./ (for embedded deployment)
  30. */
  31. // base: '/admin/',
  32. /*
  33. Directory to serve as plain static assets.
  34. Files in this directory are served at / during dev and copied to the root of outDir during build, and are always served or copied as-is without transform.
  35. The value can be either an absolute file system path or a path relative to project root.
  36. 静态资源目录,开发模式下会自动放到 / 下,生产模式下会自动放到 outDir 根路径下。
  37. 该目录可以配置为文件系统绝对目录或者相对于项目根目录的相对路径
  38. */
  39. publicDir: 'public',
  40. /*
  41. Default: 'development' for serve, 'production' for build
  42. Specifying this in config will override the default mode for both serve and build. This value can also be overridden via the command line --mode option.
  43. */
  44. //mode:'',
  45. //vite开发服务器配置
  46. server: {
  47. host: '0.0.0.0',
  48. port: 3000,
  49. open: false,
  50. strictPort: false,
  51. https: false,
  52. // 反向代理
  53. proxy: {
  54. '/sys': {
  55. target: 'http://192.168.0.47:8190',
  56. changeOrigin: true,
  57. },
  58. '/scene': {
  59. target: 'http://192.168.0.47:8190',
  60. changeOrigin: true,
  61. },
  62. '/brand': {
  63. target: 'http://192.168.0.47:8190',
  64. changeOrigin: true,
  65. },
  66. },
  67. //proxy: {
  68. // // string shorthand
  69. // '/foo': 'http://localhost:4567/foo',
  70. // // with options
  71. // '/api': {
  72. // target: 'http://jsonplaceholder.typicode.com',
  73. // changeOrigin: true,
  74. // rewrite: (path) => path.replace(/^\/api/, '')
  75. // },
  76. // // with RegEx
  77. // '^/fallback/.*': {
  78. // target: 'http://jsonplaceholder.typicode.com',
  79. // changeOrigin: true,
  80. // rewrite: (path) => path.replace(/^\/fallback/, '')
  81. // }
  82. // }
  83. },
  84. //生产模式打包配置
  85. build: {
  86. outDir: 'dist', //Specify the output directory (relative to project root).
  87. },
  88. })