vue.config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const { defineConfig } = require('@vue/cli-service')
  2. const webpack = require('webpack')
  3. module.exports = defineConfig({
  4. transpileDependencies: true,
  5. lintOnSave: false,
  6. productionSourceMap: false,
  7. publicPath: './',
  8. devServer: {
  9. port: 8080,
  10. open: true,
  11. historyApiFallback: true,
  12. client: {
  13. overlay: {
  14. errors: true, // 保留编译错误遮罩
  15. runtimeErrors: false // 关掉运行时错误遮罩(接口报错由 Message.error 提示)
  16. }
  17. },
  18. proxy: {
  19. '/auth': {
  20. target: process.env.VUE_APP_BASE_API,
  21. changeOrigin: true,
  22. pathRewrite: { '^/auth': '/auth' }
  23. },
  24. '/laboratory': {
  25. target: process.env.VUE_APP_BASE_API,
  26. changeOrigin: true,
  27. pathRewrite: { '^/laboratory': '/laboratory' }
  28. }
  29. }
  30. },
  31. css: {
  32. loaderOptions: {
  33. sass: {
  34. additionalData: `@import "@/styles/variables.scss";`
  35. }
  36. }
  37. },
  38. chainWebpack(config) {
  39. // 页面标题
  40. config.plugin('html').tap(args => {
  41. args[0].title = process.env.VUE_APP_TITLE || '实验室安全智慧化管控中心'
  42. return args
  43. })
  44. },
  45. configureWebpack: {
  46. plugins: [
  47. new webpack.ProvidePlugin({
  48. Buffer: ['buffer', 'Buffer'],
  49. process: 'process/browser'
  50. })
  51. ],
  52. resolve: {
  53. fallback: {
  54. url: require.resolve('url/'),
  55. buffer: require.resolve('buffer/'),
  56. process: require.resolve('process/browser')
  57. }
  58. },
  59. optimization: {
  60. splitChunks: {
  61. chunks: 'all',
  62. cacheGroups: {
  63. // Vue 全家桶
  64. vue: {
  65. name: 'chunk-vue',
  66. test: /[\\/]node_modules[\\/](vue|vue-router|vuex)[\\/]/,
  67. priority: 30
  68. },
  69. // ECharts 单独拆包(体积最大)
  70. echarts: {
  71. name: 'chunk-echarts',
  72. test: /[\\/]node_modules[\\/](echarts|zrender)[\\/]/,
  73. priority: 25
  74. },
  75. // Element UI
  76. elementUI: {
  77. name: 'chunk-element-ui',
  78. test: /[\\/]node_modules[\\/]element-ui[\\/]/,
  79. priority: 20
  80. },
  81. // 其余第三方
  82. vendors: {
  83. name: 'chunk-vendors',
  84. test: /[\\/]node_modules[\\/]/,
  85. priority: 10,
  86. reuseExistingChunk: true
  87. }
  88. }
  89. }
  90. }
  91. }
  92. })