選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

153 行
4.9KB

  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. // You can change the port by the following methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. const port = process.env.port || process.env.npm_config_port || 9528 // 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: process.env.NODE_ENV === 'production' ? './' : '/',
  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. // 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. target: `http://47.115.164.183:8086/`,
  41. // target: 'http://192.168.1.169:8086/',
  42. changeOrigin: true,
  43. pathRewrite: {
  44. ['^' + process.env.VUE_APP_BASE_API]: ''
  45. }
  46. },
  47. '/video-admin/qq': {
  48. // target: `http://127.0.0.1:${port}/mock`,
  49. // target: `http://localhost:3000/`,
  50. target: 'https://vv.video.qq.com/',
  51. changeOrigin: true,
  52. pathRewrite: {
  53. '^/qq': ''
  54. }
  55. }
  56. // '/uploader': {
  57. // target: 'https://jsonplaceholder.typicode.com/posts/',
  58. // changeOrigin: true,
  59. // pathRewrite: {
  60. // '^/uploader': ''
  61. // }
  62. // }
  63. }
  64. // before: require('./mock/mock-server.js')
  65. },
  66. configureWebpack: {
  67. // provide the app's title in webpack's name field, so that
  68. // it can be accessed in index.html to inject the correct title.
  69. name: name,
  70. resolve: {
  71. alias: {
  72. '@': resolve('src')
  73. }
  74. }
  75. },
  76. chainWebpack(config) {
  77. // it can improve the speed of the first screen, it is recommended to turn on preload
  78. // config.plugins.delete('preload')
  79. config.plugin('preload').tap(() => [
  80. {
  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. ])
  88. // when there are many pages, it will cause too many meaningless requests
  89. config.plugins.delete('prefetch')
  90. // set svg-sprite-loader
  91. config.module
  92. .rule('svg')
  93. .exclude.add(resolve('src/icons'))
  94. .end()
  95. config.module
  96. .rule('icons')
  97. .test(/\.svg$/)
  98. .include.add(resolve('src/icons'))
  99. .end()
  100. .use('svg-sprite-loader')
  101. .loader('svg-sprite-loader')
  102. .options({
  103. symbolId: 'icon-[name]'
  104. })
  105. .end()
  106. config
  107. .when(process.env.NODE_ENV !== 'development',
  108. config => {
  109. config
  110. .plugin('ScriptExtHtmlWebpackPlugin')
  111. .after('html')
  112. .use('script-ext-html-webpack-plugin', [{
  113. // `runtime` must same as runtimeChunk name. default is `runtime`
  114. inline: /runtime\..*\.js$/
  115. }])
  116. .end()
  117. config
  118. .optimization.splitChunks({
  119. chunks: 'all',
  120. cacheGroups: {
  121. libs: {
  122. name: 'chunk-libs',
  123. test: /[\\/]node_modules[\\/]/,
  124. priority: 10,
  125. chunks: 'initial' // only package third parties that are initially dependent
  126. },
  127. elementUI: {
  128. name: 'chunk-elementUI', // split elementUI into a single package
  129. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  130. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  131. },
  132. commons: {
  133. name: 'chunk-commons',
  134. test: resolve('src/components'), // can customize your rules
  135. minChunks: 3, // minimum common number
  136. priority: 5,
  137. reuseExistingChunk: true
  138. }
  139. }
  140. })
  141. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  142. config.optimization.runtimeChunk('single')
  143. }
  144. )
  145. }
  146. }