vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const port = 8080 // dev port
  7. const proxy_port = 8989
  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: false,
  22. devServer: {
  23. port: port,
  24. open: true,
  25. overlay: {
  26. warnings: false,
  27. errors: true
  28. },
  29. proxy: {
  30. // change xxx-api/login => mock/login
  31. // detail: https://cli.vuejs.org/config/#devserver-proxy
  32. // process.env.VUE_APP_BASE_API
  33. ['/']: {
  34. target: `http://47.111.250.197:${proxy_port}`,
  35. changeOrigin: true
  36. }
  37. }
  38. // after: require('./mock/mock-server.js')
  39. },
  40. configureWebpack: {
  41. // provide the app's title in webpack's name field, so that
  42. // it can be accessed in index.html to inject the correct title.
  43. name: 'title',
  44. resolve: {
  45. alias: {
  46. '@': resolve('src')
  47. }
  48. }
  49. },
  50. chainWebpack(config) {
  51. config.plugins.delete('preload') // TODO: need test
  52. config.plugins.delete('prefetch') // TODO: need test
  53. // set svg-sprite-loader
  54. config.module
  55. .rule('svg')
  56. .exclude.add(resolve('src/icons'))
  57. .end()
  58. config.module
  59. .rule('icons')
  60. .test(/\.svg$/)
  61. .include.add(resolve('src/icons'))
  62. .end()
  63. .use('svg-sprite-loader')
  64. .loader('svg-sprite-loader')
  65. .options({
  66. symbolId: 'icon-[name]'
  67. })
  68. .end()
  69. // set preserveWhitespace
  70. config.module
  71. .rule('vue')
  72. .use('vue-loader')
  73. .loader('vue-loader')
  74. .tap(options => {
  75. options.compilerOptions.preserveWhitespace = true
  76. return options
  77. })
  78. .end()
  79. config
  80. // https://webpack.js.org/configuration/devtool/#development
  81. .when(process.env.NODE_ENV === 'development',
  82. config => config.devtool('cheap-source-map')
  83. )
  84. config
  85. .when(process.env.NODE_ENV !== 'development',
  86. config => {
  87. config
  88. .plugin('ScriptExtHtmlWebpackPlugin')
  89. .after('html')
  90. .use('script-ext-html-webpack-plugin', [{
  91. // `runtime` must same as runtimeChunk name. default is `runtime`
  92. inline: /runtime\..*\.js$/
  93. }])
  94. .end()
  95. config
  96. .optimization.splitChunks({
  97. chunks: 'all',
  98. cacheGroups: {
  99. libs: {
  100. name: 'chunk-libs',
  101. test: /[\\/]node_modules[\\/]/,
  102. priority: 10,
  103. chunks: 'initial' // only package third parties that are initially dependent
  104. },
  105. elementUI: {
  106. name: 'chunk-elementUI', // split elementUI into a single package
  107. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  108. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  109. },
  110. commons: {
  111. name: 'chunk-commons',
  112. test: resolve('src/components'), // can customize your rules
  113. minChunks: 3, // minimum common number
  114. priority: 5,
  115. reuseExistingChunk: true
  116. }
  117. }
  118. })
  119. config.optimization.runtimeChunk('single')
  120. }
  121. )
  122. }
  123. }