vue.config.js 4.4 KB

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