vite.config.js 2.9 KB

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