vue.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. 'use strict'
  2. const { defineConfig } = require('@vue/cli-service')
  3. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  4. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  5. // 配置编辑器
  6. const Timestamp = new Date().getTime()
  7. module.exports = defineConfig({
  8. // 项目部署的基本路径,默认 '/'
  9. publicPath: '/',
  10. assetsDir: 'static',
  11. // 项目打包是否生成js的 source map 调试包,默认 true,生产部署设置为false
  12. productionSourceMap: process.env.NODE_ENV !== 'production',
  13. // devServer 支持 webpack-dev-server 所有选项
  14. devServer: {
  15. open: true,
  16. // host: 'localhost',
  17. port: 9000,
  18. hot: true,
  19. // https: false,
  20. proxy: {
  21. '/op/base': {
  22. // target: 'http://192.168.3.162:7654',
  23. target: 'https://company.citupro.com:18182/op/base',
  24. secure: false, // 是否支持 https,默认 false
  25. changeOrigin: true, // 是否支持跨域
  26. headers: {
  27. // 确保包含这些头部以兼容IE11
  28. Accept: 'application/json',
  29. 'Content-Type': 'application/json; charset=utf-8'
  30. },
  31. onProxyReq (proxyReq) {
  32. // 对于IE11的特殊处理
  33. if (proxyReq.getHeader('origin')) {
  34. proxyReq.setHeader('origin', 'https://company.citupro.com:18182/op/base')
  35. }
  36. },
  37. pathRewrite: {
  38. '^/op/base': ''
  39. }
  40. },
  41. '/op/base/api': {
  42. // target: 'http://192.168.3.162:7654',
  43. target: 'https://company.citupro.com:18183',
  44. secure: false, // 是否支持 https,默认 false
  45. changeOrigin: true, // 是否支持跨域
  46. headers: {
  47. // 确保包含这些头部以兼容IE11
  48. Accept: 'application/json',
  49. 'Content-Type': 'application/json; charset=utf-8'
  50. },
  51. onProxyReq (proxyReq) {
  52. // 对于IE11的特殊处理
  53. if (proxyReq.getHeader('origin')) {
  54. proxyReq.setHeader('origin', 'https://company.citupro.com:18183')
  55. }
  56. },
  57. pathRewrite: {
  58. '^/op/base/api': '/op/base/api'
  59. }
  60. }
  61. }
  62. },
  63. configureWebpack: config => {
  64. config.devtool = 'source-map'
  65. // 代码拆分
  66. config.optimization.splitChunks.chunks = 'all'
  67. config.output.filename = `static/js/[name].${Timestamp}.js`
  68. config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
  69. config.entry = ['core-js/stable', 'regenerator-runtime/runtime', './src/main.js']
  70. config.module.rules.push(
  71. {
  72. test: /\.geojson$/,
  73. loader: 'json-loader',
  74. type: 'javascript/auto'
  75. },
  76. // 其他加载器规则...
  77. {
  78. test: /\.jade$/,
  79. loader: 'jade'
  80. },
  81. {
  82. test: /\.pug$/,
  83. loader: 'pug-plain-loader'
  84. })
  85. if (process.env.NODE_ENV === 'production') {
  86. // 压缩 JS 文件
  87. config.plugins.push(
  88. new UglifyJsPlugin({
  89. uglifyOptions: {
  90. compress: {
  91. drop_console: true,
  92. drop_debugger: true
  93. },
  94. output: {
  95. comments: false
  96. }
  97. },
  98. sourceMap: false,
  99. parallel: true
  100. }))
  101. }
  102. },
  103. chainWebpack: config => {
  104. config.when(process.env.NODE_ENV !== 'development', config => {
  105. config.optimization.minimizer('terser').tap(options => {
  106. options[0].terserOptions.compress.drop_console = true
  107. options[0].terserOptions.output = {
  108. comments: false
  109. }
  110. return options
  111. })
  112. })
  113. },
  114. // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
  115. transpileDependencies: [
  116. // Vue 相关
  117. 'vue',
  118. 'vuex',
  119. 'vue-router',
  120. '@vue/composition-api',
  121. // UI 组件库
  122. 'element-ui',
  123. // 编辑器
  124. '@wangeditor/editor',
  125. '@wangeditor/editor-for-vue',
  126. // 其他可能包含 ES6 代码的依赖
  127. 'axios',
  128. 'lodash',
  129. 'echarts',
  130. 'decimal.js',
  131. 'nprogress',
  132. 'element-resize-detector',
  133. // 使用正则匹配更广泛的包
  134. /node_modules\/@wangeditor/,
  135. /node_modules\/vue-/,
  136. /node_modules\/element-ui/,
  137. /node_modules\/echarts/
  138. ],
  139. // 移除console
  140. terser: {
  141. terserOptions: {
  142. compress: {
  143. drop_console: true,
  144. drop_debugger: true
  145. }
  146. }
  147. },
  148. css: {
  149. loaderOptions: {
  150. sass: {
  151. additionalData: `
  152. @import "@/styles/config.scss";
  153. `
  154. }
  155. }
  156. }
  157. })