vite.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 { createHtmlPlugin } from 'vite-plugin-html';
  6. export default defineConfig(({
  7. mode,
  8. command
  9. }) => {
  10. const env = loadEnv(mode, process.cwd())
  11. const {
  12. VITE_APP_ENV
  13. } = env
  14. return {
  15. // 部署生产环境和开发环境下的URL。
  16. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  17. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  18. base: VITE_APP_ENV === 'production' ? '/' : '/',
  19. plugins: [
  20. vue(),
  21. copy({
  22. targets: [
  23. { src: './node_modules/libpag/lib/libpag.wasm', dest: process.env.NODE_ENV === 'production' ? 'dist/' : 'public/' },
  24. ],
  25. hook: process.env.NODE_ENV === 'production' ? 'writeBundle' : "buildStart",
  26. }),
  27. createHtmlPlugin({
  28. inject: {
  29. data: {
  30. title: env.VITE_APP_TITLE || '聚合智慧文档',
  31. },
  32. },
  33. })
  34. ],
  35. resolve: {
  36. // https://cn.vitejs.dev/config/#resolve-alias
  37. alias: {
  38. // 设置路径
  39. '~': path.resolve(__dirname, './'),
  40. // 设置别名
  41. '@': path.resolve(__dirname, './src')
  42. },
  43. // https://cn.vitejs.dev/config/#resolve-extensions
  44. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  45. },
  46. // vite 相关配置
  47. server: {
  48. port: 80,
  49. host: true,
  50. open: true,
  51. proxy: {
  52. '/dev-api': {
  53. target: 'http://192.168.101.99:8080/',
  54. changeOrigin: true,
  55. rewrite: (p) => p.replace(/^\/dev-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. postcssPlugin: 'internal:charset-removal',
  64. AtRule: {
  65. charset: (atRule) => {
  66. if (atRule.name === 'charset') {
  67. atRule.remove();
  68. }
  69. }
  70. }
  71. }]
  72. }
  73. }
  74. }
  75. })