vite.config.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "@nutui/nutui/dist/styles/variables.scss";@import '/@/styles/mixin.scss';`,
  68. },
  69. },
  70. },
  71. };
  72. }