vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const HOST = "http://fjopen.ndjsxh.cn:8888"
  5. // const HOST = "http://localhost:8000"
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || 'Rental Manage System' // page title
  10. // If your port is set to 80,
  11. // use administrator privileges to execute the command line.
  12. // For example, Mac: sudo npm run
  13. // You can change the port by the following method:
  14. // port = 9527 npm run dev OR npm run dev --port = 9527
  15. const port = process.env.port || process.env.npm_config_port || 8084 // dev port
  16. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  17. module.exports = {
  18. /**
  19. * You will need to set publicPath if you plan to deploy your site under a sub path,
  20. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  21. * then publicPath should be set to "/bar/".
  22. * In most cases please use '/' !!!
  23. * Detail: https://cli.vuejs.org/config/#publicpath
  24. */
  25. publicPath: '/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. lintOnSave: process.env.NODE_ENV === 'development',
  29. productionSourceMap: false,
  30. devServer: {
  31. port: port,
  32. open: true,
  33. overlay: {
  34. warnings: false,
  35. errors: true
  36. },
  37. proxy: {
  38. '/runtime': {
  39. target: HOST,
  40. changeOrigin: true,
  41. // pathRewrite: { '^/rental': '' },
  42. },
  43. '/fjopen': {
  44. target: HOST,
  45. changeOrigin: true,
  46. // pathRewrite: { '^/rental': '' },
  47. },
  48. '/upload': {
  49. target: HOST,
  50. changeOrigin: true,
  51. // pathRewrite: { '^/rental': '' },
  52. }
  53. },
  54. // before: require('./mock/mock-server.js')
  55. },
  56. configureWebpack: {
  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. // it can improve the speed of the first screen, it is recommended to turn on preload
  68. // it can improve the speed of the first screen, it is recommended to turn on preload
  69. config.plugin('preload').tap(() => [
  70. {
  71. rel: 'preload',
  72. // to ignore runtime.js
  73. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  74. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  75. include: 'initial'
  76. }
  77. ])
  78. // when there are many pages, it will cause too many meaningless requests
  79. config.plugins.delete('prefetch')
  80. // set svg-sprite-loader
  81. config.module
  82. .rule('svg')
  83. .exclude.add(resolve('src/icons'))
  84. .end()
  85. config.module
  86. .rule('icons')
  87. .test(/\.svg$/)
  88. .include.add(resolve('src/icons'))
  89. .end()
  90. .use('svg-sprite-loader')
  91. .loader('svg-sprite-loader')
  92. .options({
  93. symbolId: 'icon-[name]'
  94. })
  95. .end()
  96. config
  97. .when(process.env.NODE_ENV !== 'development',
  98. config => {
  99. config
  100. .plugin('ScriptExtHtmlWebpackPlugin')
  101. .after('html')
  102. .use('script-ext-html-webpack-plugin', [{
  103. // `runtime` must same as runtimeChunk name. default is `runtime`
  104. inline: /runtime\..*\.js$/
  105. }])
  106. .end()
  107. config
  108. .optimization.splitChunks({
  109. chunks: 'all',
  110. cacheGroups: {
  111. libs: {
  112. name: 'chunk-libs',
  113. test: /[\\/]node_modules[\\/]/,
  114. priority: 10,
  115. chunks: 'initial' // only package third parties that are initially dependent
  116. },
  117. elementUI: {
  118. name: 'chunk-elementUI', // split elementUI into a single package
  119. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  120. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  121. },
  122. commons: {
  123. name: 'chunk-commons',
  124. test: resolve('src/components'), // can customize your rules
  125. minChunks: 3, // minimum common number
  126. priority: 5,
  127. reuseExistingChunk: true
  128. }
  129. }
  130. })
  131. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  132. config.optimization.runtimeChunk('single')
  133. }
  134. )
  135. }
  136. // css: {
  137. // loaderOptions: {
  138. // css: {},
  139. // postcss: {
  140. // plugins: [
  141. // require('postcss-px2rem')({
  142. // remUnit: 37.5
  143. // })
  144. // ]
  145. // }
  146. // }
  147. // }
  148. }