vue.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 || '管理后台' // page title
  8. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  9. module.exports = {
  10. /**
  11. * You will need to set publicPath if you plan to deploy your site under a sub path,
  12. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  13. * then publicPath should be set to "/bar/".
  14. * In most cases please use '/' !!!
  15. * Detail: https://cli.vuejs.org/config/#publicpath
  16. */
  17. publicPath: '/',
  18. outputDir: 'dist',
  19. assetsDir: 'static',
  20. lintOnSave: process.env.NODE_ENV === 'development',
  21. productionSourceMap: process.env.BUILD_ENV === 'development',
  22. devServer: {
  23. port: 8080,
  24. open: true,
  25. host: '0.0.0.0',
  26. overlay: {
  27. warnings: false,
  28. errors: true
  29. },
  30. // before: require('./mock/mock-server.js')
  31. proxy: {
  32. '/api/auth': {
  33. target: 'http://tingbang-auth.codedreamit.com',
  34. changeOrigin: true,
  35. pathRewrite: {
  36. '^/api/auth': '/api/auth'
  37. }
  38. }
  39. }
  40. },
  41. configureWebpack: {
  42. // provide the app's title in webpack's name field, so that
  43. // it can be accessed in index.html to inject the correct title.
  44. name: name,
  45. resolve: {
  46. alias: {
  47. '@': resolve('src')
  48. }
  49. }
  50. },
  51. css: {
  52. loaderOptions: {
  53. sass: {
  54. prependData: `@import "@/styles/var.scss";`
  55. }
  56. }
  57. },
  58. chainWebpack (config) {
  59. // it can improve the speed of the first screen, it is recommended to turn on preload
  60. config.plugin('preload').tap(() => [
  61. {
  62. rel: 'preload',
  63. // to ignore runtime.js
  64. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  65. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  66. include: 'initial'
  67. }
  68. ])
  69. // when there are many pages, it will cause too many meaningless requests
  70. config.plugins.delete('prefetch')
  71. // set svg-sprite-loader
  72. config.module
  73. .rule('svg')
  74. .exclude.add(resolve('src/icons'))
  75. .end()
  76. config.module
  77. .rule('icons')
  78. .test(/\.svg$/)
  79. .include.add(resolve('src/icons'))
  80. .end()
  81. .use('svg-sprite-loader')
  82. .loader('svg-sprite-loader')
  83. .options({
  84. symbolId: 'icon-[name]'
  85. })
  86. .end()
  87. config
  88. .when(process.env.NODE_ENV !== 'development',
  89. config => {
  90. config
  91. .plugin('ScriptExtHtmlWebpackPlugin')
  92. .after('html')
  93. .use('script-ext-html-webpack-plugin', [{
  94. // `runtime` must same as runtimeChunk name. default is `runtime`
  95. inline: /runtime\..*\.js$/
  96. }])
  97. .end()
  98. config
  99. .optimization.splitChunks({
  100. chunks: 'all',
  101. cacheGroups: {
  102. libs: {
  103. name: 'chunk-libs',
  104. test: /[\\/]node_modules[\\/]/,
  105. priority: 10,
  106. chunks: 'initial' // only package third parties that are initially dependent
  107. },
  108. elementUI: {
  109. name: 'chunk-elementUI', // split elementUI into a single package
  110. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  111. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  112. },
  113. commons: {
  114. name: 'chunk-commons',
  115. test: resolve('src/components'), // can customize your rules
  116. minChunks: 3, // minimum common number
  117. priority: 5,
  118. reuseExistingChunk: true
  119. }
  120. }
  121. })
  122. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  123. config.optimization.runtimeChunk('single')
  124. }
  125. )
  126. }
  127. }