vue.config.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. host: '0.0.0.0',
  48. disableHostCheck: true,
  49. open: false,
  50. overlay: {
  51. warnings: false,
  52. errors: true
  53. },
  54. proxy: {
  55. '/pb': {
  56. target: 'https://api.changyuntong56.com',
  57. // target: 'http://192.168.110.9:8099/',
  58. // target: 'http://192.168.110.138:8999/',
  59. // target: 'https://apitest.changyuntong56.com',
  60. changeOrigin: true, // 开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
  61. pathRewrite: {
  62. '^/pb': '/'
  63. }, // 这里重写路径
  64. secure: false,
  65. logLevel: 'debug'
  66. }
  67. }
  68. // https: true
  69. },
  70. configureWebpack: {
  71. // provide the app's title in webpack's name field, so that
  72. // it can be accessed in index.html to inject the correct title.
  73. name: name,
  74. resolve: {
  75. alias: {
  76. '@': resolve('src')
  77. }
  78. }
  79. },
  80. chainWebpack(config) {
  81. // it can improve the speed of the first screen, it is recommended to turn on preload
  82. config.plugin('preload').tap(() => [{
  83. rel: 'preload',
  84. // to ignore runtime.js
  85. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  86. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  87. include: 'initial'
  88. }])
  89. // when there are many pages, it will cause too many meaningless requests
  90. config.plugins.delete('prefetch')
  91. config.plugin('html')
  92. .tap(args => {
  93. args[0].cdn = cdn
  94. return args
  95. })
  96. // set svg-sprite-loader
  97. config.module
  98. .rule('svg')
  99. .exclude.add(resolve('src/icons'))
  100. .end()
  101. config.module
  102. .rule('icons')
  103. .test(/\.svg$/)
  104. .include.add(resolve('src/icons'))
  105. .end()
  106. .use('svg-sprite-loader')
  107. .loader('svg-sprite-loader')
  108. .options({
  109. symbolId: 'icon-[name]'
  110. })
  111. .end()
  112. config
  113. .when(process.env.NODE_ENV !== 'development',
  114. config => {
  115. config
  116. .plugin('ScriptExtHtmlWebpackPlugin')
  117. .after('html')
  118. .use('script-ext-html-webpack-plugin', [{
  119. // `runtime` must same as runtimeChunk name. default is `runtime`
  120. inline: /runtime\..*\.js$/
  121. }])
  122. .end()
  123. config
  124. .optimization.splitChunks({
  125. chunks: 'all',
  126. cacheGroups: {
  127. libs: {
  128. name: 'chunk-libs',
  129. test: /[\\/]node_modules[\\/]/,
  130. priority: 10,
  131. chunks: 'initial' // only package third parties that are initially dependent
  132. },
  133. elementUI: {
  134. name: 'chunk-elementUI', // split elementUI into a single package
  135. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  136. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  137. },
  138. commons: {
  139. name: 'chunk-commons',
  140. test: resolve('src/components'), // can customize your rules
  141. minChunks: 3, // minimum common number
  142. priority: 5,
  143. reuseExistingChunk: true
  144. }
  145. }
  146. })
  147. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  148. config.optimization.runtimeChunk('single')
  149. }
  150. )
  151. }
  152. }