vue.config.js 2.8 KB

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