vue.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 || 9527 // 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]: {
  46. // target: `http://127.0.0.1:${port}/mock`,
  47. target: 'https://localhost:9001',
  48. changeOrigin: true,
  49. pathRewrite: {
  50. ['^' + process.env.VUE_APP_BASE_API]: ''
  51. }
  52. }
  53. }
  54. },
  55. configureWebpack: {
  56. // provide the app's title in webpack's name field, so that
  57. // it can be accessed in index.html to inject the correct title.
  58. name: name,
  59. resolve: {
  60. alias: {
  61. '@': resolve('src/main/frontend')
  62. }
  63. }
  64. },
  65. chainWebpack(config) {
  66. config.plugins.delete('preload') // TODO: need test
  67. config.plugins.delete('prefetch') // TODO: need test
  68. // set svg-sprite-loader
  69. config.module
  70. .rule('svg')
  71. .exclude.add(resolve('src/main/frontend/icons'))
  72. .end()
  73. config.module
  74. .rule('icons')
  75. .test(/\.svg$/)
  76. .include.add(resolve('src/main/frontend/icons'))
  77. .end()
  78. .use('svg-sprite-loader')
  79. .loader('svg-sprite-loader')
  80. .options({
  81. symbolId: 'icon-[name]'
  82. })
  83. .end()
  84. // set preserveWhitespace
  85. config.module
  86. .rule('vue')
  87. .use('vue-loader')
  88. .loader('vue-loader')
  89. .tap(options => {
  90. options.compilerOptions.preserveWhitespace = true
  91. return options
  92. })
  93. .end()
  94. config
  95. // https://webpack.js.org/configuration/devtool/#development
  96. .when(process.env.NODE_ENV === 'development',
  97. config => config.devtool('cheap-source-map')
  98. )
  99. config
  100. .when(process.env.NODE_ENV !== 'development',
  101. config => {
  102. config
  103. .plugin('ScriptExtHtmlWebpackPlugin')
  104. .after('html')
  105. .use('script-ext-html-webpack-plugin', [{
  106. // `runtime` must same as runtimeChunk name. default is `runtime`
  107. inline: /runtime\..*\.js$/
  108. }])
  109. .end()
  110. /* config
  111. .optimization.splitChunks({
  112. chunks: 'all',
  113. cacheGroups: {
  114. libs: {
  115. name: 'chunk-libs',
  116. test: /[\\/]node_modules[\\/]/,
  117. priority: 10,
  118. chunks: 'initial' // only package third parties that are initially dependent
  119. },
  120. elementUI: {
  121. name: 'chunk-elementUI', // split elementUI into a single package
  122. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  123. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  124. },
  125. commons: {
  126. name: 'chunk-commons',
  127. test: resolve('src/main/frontend/components'), // can customize your rules
  128. minChunks: 3, // minimum common number
  129. priority: 5,
  130. reuseExistingChunk: true
  131. }
  132. }
  133. })
  134. config.optimization.runtimeChunk('single')*/
  135. }
  136. )
  137. }
  138. }