vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import copy from 'rollup-plugin-copy'
  5. // import createVitePlugins from './vite/plugins'
  6. // https://vitejs.dev/config/
  7. // export default defineConfig({
  8. // plugins: [
  9. // vue(),
  10. // copy({
  11. // targets: [
  12. // { src: './node_modules/libpag/lib/libpag.wasm', dest: process.env.NODE_ENV === 'production' ? 'dist/' : 'public/' },
  13. // ],
  14. // hook: process.env.NODE_ENV === 'production' ? 'writeBundle' : "buildStart",
  15. // })
  16. // ],
  17. // resolve: {
  18. // // https://cn.vitejs.dev/config/#resolve-alias
  19. // alias: {
  20. // // 设置路径
  21. // '~': path.resolve(__dirname, './'),
  22. // // 设置别名
  23. // '@': path.resolve(__dirname, './src')
  24. // },
  25. // // https://cn.vitejs.dev/config/#resolve-extensions
  26. // extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  27. // },
  28. // })
  29. export default defineConfig(({
  30. mode,
  31. command
  32. }) => {
  33. const env = loadEnv(mode, process.cwd())
  34. const {
  35. VITE_APP_ENV
  36. } = env
  37. return {
  38. // 部署生产环境和开发环境下的URL。
  39. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  40. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  41. base: VITE_APP_ENV === 'production' ? '/' : '/',
  42. plugins: [
  43. vue(),
  44. copy({
  45. targets: [
  46. { src: './node_modules/libpag/lib/libpag.wasm', dest: process.env.NODE_ENV === 'production' ? 'dist/' : 'public/' },
  47. ],
  48. hook: process.env.NODE_ENV === 'production' ? 'writeBundle' : "buildStart",
  49. })
  50. ],
  51. resolve: {
  52. // https://cn.vitejs.dev/config/#resolve-alias
  53. alias: {
  54. // 设置路径
  55. '~': path.resolve(__dirname, './'),
  56. // 设置别名
  57. '@': path.resolve(__dirname, './src')
  58. },
  59. // https://cn.vitejs.dev/config/#resolve-extensions
  60. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  61. },
  62. // vite 相关配置
  63. server: {
  64. port: 80,
  65. host: true,
  66. open: true,
  67. proxy: {
  68. '/dev-api': {
  69. target: 'http://192.168.101.99:8080/',
  70. changeOrigin: true,
  71. rewrite: (p) => p.replace(/^\/dev-api/, '')
  72. }
  73. }
  74. },
  75. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  76. css: {
  77. postcss: {
  78. plugins: [{
  79. postcssPlugin: 'internal:charset-removal',
  80. AtRule: {
  81. charset: (atRule) => {
  82. if (atRule.name === 'charset') {
  83. atRule.remove();
  84. }
  85. }
  86. }
  87. }]
  88. }
  89. }
  90. }
  91. })