vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: 18184,
  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. '/api/vanna': {
  34. target: 'https://company.citupro.com:18184',
  35. secure: false, // 是否支持 https,默认 false
  36. changeOrigin: true // 是否支持跨域
  37. },
  38. '/op/base': {
  39. target: 'https://company.citupro.com:18183',
  40. secure: false, // 是否支持 https,默认 false
  41. changeOrigin: true // 是否支持跨域
  42. }
  43. }
  44. },
  45. configureWebpack: config => {
  46. config.devtool = 'source-map'
  47. // 代码拆分
  48. config.optimization.splitChunks.chunks = 'all'
  49. config.output.filename = `static/js/[name].${Timestamp}.js`
  50. config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
  51. config.module.rules.push(
  52. {
  53. test: /\.geojson$/,
  54. loader: 'json-loader',
  55. type: 'javascript/auto'
  56. },
  57. // 其他加载器规则...
  58. {
  59. test: /\.jade$/,
  60. loader: 'jade'
  61. },
  62. {
  63. test: /\.pug$/,
  64. loader: 'pug-plain-loader'
  65. })
  66. config.plugins.push(
  67. new WriteFilePlugin({
  68. test: /version\.json$/,
  69. useHashIndex: true
  70. })
  71. )
  72. if (process.env.NODE_ENV === 'production') {
  73. // 压缩 JS 文件
  74. config.plugins.push(
  75. new UglifyJsPlugin({
  76. uglifyOptions: {
  77. compress: {
  78. drop_console: true,
  79. drop_debugger: true
  80. },
  81. output: {
  82. comments: false
  83. }
  84. },
  85. sourceMap: false,
  86. parallel: true
  87. }))
  88. }
  89. },
  90. chainWebpack: config => {
  91. config.when(process.env.NODE_ENV !== 'development', config => {
  92. config.optimization.minimizer('terser').tap(options => {
  93. options[0].terserOptions.compress.drop_console = true
  94. options[0].terserOptions.output = {
  95. comments: false
  96. }
  97. return options
  98. })
  99. })
  100. },
  101. // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
  102. transpileDependencies: [
  103. // '@vue-office/excel',
  104. // 'vue-demi',
  105. // '@vue-office',
  106. // 'xlsx',
  107. // 'exceljs',
  108. // 'html2canvas',
  109. // '@handsontable',
  110. // '@handsontable/vue',
  111. // 'handsontable',
  112. // 'handsontable/registry',
  113. // 'js-base64',
  114. // 'vis-network',
  115. // 'vuetify',
  116. // 'axios'
  117. ]
  118. })