vue.config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 || 'vue Admin Template' // 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. // const port = 9529 // dev port
  12. const port = 8082 // dev port
  13. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  14. module.exports = {
  15. /**
  16. * You will need to set publicPath if you plan to deploy your site under a sub path,
  17. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  18. * then publicPath should be set to "/bar/".
  19. * In most cases please use '/' !!!
  20. * Detail: https://cli.vuejs.org/config/#publicpath
  21. */
  22. publicPath: '/',
  23. outputDir: 'dist',
  24. assetsDir: 'static',
  25. lintOnSave: process.env.NODE_ENV === 'development',
  26. productionSourceMap: false,
  27. devServer: {
  28. allowedHosts: ['tmrwatch.cn'],
  29. port: port,
  30. open: true,
  31. overlay: {
  32. warnings: false,
  33. errors: true
  34. },
  35. proxy: {
  36. // change xxx-api/login => mock/login
  37. // // detail: https://cli.vuejs.org/config/#devserver-proxy
  38. // [process.env.VUE_APP_BASE_API]: {
  39. // target: `http://127.0.0.1:${port}/mock`,
  40. // changeOrigin: true,
  41. // pathRewrite: {
  42. // ['^' + process.env.VUE_APP_BASE_API]: ''
  43. // }
  44. // },
  45. '/api': {
  46. // 要访问的跨域的api的域名 蒙牛测试地址 白少本地服务
  47. target: 'http://8.130.17.8:8082',
  48. changeOrigin: true,
  49. pathRewrite: {
  50. '^/api': ''
  51. }
  52. }
  53. }
  54. // after: require('./mock/mock-server.js')
  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. devtool: 'source-map',
  60. name: name,
  61. resolve: {
  62. alias: {
  63. '@': resolve('src')
  64. }
  65. }
  66. },
  67. chainWebpack(config) {
  68. config.plugins.delete('preload') // need test
  69. config.plugins.delete('prefetch') // need test
  70. // set svg-sprite-loader
  71. config.module
  72. .rule('svg')
  73. .exclude.add(resolve('src/icons'))
  74. .end()
  75. config.module
  76. .rule('icons')
  77. .test(/\.svg$/)
  78. .include.add(resolve('src/icons'))
  79. .end()
  80. .use('svg-sprite-loader')
  81. .loader('svg-sprite-loader')
  82. .options({
  83. symbolId: 'icon-[name]'
  84. })
  85. .end()
  86. // set preserveWhitespace
  87. config.module
  88. .rule('vue')
  89. .use('vue-loader')
  90. .loader('vue-loader')
  91. .tap(options => {
  92. options.compilerOptions.preserveWhitespace = true
  93. return options
  94. })
  95. .end()
  96. config
  97. // https://webpack.js.org/configuration/devtool/#development
  98. .when(process.env.NODE_ENV === 'development',
  99. config => config.devtool('cheap-source-map')
  100. )
  101. config
  102. .when(process.env.NODE_ENV !== 'development',
  103. config => {
  104. config
  105. .plugin('ScriptExtHtmlWebpackPlugin')
  106. .after('html')
  107. .use('script-ext-html-webpack-plugin', [{
  108. // `runtime` must same as runtimeChunk name. default is `runtime`
  109. inline: /runtime\..*\.js$/
  110. }])
  111. .end()
  112. config
  113. .optimization.splitChunks({
  114. chunks: 'all',
  115. cacheGroups: {
  116. libs: {
  117. name: 'chunk-libs',
  118. test: /[\\/]node_modules[\\/]/,
  119. priority: 10,
  120. chunks: 'initial' // only package third parties that are initially dependent
  121. },
  122. elementUI: {
  123. name: 'chunk-elementUI', // split elementUI into a single package
  124. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  125. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  126. },
  127. commons: {
  128. name: 'chunk-commons',
  129. test: resolve('src/components'), // can customize your rules
  130. minChunks: 3, // minimum common number
  131. priority: 5,
  132. reuseExistingChunk: true
  133. }
  134. }
  135. })
  136. config.optimization.runtimeChunk('single')
  137. }
  138. )
  139. }
  140. }