vue.config.js 4.7 KB

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