vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: `https://adminnew.jiuweiyun.work/`,
  38. // target: `http://api.admin.app.jiuweiyun.cn`, // 正式
  39. // target: `http://api.appadmin.woaidakele.cn`, // 测试
  40. // target: `http://192.168.2.75:8082`, // 测试
  41. changeOrigin: true,
  42. pathRewrite: {
  43. ['^' + process.env.VUE_APP_BASE_API]: '/api'
  44. }
  45. }
  46. // [process.env.VUE_APP_BASE_API_PDF]: {
  47. // target: `https://api.admin.app.jiuweiyun.cn//public/uploads/document/images/rankImg`, // 正式
  48. // // target: `https://api.admin.app.jiuweiyun.cn`, // 体验店
  49. // // target: 'http://192.168.0.15:8088',
  50. // // target: `http://192.168.2.75:8082`, // 测试
  51. // changeOrigin: true,
  52. // pathRewrite: {
  53. // ['^' + process.env.VUE_APP_BASE_API]: '/api'
  54. // }
  55. // }
  56. }
  57. },
  58. configureWebpack: {
  59. // provide the app's title in webpack's name field, so that
  60. // it can be accessed in index.html to inject the correct title.
  61. name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src')
  65. }
  66. },
  67. performance: {
  68. hints: false
  69. }
  70. },
  71. chainWebpack(config) {
  72. config.externals({ './cptable': 'var cptable' })
  73. config.plugins.delete('preload') // TODO: need test
  74. config.plugins.delete('prefetch') // TODO: need test
  75. // set svg-sprite-loader
  76. config.module
  77. .rule('svg')
  78. .exclude.add(resolve('src/icons'))
  79. .end()
  80. config.module
  81. .rule('icons')
  82. .test(/\.svg$/)
  83. .include.add(resolve('src/icons'))
  84. .end()
  85. .use('svg-sprite-loader')
  86. .loader('svg-sprite-loader')
  87. .options({
  88. symbolId: 'icon-[name]'
  89. })
  90. .end()
  91. // set preserveWhitespace
  92. config.module
  93. .rule('vue')
  94. .use('vue-loader')
  95. .loader('vue-loader')
  96. .tap(options => {
  97. options.compilerOptions.preserveWhitespace = true
  98. return options
  99. })
  100. .end()
  101. config
  102. // https://webpack.js.org/configuration/devtool/#development
  103. .when(process.env.NODE_ENV === 'development',
  104. config => config.devtool('cheap-source-map')
  105. )
  106. config
  107. .when(process.env.NODE_ENV !== 'development',
  108. config => {
  109. config
  110. .plugin('ScriptExtHtmlWebpackPlugin')
  111. .after('html')
  112. .use('script-ext-html-webpack-plugin', [{
  113. // `runtime` must same as runtimeChunk name. default is `runtime`
  114. inline: /runtime\..*\.js$/
  115. }])
  116. .end()
  117. config
  118. .optimization.splitChunks({
  119. chunks: 'all',
  120. cacheGroups: {
  121. libs: {
  122. name: 'chunk-libs',
  123. test: /[\\/]node_modules[\\/]/,
  124. priority: 10,
  125. chunks: 'initial' // only package third parties that are initially dependent
  126. },
  127. elementUI: {
  128. name: 'chunk-elementUI', // split elementUI into a single package
  129. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  130. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  131. },
  132. commons: {
  133. name: 'chunk-commons',
  134. test: resolve('src/components'), // can customize your rules
  135. minChunks: 3, // minimum common number
  136. priority: 5,
  137. reuseExistingChunk: true
  138. }
  139. }
  140. })
  141. config.optimization.runtimeChunk('single')
  142. }
  143. )
  144. }
  145. }