vue.config.js 3.1 KB

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