vite.config.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. root,
  19. resolve: {
  20. alias: [
  21. {
  22. find: 'vue-i18n',
  23. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  24. },
  25. // /@/xxxx => src/xxxx
  26. {
  27. find: /\/@\//,
  28. replacement: pathResolve('src') + '/',
  29. },
  30. // /#/xxxx => types/xxxx
  31. {
  32. find: /\/#\//,
  33. replacement: pathResolve('types') + '/',
  34. },
  35. ],
  36. },
  37. server: {
  38. proxy: {
  39. "/service": {
  40. target: "https://v4-uat.4dkankan.com/",
  41. changeOrigin: true,
  42. rewrite: (path) => path.replace(/^\/api/, ""),
  43. },
  44. },
  45. },
  46. plugins: [
  47. vue(),
  48. Components({
  49. resolvers: [VantResolver()]
  50. })
  51. ],
  52. build: {
  53. minify: 'terser',
  54. terserOptions: {
  55. compress: {
  56. //生产环境时移除console
  57. drop_console: true,
  58. drop_debugger: true,
  59. },
  60. },
  61. },
  62. css: {
  63. preprocessorOptions: {
  64. scss: {
  65. // 配置 nutui 全局 scss 变量
  66. additionalData: `@import "@nutui/nutui/dist/styles/variables.scss";@import '/@/styles/mixin.scss';`,
  67. },
  68. },
  69. },
  70. };
  71. }