vite.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. preprocessorOptions: {
  56. scss: {
  57. additionalData: '@import "./src/style/index.scss";' // 添加公共样式
  58. }
  59. },
  60. postcss: {
  61. plugins: [
  62. postCssPxToRem({
  63. rootValue: 37.5, // Vant 官方根字体大小是 37.5
  64. propList: ['*'],
  65. selectorBlackList: ['.norem'] // 过滤掉.norem-开头的class,不进行rem转换
  66. })
  67. ]
  68. }
  69. }
  70. })