vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import vue from '@vitejs/plugin-vue'; //提供 Vue 3 单文件组件支持
  2. import OptimizationPersist from "vite-plugin-optimize-persist";
  3. import PkgConfig from "vite-plugin-package-config";
  4. import path from 'path';
  5. import {
  6. defineConfig
  7. } from 'vite';
  8. // import postCssPxToRem from "postcss-pxtorem";
  9. // https://vitejs.dev/config/
  10. export default defineConfig({
  11. plugins: [
  12. vue(),
  13. PkgConfig(),
  14. OptimizationPersist()
  15. ],
  16. // 部署生产环境和开发环境下的URL。
  17. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上,例如 https://www.ruoyi.vip/。
  18. // 如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  19. // base: './',
  20. base: process.env.NODE_ENV === 'development' ? './' : '/sdjt/',
  21. resolve: {
  22. alias: {
  23. // 设置别名
  24. '@': path.resolve(__dirname, './src')
  25. },
  26. //导入时想要省略的扩展名列表
  27. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
  28. },
  29. // 强制预构建插件包
  30. optimizeDeps: {
  31. //检测需要预构建的依赖项
  32. entries: [],
  33. //默认情况下,不在 node_modules 中的,链接的包不会预构建
  34. include: ["@/common/store/widget"],
  35. exclude: [] //排除在优化之外
  36. },
  37. /* 全局变量 */
  38. css: {
  39. // 指定传递给 CSS 预处理器的选项
  40. preprocessorOptions: {
  41. scss: {
  42. additionalData: '@use "@/assets/styles/variables.scss" as *;'
  43. },
  44. },
  45. // postcss: {
  46. // plugins: [
  47. // postCssPxToRem({
  48. // rootValue: 192, // (设计稿/10)1rem的大小
  49. // propList: ['*'], // 需要转换的属性,这里选择全部都进行转换
  50. // })
  51. // ]
  52. // }
  53. },
  54. /* 服务器配置 */
  55. server: {
  56. /* 端口 */
  57. port: 3000,
  58. /* 地址 */
  59. host: "0.0.0.0",
  60. /* 编译后是否打开浏览器 */
  61. open: true,
  62. /* 是否开启https */
  63. https: false,
  64. },
  65. /* 打包配置 */
  66. build: {
  67. /**
  68. * 设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——'modules',这是指 支持原生 ES 模块的浏览器。
  69. */
  70. target: 'modules',
  71. /**
  72. * 指定输出路径(相对于 项目根目录).
  73. * @default 'dist'
  74. */
  75. outDir: "dist",
  76. /**
  77. * 启用/禁用 CSS 代码拆分
  78. */
  79. cssCodeSplit: true,
  80. /**
  81. * 混淆器,terser构建后文件体积更小
  82. */
  83. minify: 'terser', // 混淆器,terser构建后文件体积更小
  84. chunkSizeWarningLimit: 4500,
  85. // 自定义rollup-commonjs插件选项
  86. commonjsOptions: {
  87. include: /node_modules|packages|src\/common\/store/
  88. },
  89. rollupOptions: {
  90. output: {
  91. manualChunks(id) {
  92. if (id.includes('node_modules')) {
  93. return id.toString().split('node_modules/')[1].split('/')[0].toString();
  94. }
  95. }
  96. }
  97. }
  98. },
  99. })