vue.config.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. // productionSourceMap: false,
  14. // devServer 支持 webpack-dev-server 所有选项
  15. devServer: {
  16. open: true,
  17. // host: 'localhost',
  18. port: 9000,
  19. hot: true,
  20. // https: false,
  21. proxy: {
  22. '/op/base': {
  23. // target: 'http://192.168.3.162:7654',
  24. target: 'https://company.citupro.com:18182/op/base',
  25. secure: false, // 是否支持 https,默认 false
  26. changeOrigin: true, // 是否支持跨域
  27. headers: {
  28. // 确保包含这些头部以兼容IE11
  29. Accept: 'application/json',
  30. 'Content-Type': 'application/json; charset=utf-8'
  31. },
  32. onProxyReq (proxyReq) {
  33. // 对于IE11的特殊处理
  34. if (proxyReq.getHeader('origin')) {
  35. proxyReq.setHeader('origin', 'https://company.citupro.com:18182/op/base')
  36. }
  37. },
  38. pathRewrite: {
  39. '^/op/base': ''
  40. }
  41. },
  42. '/op/base/api': {
  43. // target: 'http://192.168.3.162:7654',
  44. target: 'https://company.citupro.com:18183',
  45. secure: false, // 是否支持 https,默认 false
  46. changeOrigin: true, // 是否支持跨域
  47. headers: {
  48. // 确保包含这些头部以兼容IE11
  49. Accept: 'application/json',
  50. 'Content-Type': 'application/json; charset=utf-8'
  51. },
  52. onProxyReq (proxyReq) {
  53. // 对于IE11的特殊处理
  54. if (proxyReq.getHeader('origin')) {
  55. proxyReq.setHeader('origin', 'https://company.citupro.com:18183')
  56. }
  57. },
  58. pathRewrite: {
  59. '^/op/base/api': '/op/base/api'
  60. }
  61. }
  62. }
  63. },
  64. configureWebpack: config => {
  65. config.devtool = 'source-map'
  66. // 代码拆分
  67. config.optimization.splitChunks.chunks = 'all'
  68. config.entry = ['core-js/stable', 'regenerator-runtime/runtime', './src/main.js']
  69. // 代码拆分配置
  70. // config.optimization.splitChunks = {
  71. // chunks: 'all',
  72. // cacheGroups: {
  73. // vendors: {
  74. // test: /[\\/]node_modules[\\/]/,
  75. // priority: -10,
  76. // name: 'vendors'
  77. // },
  78. // common: {
  79. // minChunks: 2,
  80. // priority: -20,
  81. // reuseExistingChunk: true
  82. // }
  83. // }
  84. // }
  85. config.output.filename = `static/js/[name].${Timestamp}.js`
  86. config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
  87. config.module.rules.push(
  88. {
  89. test: /\.geojson$/,
  90. loader: 'json-loader',
  91. type: 'javascript/auto'
  92. },
  93. // 其他加载器规则...
  94. {
  95. test: /\.jade$/,
  96. loader: 'jade'
  97. },
  98. {
  99. test: /\.pug$/,
  100. loader: 'pug-plain-loader'
  101. }
  102. )
  103. if (process.env.NODE_ENV === 'production') {
  104. config.plugins.push(
  105. new UglifyJsPlugin({
  106. uglifyOptions: {
  107. compress: {
  108. drop_console: true,
  109. drop_debugger: true
  110. },
  111. output: {
  112. comments: false
  113. }
  114. },
  115. sourceMap: false,
  116. parallel: true
  117. }))
  118. }
  119. },
  120. chainWebpack: config => {
  121. config.when(process.env.NODE_ENV !== 'development', config => {
  122. config.optimization.minimizer('terser').tap(options => {
  123. options[0].terserOptions.compress.drop_console = true
  124. options[0].terserOptions.output = {
  125. comments: false
  126. }
  127. return options
  128. })
  129. })
  130. },
  131. // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
  132. transpileDependencies: [
  133. // /[\\/]node_modules[\\/]/ // 转译所有 node_modules 中的依赖
  134. // Vue 相关
  135. // 'vue',
  136. // 'vuex',
  137. // 'vue-router',
  138. // UI 组件库
  139. 'element-ui',
  140. // 'async-validator',
  141. // 编辑器
  142. '@wangeditor/editor',
  143. '@wangeditor/editor-for-vue',
  144. // '@mdi/font',
  145. // 'scrolling-element',
  146. // // 其他可能包含 ES6 代码的依赖
  147. 'fs',
  148. 'axios',
  149. 'lodash',
  150. // 移除 'echarts' 以避免模块转换问题
  151. 'decimal.js',
  152. 'nprogress',
  153. 'element-resize-detector',
  154. // // 使用正则匹配更广泛的包
  155. /node_modules\/@wangeditor/
  156. // /node_modules\/vue-/,
  157. // /node_modules\/element-ui/,
  158. // 注释掉 echarts 相关的转译配置
  159. // /node_modules\/echarts/
  160. ],
  161. // 移除console
  162. terser: {
  163. terserOptions: {
  164. compress: {
  165. drop_console: true,
  166. drop_debugger: true
  167. }
  168. }
  169. },
  170. css: {
  171. loaderOptions: {
  172. sass: {
  173. additionalData: `
  174. @import "@/styles/config.scss";
  175. `
  176. }
  177. }
  178. }
  179. })