vue.config.js 6.1 KB

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