vue.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const name = process.env.VUE_APP_TITLE || '铁谷管理系统' // 网页标题
  7. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  8. module.exports = {
  9. publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
  10. outputDir: 'dist',
  11. assetsDir: 'static',
  12. lintOnSave: process.env.NODE_ENV === 'development',
  13. productionSourceMap: false,
  14. devServer: {
  15. host: '0.0.0.0',
  16. port: port,
  17. open: true,
  18. proxy: {
  19. [process.env.VUE_APP_BASE_API]: {
  20. target: `http://192.168.1.21:8080`,
  21. changeOrigin: true,
  22. pathRewrite: {
  23. ['^' + process.env.VUE_APP_BASE_API]: ''
  24. }
  25. }
  26. },
  27. disableHostCheck: true
  28. },
  29. configureWebpack: {
  30. name: name,
  31. resolve: {
  32. alias: {
  33. '@': resolve('src')
  34. }
  35. }
  36. },
  37. chainWebpack(config) {
  38. config.plugins.delete('preload')
  39. config.plugins.delete('prefetch')
  40. config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
  41. config.module
  42. .rule('icons')
  43. .test(/\.svg$/)
  44. .include.add(resolve('src/assets/icons'))
  45. .end()
  46. .use('svg-sprite-loader')
  47. .loader('svg-sprite-loader')
  48. .options({
  49. symbolId: 'icon-[name]'
  50. })
  51. .end()
  52. config.when(process.env.NODE_ENV !== 'development', config => {
  53. config
  54. .plugin('ScriptExtHtmlWebpackPlugin')
  55. .after('html')
  56. .use('script-ext-html-webpack-plugin', [
  57. {
  58. inline: /runtime\..*\.js$/
  59. }
  60. ])
  61. .end()
  62. config.optimization
  63. .minimize(true)
  64. .minimizer('terser')
  65. .tap(args => {
  66. let { terserOptions } = args[0]
  67. terserOptions.compress.drop_console = true
  68. terserOptions.compress.drop_debugger = true
  69. return args
  70. })
  71. config.optimization.splitChunks({
  72. chunks: 'all',
  73. cacheGroups: {
  74. libs: {
  75. name: 'chunk-libs',
  76. test: /[\\/]node_modules[\\/]/,
  77. priority: 10,
  78. chunks: 'initial' // only package third parties that are initially dependent
  79. },
  80. elementUI: {
  81. name: 'chunk-elementUI', // split elementUI into a single package
  82. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  83. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  84. },
  85. commons: {
  86. name: 'chunk-commons',
  87. test: resolve('src/components'), // can customize your rules
  88. minChunks: 3, // minimum common number
  89. priority: 5,
  90. reuseExistingChunk: true
  91. }
  92. }
  93. })
  94. config.optimization.runtimeChunk('single'),
  95. {
  96. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  97. to: './' //到根目录下
  98. }
  99. })
  100. }
  101. }