vue.config.js 3.2 KB

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