玛尔挡水温监测系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vite.config.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import path from 'path'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import autoImport from 'unplugin-auto-import/vite'
  5. import compression from 'vite-plugin-compression'
  6. import eslint from 'vite-plugin-eslint'
  7. import setupExtend from 'unplugin-vue-setup-extend-plus/vite'
  8. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  9. // vite.config.js 配置说明(参考文档 https://vitejs.dev/config)
  10. export default defineConfig(({ mode, command }) => {
  11. const env = loadEnv(mode, process.cwd())
  12. const isBuild = command === 'build'
  13. return {
  14. // 开发或生产环境服务的公共基础路径(如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.my-app.com/my-app/,则设置 baseUrl 为 /my-app/)
  15. base: env.VITE_APP_CONTEXT_PATH,
  16. // 需要用到的插件数组
  17. plugins: [
  18. vue(),
  19. autoImport({
  20. dts: false,
  21. imports: ['vue', 'vue-router', 'pinia'],
  22. eslintrc: {
  23. enabled: true, // 启用 ESLint 自动导入配置
  24. filepath: './.eslintrc-auto-import.json', // 生成的文件路径
  25. globalsPropValue: true
  26. }
  27. }),
  28. compression(), // 启动gzip压缩
  29. eslint(),
  30. setupExtend({}),
  31. createSvgIconsPlugin({
  32. iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
  33. symbolId: 'icon-[dir]-[name]',
  34. svgoOptions: isBuild
  35. })
  36. ],
  37. resolve: {
  38. alias: {
  39. // 设置路径
  40. '~': path.resolve(__dirname, './'),
  41. // 设置别名
  42. '@': path.resolve(__dirname, './src')
  43. },
  44. // 导入时想要省略的扩展名列表
  45. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  46. },
  47. server: {
  48. host: '0.0.0.0',
  49. port: 80,
  50. open: true,
  51. proxy: {
  52. [env.VITE_APP_BASE_API]: {
  53. target: 'http://localhost:8080',
  54. changeOrigin: true,
  55. rewrite: (p) => p.replace(env.VITE_APP_BASE_API, '')
  56. }
  57. }
  58. },
  59. // fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  60. css: {
  61. postcss: {
  62. plugins: [
  63. {
  64. postcssPlugin: 'internal:charset-removal',
  65. AtRule: {
  66. charset: (atRule) => {
  67. if (atRule.name === 'charset') {
  68. atRule.remove()
  69. }
  70. }
  71. }
  72. }
  73. ]
  74. }
  75. }
  76. }
  77. })