vite.config.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import vue from '@vitejs/plugin-vue'
  2. import path from 'path'
  3. import { ConfigEnv, defineConfig, UserConfigExport } from 'vite'
  4. import Components from 'unplugin-vue-components/vite';
  5. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
  6. import { viteVConsole } from 'vite-plugin-vconsole'
  7. export default ({ command, mode }: ConfigEnv): UserConfigExport => defineConfig({
  8. base: '/',
  9. css: {
  10. preprocessorOptions: {
  11. scss: {
  12. additionalData: '@import "./src/styles/variables";'
  13. },
  14. }
  15. },
  16. resolve: {
  17. alias: [
  18. {
  19. find: '/@',
  20. replacement: path.resolve(__dirname, './src'),
  21. }
  22. ]
  23. },
  24. server: {
  25. open: true,
  26. host: '0.0.0.0',
  27. port: 8080
  28. },
  29. build: {
  30. target: ['es2015'], // 最低支持 es2015
  31. sourcemap: true
  32. },
  33. plugins: [
  34. vue(),
  35. Components({// 自动导入组件
  36. resolvers: [AntDesignVueResolver({ importStyle: false })],
  37. dts: 'src/typings/components.d.ts'
  38. }),
  39. viteVConsole({
  40. entry: path.resolve(__dirname, './src/main.ts'), // 入口文件
  41. localEnabled: command === 'serve', // serve开发环境下
  42. // enabled: command !== 'serve' || mode === 'test', // 打包环境下/发布测试包,
  43. config: { // vconsole 配置项
  44. maxLogNumber: 1000,
  45. theme: 'light'
  46. }
  47. }),
  48. ],
  49. })