25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

vue.config.js 6.6 KiB

2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 Element Admin' // 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 method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  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: 'static',
  26. lintOnSave: process.env.NODE_ENV === 'development',
  27. productionSourceMap: false,
  28. devServer: {
  29. port: port,
  30. open: false,
  31. overlay: {
  32. warnings: false,
  33. errors: true
  34. },
  35. // allowedHosts: ['192.168.0.104:8080', '192.168.0.104:8081'],
  36. // headers: {
  37. // 'Access-Control-Allow-Origin': '192.168.0.104:8080, 192.168.0.104:8081',
  38. // 'Access-Control-Allow-Headers': '*',
  39. // 'Access-Control-Allow-Methods': '*',
  40. // 'Access-Control-Allow-Credentials': 'true'
  41. // },
  42. // before: require('./mock/mock-server.js'),
  43. // 这里写入需要代理的api和对应的目标地址
  44. proxy: {
  45. '/api': {
  46. // target: 'http://localhost:8080',
  47. // target: 'http://192.168.1.38:8080',
  48. target: 'http://a.wms.picaiba.com',
  49. // target: 'http://192.168.0.127:8080',
  50. // target: 'http://192.168.0.165:8080',
  51. // target: 'http://192.168.43.105:8080',
  52. // target: 'http://127.0.0.1:8080',
  53. // target: 'http://192.168.0.70:8080',
  54. // target: 'http://192.168.0.199:8080',
  55. ws: true,
  56. changeOrigin: true,
  57. pathRewrite: {
  58. '^/api': ''
  59. }
  60. // 使用了proxy 就需要开启下面的选项 (http-proxy-middleware会将post请求给parse了 所以需要再次进行string化)
  61. // onProxyReq: (proxyReq, req, res, options) => {
  62. // if (req.body) {
  63. // const bodyData = JSON.stringify(req.body)
  64. // // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
  65. // proxyReq.setHeader('Content-Type', 'application/json')
  66. // proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
  67. // // stream the content
  68. // proxyReq.write(bodyData)
  69. // }
  70. // }
  71. },
  72. '/spc': {
  73. // target: 'http://192.168.0.180:8080',
  74. target: 'http://58.210.206.230:8000',
  75. // target: 'http://192.168.0.187:8080',
  76. // target: 'http://192.168.43.105:8080',
  77. // target: 'http://127.0.0.1:8080',
  78. ws: true,
  79. changeOrigin: true,
  80. pathRewrite: {
  81. '^/spc': ''
  82. }
  83. // 使用了proxy 就需要开启下面的选项 (http-proxy-middleware会将post请求给parse了 所以需要再次进行string化)
  84. // onProxyReq: (proxyReq, req, res, options) => {
  85. // if (req.body) {
  86. // const bodyData = JSON.stringify(req.body)
  87. // // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
  88. // proxyReq.setHeader('Content-Type', 'application/json')
  89. // proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
  90. // // stream the content
  91. // proxyReq.write(bodyData)
  92. // }
  93. // }
  94. }
  95. }
  96. },
  97. configureWebpack: {
  98. // provide the app's title in webpack's name field, so that
  99. // it can be accessed in index.html to inject the correct title.
  100. name: name,
  101. resolve: {
  102. alias: {
  103. '@': resolve('src')
  104. }
  105. }
  106. },
  107. css: {
  108. loaderOptions: {
  109. // vue cli默认使用node-sass作为sass预处理器,使用下面的选项可以使用sass包作为预处理器
  110. // 用于解决node-sass需要从外网下载依赖的卡顿问题
  111. sass: {
  112. implementation: require('sass')
  113. }
  114. }
  115. },
  116. chainWebpack(config) {
  117. config.plugins.delete('preload') // TODO: need test
  118. config.plugins.delete('prefetch') // TODO: need test
  119. // set svg-sprite-loader
  120. config.module
  121. .rule('svg')
  122. .exclude.add(resolve('src/icons'))
  123. .end()
  124. config.module
  125. .rule('icons')
  126. .test(/\.svg$/)
  127. .include.add(resolve('src/icons'))
  128. .end()
  129. .use('svg-sprite-loader')
  130. .loader('svg-sprite-loader')
  131. .options({
  132. symbolId: 'icon-[name]'
  133. })
  134. .end()
  135. // set preserveWhitespace
  136. config.module
  137. .rule('vue')
  138. .use('vue-loader')
  139. .loader('vue-loader')
  140. .tap(options => {
  141. options.compilerOptions.preserveWhitespace = true
  142. return options
  143. })
  144. .end()
  145. config
  146. .when(process.env.NODE_ENV !== 'development',
  147. config => {
  148. config
  149. .plugin('ScriptExtHtmlWebpackPlugin')
  150. .after('html')
  151. .use('script-ext-html-webpack-plugin', [{
  152. // `runtime` must same as runtimeChunk name. default is `runtime`
  153. inline: /runtime\..*\.js$/
  154. }])
  155. .end()
  156. config
  157. .optimization.splitChunks({
  158. chunks: 'all',
  159. cacheGroups: {
  160. libs: {
  161. name: 'chunk-libs',
  162. test: /[\\/]node_modules[\\/]/,
  163. priority: 10,
  164. chunks: 'initial' // only package third parties that are initially dependent
  165. },
  166. elementUI: {
  167. name: 'chunk-elementUI', // split elementUI into a single package
  168. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  169. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  170. },
  171. commons: {
  172. name: 'chunk-commons',
  173. test: resolve('src/components'), // can customize your rules
  174. minChunks: 3, // minimum common number
  175. priority: 5,
  176. reuseExistingChunk: true
  177. }
  178. }
  179. })
  180. config.optimization.runtimeChunk('single')
  181. }
  182. )
  183. }
  184. }