vue.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 port = 9528 // dev port
  9. module.exports = {
  10. publicPath: '/',
  11. outputDir: 'dist',
  12. assetsDir: 'static',
  13. lintOnSave: process.env.NODE_ENV === 'development',
  14. productionSourceMap: false,
  15. devServer: {
  16. port: port,
  17. disableHostCheck: true,
  18. open: true,
  19. overlay: {
  20. warnings: false,
  21. errors: true
  22. },
  23. disableHostCheck: true, // webpack4.0 开启热更新
  24. proxy: {
  25. [process.env.VUE_APP_BASE_API]: {
  26. target: `http://127.0.0.1:${port}/mock`,
  27. changeOrigin: true,
  28. pathRewrite: {
  29. ['^' + process.env.VUE_APP_BASE_API]: ''
  30. }
  31. }
  32. }
  33. },
  34. configureWebpack: {
  35. name: name,
  36. resolve: {
  37. alias: {
  38. '@': resolve('src')
  39. }
  40. }
  41. },
  42. chainWebpack(config) {
  43. config.plugins.delete('preload') // TODO: need test
  44. config.plugins.delete('prefetch') // TODO: need test
  45. config.module
  46. .rule('svg')
  47. .exclude.add(resolve('src/icons'))
  48. .end()
  49. config.module
  50. .rule('icons')
  51. .test(/\.svg$/)
  52. .include.add(resolve('src/icons'))
  53. .end()
  54. .use('svg-sprite-loader')
  55. .loader('svg-sprite-loader')
  56. .options({
  57. symbolId: 'icon-[name]'
  58. })
  59. .end()
  60. config.module
  61. .rule('vue')
  62. .use('vue-loader')
  63. .loader('vue-loader')
  64. .tap(options => {
  65. options.compilerOptions.preserveWhitespace = true
  66. return options
  67. })
  68. .end()
  69. config
  70. .when(process.env.NODE_ENV === 'development',
  71. config => config.devtool('cheap-source-map')
  72. )
  73. config
  74. .when(process.env.NODE_ENV !== 'development',
  75. config => {
  76. config
  77. .plugin('ScriptExtHtmlWebpackPlugin')
  78. .after('html')
  79. .use('script-ext-html-webpack-plugin', [{
  80. inline: /runtime\..*\.js$/
  81. }])
  82. .end()
  83. config
  84. .optimization.splitChunks({
  85. chunks: 'all',
  86. cacheGroups: {
  87. libs: {
  88. name: 'chunk-libs',
  89. test: /[\\/]node_modules[\\/]/,
  90. priority: -10,
  91. chunks: 'initial' // only package third parties that are initially dependent
  92. }
  93. }
  94. })
  95. config.optimization.runtimeChunk('single')
  96. }
  97. )
  98. }
  99. }