vue.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.module.rules.push(
  70. {
  71. test: /\.geojson$/,
  72. loader: 'json-loader',
  73. type: 'javascript/auto'
  74. },
  75. // 其他加载器规则...
  76. {
  77. test: /\.jade$/,
  78. loader: 'jade'
  79. },
  80. {
  81. test: /\.pug$/,
  82. loader: 'pug-plain-loader'
  83. })
  84. if (process.env.NODE_ENV === 'production') {
  85. // 压缩 JS 文件
  86. config.plugins.push(
  87. new UglifyJsPlugin({
  88. uglifyOptions: {
  89. compress: {
  90. drop_console: true,
  91. drop_debugger: true
  92. },
  93. output: {
  94. comments: false
  95. }
  96. },
  97. sourceMap: false,
  98. parallel: true
  99. }))
  100. }
  101. },
  102. chainWebpack: config => {
  103. config.when(process.env.NODE_ENV !== 'development', config => {
  104. config.optimization.minimizer('terser').tap(options => {
  105. options[0].terserOptions.compress.drop_console = true
  106. options[0].terserOptions.output = {
  107. comments: false
  108. }
  109. return options
  110. })
  111. })
  112. },
  113. // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
  114. transpileDependencies: [
  115. 'axios',
  116. '@wangeditor/editor',
  117. '@wangeditor/editor-for-vue',
  118. 'decimal.js',
  119. 'element-resize-detector',
  120. 'element-ui',
  121. 'nprogress',
  122. '@vue/composition-api',
  123. 'fs',
  124. 'qs',
  125. 'lodash'
  126. ],
  127. // 移除console
  128. terser: {
  129. terserOptions: {
  130. compress: {
  131. drop_console: true,
  132. drop_debugger: true
  133. }
  134. }
  135. },
  136. css: {
  137. loaderOptions: {
  138. sass: {
  139. additionalData: `
  140. @import "@/styles/config.scss";
  141. `
  142. }
  143. }
  144. }
  145. })