vue.config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title || '大卫博士管理后台' // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  14. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  15. module.exports = {
  16. /**
  17. * You will need to set publicPath if you plan to deploy your site under a sub path,
  18. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  19. * then publicPath should be set to "/bar/".
  20. * In most cases please use '/' !!!
  21. * Detail: https://cli.vuejs.org/config/#publicpath
  22. */
  23. publicPath: './',
  24. outputDir: 'dist',
  25. assetsDir: 'static',
  26. lintOnSave: process.env.NODE_ENV === 'development',
  27. productionSourceMap: false,
  28. devServer: {
  29. port: port,
  30. open: true,
  31. overlay: {
  32. warnings: false,
  33. errors: true
  34. },
  35. proxy: {
  36. [process.env.VUE_APP_BASE_API]: {
  37. target: `http://kefu.admin.cliu.cc/`,
  38. // target: `http://api.admin.app.jiuweiyun.cn`, // 正式
  39. // target: `http://api.appadmin.woaidakele.cn`, // 测试
  40. // target: 'http://192.168.0.15:8088',
  41. // target: `http://192.168.2.75:8082`, // 测试
  42. changeOrigin: true,
  43. pathRewrite: {
  44. ['^' + process.env.VUE_APP_BASE_API]: '/api'
  45. }
  46. }
  47. // [process.env.VUE_APP_BASE_API_PDF]: {
  48. // target: `https://api.admin.app.jiuweiyun.cn//public/uploads/document/images/rankImg`, // 正式
  49. // // target: `https://api.admin.app.jiuweiyun.cn`, // 体验店
  50. // // target: 'http://192.168.0.15:8088',
  51. // // target: `http://192.168.2.75:8082`, // 测试
  52. // changeOrigin: true,
  53. // pathRewrite: {
  54. // ['^' + process.env.VUE_APP_BASE_API]: '/api'
  55. // }
  56. // }
  57. }
  58. },
  59. configureWebpack: {
  60. // provide the app's title in webpack's name field, so that
  61. // it can be accessed in index.html to inject the correct title.
  62. name: name,
  63. resolve: {
  64. alias: {
  65. '@': resolve('src')
  66. }
  67. },
  68. performance: {
  69. hints: false
  70. }
  71. },
  72. chainWebpack(config) {
  73. config.externals({ './cptable': 'var cptable' })
  74. config.plugins.delete('preload') // TODO: need test
  75. config.plugins.delete('prefetch') // TODO: need test
  76. // set svg-sprite-loader
  77. config.module
  78. .rule('svg')
  79. .exclude.add(resolve('src/icons'))
  80. .end()
  81. config.module
  82. .rule('icons')
  83. .test(/\.svg$/)
  84. .include.add(resolve('src/icons'))
  85. .end()
  86. .use('svg-sprite-loader')
  87. .loader('svg-sprite-loader')
  88. .options({
  89. symbolId: 'icon-[name]'
  90. })
  91. .end()
  92. // set preserveWhitespace
  93. config.module
  94. .rule('vue')
  95. .use('vue-loader')
  96. .loader('vue-loader')
  97. .tap(options => {
  98. options.compilerOptions.preserveWhitespace = true
  99. return options
  100. })
  101. .end()
  102. config
  103. // https://webpack.js.org/configuration/devtool/#development
  104. .when(process.env.NODE_ENV === 'development',
  105. config => config.devtool('cheap-source-map')
  106. )
  107. config
  108. .when(process.env.NODE_ENV !== 'development',
  109. config => {
  110. config
  111. .plugin('ScriptExtHtmlWebpackPlugin')
  112. .after('html')
  113. .use('script-ext-html-webpack-plugin', [{
  114. // `runtime` must same as runtimeChunk name. default is `runtime`
  115. inline: /runtime\..*\.js$/
  116. }])
  117. .end()
  118. config
  119. .optimization.splitChunks({
  120. chunks: 'all',
  121. cacheGroups: {
  122. libs: {
  123. name: 'chunk-libs',
  124. test: /[\\/]node_modules[\\/]/,
  125. priority: 10,
  126. chunks: 'initial' // only package third parties that are initially dependent
  127. },
  128. elementUI: {
  129. name: 'chunk-elementUI', // split elementUI into a single package
  130. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  131. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  132. },
  133. commons: {
  134. name: 'chunk-commons',
  135. test: resolve('src/components'), // can customize your rules
  136. minChunks: 3, // minimum common number
  137. priority: 5,
  138. reuseExistingChunk: true
  139. }
  140. }
  141. })
  142. config.optimization.runtimeChunk('single')
  143. }
  144. )
  145. }
  146. }