vite.config.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // import { createVitePlugins } from './build/vite/plugins';
  2. import { resolve } from 'path';
  3. import { ConfigEnv, UserConfig } from 'vite';
  4. // import { wrapperEnv } from './build/utils';
  5. import Components from 'unplugin-vue-components/vite';
  6. import { VantResolver } from 'unplugin-vue-components/resolvers';
  7. import vue from '@vitejs/plugin-vue';
  8. const pathResolve = (dir: string) => {
  9. return resolve(process.cwd(), '.', dir);
  10. };
  11. // https://vitejs.dev/config/
  12. export default function (_: ConfigEnv): UserConfig {
  13. // const isProduction = command === 'build';
  14. const root = process.cwd();
  15. // const env = loadEnv(mode, root);
  16. // const viteEnv = wrapperEnv(env);
  17. return {
  18. base: './',
  19. root,
  20. resolve: {
  21. alias: [
  22. {
  23. find: 'vue-i18n',
  24. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  25. },
  26. // /@/xxxx => src/xxxx
  27. {
  28. find: /\/@\//,
  29. replacement: pathResolve('src') + '/',
  30. },
  31. // /#/xxxx => types/xxxx
  32. {
  33. find: /\/#\//,
  34. replacement: pathResolve('types') + '/',
  35. },
  36. ],
  37. },
  38. server: {
  39. proxy: {
  40. '/service': {
  41. target: 'https://v4-uat.4dkankan.com/',
  42. changeOrigin: true,
  43. rewrite: (path) => path.replace(/^\/api/, ''),
  44. },
  45. },
  46. },
  47. plugins: [
  48. vue(),
  49. Components({
  50. resolvers: [VantResolver()],
  51. }),
  52. ],
  53. build: {
  54. minify: 'terser',
  55. terserOptions: {
  56. compress: {
  57. //生产环境时移除console
  58. drop_console: false,
  59. drop_debugger: true,
  60. },
  61. },
  62. },
  63. css: {
  64. preprocessorOptions: {
  65. // scss: {
  66. // // 配置 nutui 全局 scss 变量
  67. // additionalData: `@import "vant/lib/index.css";`,
  68. // },
  69. // css: {
  70. // // 配置 nutui 全局 scss 变量
  71. // additionalData: `@import "vant/lib/index.css";`,
  72. // },
  73. },
  74. },
  75. };
  76. }