vue.config.js 6.0 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 || 'vue Admin Template' // page title
  8. const cdn = {
  9. css: {
  10. dev: [
  11. '/cdn/element-ui/2.13.2/theme-chalk/index.css',
  12. `./static/iconfont/iconfont.css`
  13. ],
  14. ship: [
  15. '/cdn/element-ui/2.13.2/theme-chalk/index.css',
  16. `./static/iconfont/iconfont.css`
  17. ],
  18. product: [
  19. `/cdn/winseaview/index.css`,
  20. '/cdn/element-ui/2.13.2/theme-chalk/index.css',
  21. `./static/iconfont/iconfont.css`
  22. ]
  23. }
  24. }
  25. // If your port is set to 80,
  26. // use administrator privileges to execute the command line.
  27. // For example, Mac: sudo npm run
  28. // You can change the port by the following methods:
  29. // port = 9528 npm run dev OR npm run dev --port = 9528
  30. const port = process.env.port || process.env.npm_config_port || 9528 // dev port
  31. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  32. module.exports = {
  33. /**
  34. * You will need to set publicPath if you plan to deploy your site under a sub path,
  35. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  36. * then publicPath should be set to "/bar/".
  37. * In most cases please use '/' !!!
  38. * Detail: https://cli.vuejs.org/config/#publicpath
  39. */
  40. publicPath: '/',
  41. outputDir: 'dist',
  42. assetsDir: 'static',
  43. lintOnSave: process.env.NODE_ENV === 'development',
  44. productionSourceMap: false,
  45. devServer: {
  46. port: port,
  47. disableHostCheck: true,
  48. open: false,
  49. overlay: {
  50. warnings: false,
  51. errors: true
  52. },
  53. proxy: {
  54. '/pb': {
  55. // target: 'http://192.168.110.67:8099/',
  56. target: 'http://192.168.110.9:8099/',
  57. // target: 'https://apitest.eliangeyun.com',
  58. changeOrigin: true, // 开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
  59. pathRewrite: {
  60. '^/pb': '/'
  61. }, // 这里重写路径
  62. secure: false,
  63. logLevel: 'debug'
  64. }
  65. }
  66. // https: true
  67. },
  68. configureWebpack: {
  69. // provide the app's title in webpack's name field, so that
  70. // it can be accessed in index.html to inject the correct title.
  71. name: name,
  72. resolve: {
  73. alias: {
  74. '@': resolve('src')
  75. }
  76. }
  77. },
  78. chainWebpack(config) {
  79. // it can improve the speed of the first screen, it is recommended to turn on preload
  80. config.plugin('preload').tap(() => [{
  81. rel: 'preload',
  82. // to ignore runtime.js
  83. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  84. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  85. include: 'initial'
  86. }])
  87. // when there are many pages, it will cause too many meaningless requests
  88. config.plugins.delete('prefetch')
  89. config.plugin('html')
  90. .tap(args => {
  91. args[0].cdn = cdn
  92. return args
  93. })
  94. // set svg-sprite-loader
  95. config.module
  96. .rule('svg')
  97. .exclude.add(resolve('src/icons'))
  98. .end()
  99. config.module
  100. .rule('icons')
  101. .test(/\.svg$/)
  102. .include.add(resolve('src/icons'))
  103. .end()
  104. .use('svg-sprite-loader')
  105. .loader('svg-sprite-loader')
  106. .options({
  107. symbolId: 'icon-[name]'
  108. })
  109. .end()
  110. config
  111. .when(process.env.NODE_ENV !== 'development',
  112. config => {
  113. config
  114. .plugin('ScriptExtHtmlWebpackPlugin')
  115. .after('html')
  116. .use('script-ext-html-webpack-plugin', [{
  117. // `runtime` must same as runtimeChunk name. default is `runtime`
  118. inline: /runtime\..*\.js$/
  119. }])
  120. .end()
  121. config
  122. .optimization.splitChunks({
  123. chunks: 'all',
  124. cacheGroups: {
  125. libs: {
  126. name: 'chunk-libs',
  127. test: /[\\/]node_modules[\\/]/,
  128. priority: 10,
  129. chunks: 'initial' // only package third parties that are initially dependent
  130. },
  131. elementUI: {
  132. name: 'chunk-elementUI', // split elementUI into a single package
  133. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  134. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  135. },
  136. commons: {
  137. name: 'chunk-commons',
  138. test: resolve('src/components'), // can customize your rules
  139. minChunks: 3, // minimum common number
  140. priority: 5,
  141. reuseExistingChunk: true
  142. }
  143. }
  144. })
  145. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  146. config.optimization.runtimeChunk('single')
  147. }
  148. )
  149. }
  150. }