vue.config.js 4.5 KB

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