vue.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict'
  2. const { defineConfig } = require('@vue/cli-service')
  3. const WriteFilePlugin = require('write-file-webpack-plugin')
  4. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  5. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  6. // const fs = require('fs')
  7. // 配置编辑器
  8. const Timestamp = new Date().getTime()
  9. // if (process.env.NODE_ENV === 'production') {
  10. // fs.writeFile('./public/version.json', JSON.stringify({ version: Timestamp }), () => {
  11. // console.log('新版本号生成成功')
  12. // })
  13. // }
  14. module.exports = defineConfig({
  15. // 项目部署的基本路径,默认 '/'
  16. publicPath: '/',
  17. assetsDir: 'static',
  18. // 项目打包是否生成js的 source map 调试包,默认 true,生产部署设置为false
  19. productionSourceMap: process.env.NODE_ENV !== 'production',
  20. // devServer 支持 webpack-dev-server 所有选项
  21. devServer: {
  22. open: true,
  23. // host: 'localhost',
  24. port: 18183,
  25. hot: true,
  26. // https: false,
  27. proxy: {
  28. '/api': {
  29. target: 'https://company.citupro.com:18183',
  30. secure: false, // 是否支持 https,默认 false
  31. changeOrigin: true // 是否支持跨域
  32. },
  33. '/op/base': {
  34. target: 'https://company.citupro.com:18183',
  35. secure: false, // 是否支持 https,默认 false
  36. changeOrigin: true // 是否支持跨域
  37. }
  38. // '/n8n-proxy': {
  39. // target: 'http://localhost:3001', // 指向你的 proxy-server.js(运行在 3001 端口)
  40. // changeOrigin: true, // 关键:让 proxy-server 认为请求来自 n8n 服务器
  41. // pathRewrite: { '^/n8n-proxy': '' }, // 移除 /n8n-proxy 前缀,转发路径变为 /home/workflows
  42. // ws: true, // 支持 WebSocket(n8n 可能用到)
  43. // logLevel: 'debug' // 可选:开启调试日志,查看代理是否生效(控制台会输出转发信息)
  44. // },
  45. // // 静态资源代理:匹配 n8n 的 /assets 和 /static 路径(解决之前的 MIME 错误)
  46. // '^/(assets|static)/': {
  47. // target: 'http://localhost:3001',
  48. // changeOrigin: true,
  49. // ws: true
  50. // }
  51. }
  52. },
  53. configureWebpack: config => {
  54. config.devtool = 'source-map'
  55. // 代码拆分
  56. config.optimization.splitChunks.chunks = 'all'
  57. config.output.filename = `static/js/[name].${Timestamp}.js`
  58. config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
  59. config.module.rules.push(
  60. {
  61. test: /\.geojson$/,
  62. loader: 'json-loader',
  63. type: 'javascript/auto'
  64. },
  65. // 其他加载器规则...
  66. {
  67. test: /\.jade$/,
  68. loader: 'jade'
  69. },
  70. {
  71. test: /\.pug$/,
  72. loader: 'pug-plain-loader'
  73. })
  74. config.plugins.push(
  75. new WriteFilePlugin({
  76. test: /version\.json$/,
  77. useHashIndex: true
  78. })
  79. )
  80. if (process.env.NODE_ENV === 'production') {
  81. // 压缩 JS 文件
  82. config.plugins.push(
  83. new UglifyJsPlugin({
  84. uglifyOptions: {
  85. compress: {
  86. drop_console: true,
  87. drop_debugger: true
  88. },
  89. output: {
  90. comments: false
  91. }
  92. },
  93. sourceMap: false,
  94. parallel: true
  95. }))
  96. }
  97. },
  98. chainWebpack: config => {
  99. config.when(process.env.NODE_ENV !== 'development', config => {
  100. config.optimization.minimizer('terser').tap(options => {
  101. options[0].terserOptions.compress.drop_console = true
  102. options[0].terserOptions.output = {
  103. comments: false
  104. }
  105. return options
  106. })
  107. })
  108. },
  109. // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
  110. transpileDependencies: [
  111. '@vue-office/excel',
  112. 'vue-demi',
  113. '@vue-office',
  114. 'xlsx',
  115. 'exceljs',
  116. 'html2canvas',
  117. '@handsontable',
  118. '@handsontable/vue',
  119. 'handsontable',
  120. 'handsontable/registry',
  121. 'js-base64',
  122. 'vis-network',
  123. 'vuetify',
  124. 'axios'
  125. ]
  126. })