vue.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. const port = 8000 // dev port
  12. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  13. module.exports = {
  14. /**
  15. * You will need to set publicPath if you plan to deploy your site under a sub path,
  16. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  17. * then publicPath should be set to "/bar/".
  18. * In most cases please use '/' !!!
  19. * Detail: https://cli.vuejs.org/config/#publicpath
  20. */
  21. publicPath: '/',
  22. outputDir: 'dist',
  23. assetsDir: 'static',
  24. lintOnSave: false,
  25. productionSourceMap: false,
  26. devServer: {
  27. port: port,
  28. open: true,
  29. overlay: {
  30. warnings: false,
  31. errors: true
  32. },
  33. proxy: {
  34. [process.env.VUE_APP_BASE_API]: {
  35. target: `https://www.workark.com/prod-api/admin-api`,
  36. changeOrigin: true, // target是域名的话,需要这个参数
  37. pathRewrite: ['^' + process.env.VUE_APP_BASE_API]: ''
  38. }
  39. }
  40. }
  41. },
  42. configureWebpack: {
  43. // provide the app's title in webpack's name field, so that
  44. // it can be accessed in index.html to inject the correct title.
  45. name: name,
  46. resolve: {
  47. alias: {
  48. '@': resolve('src')
  49. }
  50. }
  51. },
  52. chainWebpack(config) {
  53. config.plugins.delete('preload')
  54. config.plugins.delete('prefetch')
  55. // set svg-sprite-loader
  56. config.module
  57. .rule('svg')
  58. .exclude.add(resolve('src/icons'))
  59. .end()
  60. config.module
  61. .rule('icons')
  62. .test(/\.svg$/)
  63. .include.add(resolve('src/icons'))
  64. .end()
  65. .use('svg-sprite-loader')
  66. .loader('svg-sprite-loader')
  67. .options({
  68. symbolId: 'icon-[name]'
  69. })
  70. .end()
  71. // set preserveWhitespace
  72. config.module
  73. .rule('vue')
  74. .use('vue-loader')
  75. .loader('vue-loader')
  76. .tap(options => {
  77. options.compilerOptions.preserveWhitespace = true
  78. return options
  79. })
  80. .
  81. end()
  82. config
  83. // https://webpack.js.org/configuration/devtool/#development
  84. .when(process.env.NODE_ENV === 'development',
  85. config => config.devtool('cheap-source-map')
  86. )
  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. config.optimization.runtimeChunk('single')
  123. }
  124. )
  125. }
  126. }