vue.config.js 4.8 KB

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