vite.config.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * @Author: jixiang
  3. * @Date: 2021-07-07 15:19:05
  4. * @Description: 配置中心
  5. * @FilePath: /suqian_account_new/vite.config.ts
  6. * One World One Drefeel(56580223@qq.com)
  7. */
  8. import { defineConfig } from 'vite';
  9. import vue from '@vitejs/plugin-vue';
  10. import styleImport from 'vite-plugin-style-import';
  11. // import path from 'path';
  12. import path, { resolve } from 'path'; // 主要用于alias文件路径别名
  13. // https://vitejs.dev/config/
  14. const setAlias = (alias: [string, string][]) =>
  15. alias.map((v) => {
  16. return { find: v[0], replacement: path.resolve(__dirname, v[1]) };
  17. });
  18. export default defineConfig({
  19. plugins: [
  20. vue(),
  21. styleImport({
  22. libs: [
  23. {
  24. libraryName: 'ant-design-vue',
  25. esModule: true,
  26. resolveStyle: (name) => {
  27. return `ant-design-vue/es/${name}/style/css`;
  28. },
  29. },
  30. ],
  31. }),
  32. ], // 配置需要使用的插件列表,这里将vue添加进去
  33. // 配置文件别名 vite1.0是/@/ 2.0改为/@
  34. // 这里是将src目录配置别名为 /@ 方便在项目中导入src目录下的文件
  35. resolve: {
  36. alias: setAlias([['@', 'src']]),
  37. },
  38. // 强制预构建插件包
  39. optimizeDeps: {
  40. include: ['axios'],
  41. },
  42. // 打包配置
  43. build: {
  44. target: 'modules',
  45. outDir: 'dist', //指定输出路径
  46. assetsDir: 'bookManage/assets', // 指定生成静态资源的存放路径
  47. minify: 'terser', // 混淆器,terser构建后文件体积更小
  48. },
  49. css: {
  50. preprocessorOptions: {
  51. less: {
  52. modifyVars: {
  53. hack: `true; @import (reference) "${path.resolve('src/styles/index.less')}";`,
  54. },
  55. javascriptEnabled: true,
  56. },
  57. },
  58. },
  59. // 本地运行配置,及反向代理配置
  60. server: {
  61. cors: true, // 默认启用并允许任何源
  62. open: true, // 在服务器启动时自动在浏览器中打开应用程序
  63. host: '0.0.0.0',
  64. //反向代理配置,注意rewrite写法,开始没看文档在这里踩了坑
  65. // proxy: {
  66. // '/api': {
  67. // target: 'http://192.168.99.223:3000', //代理接口
  68. // changeOrigin: true,
  69. // rewrite: (path) => path.replace(/^\/api/, '')
  70. // }
  71. // }
  72. },
  73. });