当前位置:   article > 正文

vue3.0 vite-config配置_you can also disable this overlay by setting serve

you can also disable this overlay by setting server.hmr.overlay to false in
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import { resolve } from 'path'
  5. import viteSvgIcons from 'vite-plugin-svg-icons'
  6. import VueSetupExtend from 'vite-plugin-vue-setup-extend'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import Components from 'unplugin-vue-components/vite'
  9. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  10. import styleImport from 'vite-plugin-style-import'
  11. // https://vitejs.dev/config/
  12. export default defineConfig({
  13. base: '/',
  14. clearScreen: false,
  15. server: {
  16. hmr: { overlay: false }, // 禁用或配置 HMR 连接 设置 server.hmr.overlay 为 false 可以禁用服务器错误遮罩层
  17. // 服务配置
  18. port: 8080, // 类型: number 指定服务器端口;
  19. open: false, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
  20. cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
  21. //proxy look for https://vitejs.cn/config/#server-proxy
  22. proxy: {
  23. '/dev': {
  24. target: '',
  25. changeOrigin: true,
  26. rewrite: path => path.replace(/^\/dev/, '')
  27. }
  28. }
  29. },
  30. plugins: [
  31. vue({
  32. // refTransform: true // 开启ref转换
  33. }),
  34. vueJsx(),
  35. VueSetupExtend(),
  36. AutoImport({
  37. imports: [
  38. 'vue',
  39. 'vuex',
  40. 'vue-router',
  41. {
  42. '@/utils/elementUI': ['messages']
  43. }
  44. ],
  45. resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
  46. dts: true
  47. }),
  48. Components({
  49. extensions: ['vue', 'jsx'],
  50. dts: true,
  51. include: [/\.vue$/, /\.jsx$/, /\.vue\?vue/],
  52. resolvers: [
  53. ElementPlusResolver({
  54. importStyle: 'sass'
  55. })
  56. ]
  57. })
  58. // styleImport({
  59. // libs: [
  60. // {
  61. // libraryName: 'vxe-table',
  62. // esModule: true,
  63. // resolveComponent: (name) => `vxe-table/es/${name}`,
  64. // resolveStyle: (name) => `vxe-table/es/${name}/style.css`
  65. // }
  66. // ]
  67. // })
  68. ],
  69. build: {
  70. // minify: 'terser',
  71. brotliSize: false,
  72. // 消除打包大小超过500kb警告
  73. chunkSizeWarningLimit: 2000,
  74. //remote console.log in prod
  75. terserOptions: {
  76. //detail to look https://terser.org/docs/api-reference#compress-options
  77. compress: {
  78. drop_console: false,
  79. pure_funcs: ['console.log', 'console.info'],
  80. drop_debugger: true
  81. }
  82. },
  83. //build assets Separate
  84. assetsDir: 'static/assets',
  85. rollupOptions: {
  86. output: {
  87. chunkFileNames: 'static/js/[name]-[hash].js',
  88. entryFileNames: 'static/js/[name]-[hash].js',
  89. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  90. }
  91. }
  92. },
  93. optimizeDeps: {
  94. include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en']
  95. },
  96. resolve: {
  97. alias: {
  98. '@': resolve(__dirname, 'src'),
  99. //remove i18n waring
  100. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  101. },
  102. extensions: ['.vue', '.js', '.ts', '.jsx']
  103. },
  104. css: {
  105. preprocessorOptions: {
  106. scss: {
  107. additionalData: `@use "@/styles/element/index.scss" as *;`
  108. }
  109. }
  110. }
  111. })

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/83932
推荐阅读
相关标签
  

闽ICP备14008679号