Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

96 wiersze
2.3 KiB

  1. import vue2 from '@vitejs/plugin-vue2';
  2. import gzip from 'rollup-plugin-gzip';
  3. import { fileURLToPath } from 'url';
  4. import path, { resolve } from 'path';
  5. import { createHtmlPlugin } from 'vite-plugin-html';
  6. import { defineConfig, loadEnv } from 'vite';
  7. import inject from 'rollup-plugin-inject';
  8. // 获取当前文件所在的目录
  9. const __filename = fileURLToPath(import.meta.url);
  10. const __dirname = path.dirname(__filename);
  11. // 读取 package.json 文件
  12. const pkg = require(path.resolve(__dirname, 'package.json'));
  13. const pathResolve = (dir) => {
  14. return resolve(__dirname, '.', dir);
  15. };
  16. const alias = {
  17. '/@': pathResolve('./src/')
  18. };
  19. const plugins = [vue2(), createHtmlPlugin({
  20. minify: true,
  21. inject: {
  22. data: {
  23. version: pkg.version
  24. }
  25. },
  26. })]
  27. const viteConfig = defineConfig((mode) => {
  28. const env = loadEnv(mode.mode, process.cwd());
  29. return {
  30. publicDir: 'src/static',
  31. plugins: mode.command === 'serve' ? plugins
  32. : plugins.concat([gzip()]),
  33. root: process.cwd(),
  34. resolve: { alias },
  35. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  36. server: {
  37. host: '0.0.0.0',
  38. port: 8888,
  39. open: false,
  40. hmr: true,
  41. headers: {
  42. 'Access-Control-Allow-Origin': '*'
  43. },
  44. proxy: {
  45. '/api': {
  46. target: 'https://admintest.malls.iformall.com/api',
  47. // target: 'https://admin.malls.iformall.com/api',
  48. ws: true,
  49. changeOrigin: true,
  50. rewrite: (path) => path.replace(/^\/api/, ''),
  51. },
  52. },
  53. },
  54. build: {
  55. outDir: 'dist',
  56. chunkSizeWarningLimit: 1500,
  57. rollupOptions: {
  58. plugins: [
  59. inject({
  60. "echarts": 'echarts',
  61. 'vue-ueditor-wrap': 'vue-ueditor-wrap',
  62. })
  63. ],
  64. output: {
  65. entryFileNames: `assets/[name].[hash].js`,
  66. chunkFileNames: `assets/[name].[hash].js`,
  67. assetFileNames: `assets/[name].[hash].[ext]`,
  68. compact: true,
  69. manualChunks: {
  70. // vue: ['vue', 'vue-router'],
  71. // echarts: ['echarts'],
  72. },
  73. },
  74. },
  75. },
  76. css: {
  77. preprocessorOptions: {
  78. css: { charset: false }
  79. }
  80. },
  81. define: {
  82. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  83. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  84. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  85. __VERSION__: JSON.stringify(process.env.npm_package_version),
  86. },
  87. };
  88. });
  89. export default viteConfig;