vite.config.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import styleImport, { VantResolve } from 'vite-plugin-style-import'
  4. import postCssPxToRem from 'postcss-pxtorem'
  5. import WindiCSS from 'vite-plugin-windicss'
  6. import * as path from 'path'
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. server: {
  10. port: 4500, // 设置服务启动端口号
  11. open: true, // 设置服务启动时是否自动打开浏览器
  12. cors: true // 允许跨域
  13. // 设置代理,根据我们项目实际情况配置
  14. // proxy: {
  15. // '/api': {
  16. // target: 'http://xxx.xxx.xxx.xxx:x000',
  17. // changeOrigin: true,
  18. // secure: false,
  19. // rewrite: (path) => path.replace('/api/', '/')
  20. // }
  21. // },
  22. },
  23. base: './', // 设置打包路径
  24. build:{
  25. outDir: 'newMobile',
  26. },
  27. plugins: [
  28. vue(),
  29. WindiCSS(),
  30. styleImport({
  31. // resolves: [VantResolve()],
  32. libs: [
  33. {
  34. libraryName: 'vant',
  35. esModule: true,
  36. resolveStyle: component => `vant/es/${component}/style/index`
  37. }
  38. ]
  39. })
  40. ],
  41. resolve: {
  42. alias: {
  43. '@': path.resolve(__dirname, 'src'), //使用@来代表src目录
  44. components: path.resolve(__dirname, 'src/components'),
  45. styles: path.resolve(__dirname, 'src/styles'),
  46. plugins: path.resolve(__dirname, 'src/plugins'),
  47. views: path.resolve(__dirname, 'src/views'),
  48. layouts: path.resolve(__dirname, 'src/layouts'),
  49. utils: path.resolve(__dirname, 'src/utils'),
  50. apis: path.resolve(__dirname, 'src/apis'),
  51. dirs: path.resolve(__dirname, 'src/directives')
  52. }
  53. },
  54. css: {
  55. postcss: {
  56. plugins: [
  57. postCssPxToRem({
  58. rootValue: 37.5, // Vant 官方根字体大小是 37.5
  59. propList: ['*'],
  60. selectorBlackList: ['.norem'] // 过滤掉.norem-开头的class,不进行rem转换
  61. })
  62. ]
  63. }
  64. }
  65. })