You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

207 lines
7.0 KiB

  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://192.168.1.25:8080', // tong wanghao
  47. // target: 'http://192.168.1.65:8080/',
  48. // target: 'http://192.168.0.88',
  49. target: 'http://hfxny.mes.picaiba.com',
  50. // target: 'http://192.168.1.49:8080', // tong wanghao
  51. // target: 'http://192.168.1.67:8080',
  52. // target: 'http://192.168.0.165:8080',
  53. // target: 'http://192.168.43.105:8080',
  54. // target: 'http://127.0.0.1:8080',
  55. // target: 'http://192.168.0.70:8080',
  56. // target: 'http://192.168.0.199:8080',
  57. ws: true,
  58. changeOrigin: true,
  59. pathRewrite: {
  60. '^/portapi': ''
  61. }
  62. // 使用了proxy 就需要开启下面的选项 (http-proxy-middleware会将post请求给parse了 所以需要再次进行string化)
  63. // onProxyReq: (proxyReq, req, res, options) => {
  64. // if (req.body) {
  65. // const bodyData = JSON.stringify(req.body)
  66. // // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
  67. // proxyReq.setHeader('Content-Type', 'application/json')
  68. // proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
  69. // // stream the content
  70. // proxyReq.write(bodyData)
  71. // }
  72. // }
  73. },
  74. '/spc': {
  75. target: 'http://58.210.206.230:8000',
  76. // target: 'http://192.168.0.187:8080',
  77. // target: 'http://192.168.43.105:8080',
  78. // target: 'http://127.0.0.1:8080',
  79. ws: true,
  80. changeOrigin: true,
  81. pathRewrite: {
  82. '^/spc': ''
  83. }
  84. // 使用了proxy 就需要开启下面的选项 (http-proxy-middleware会将post请求给parse了 所以需要再次进行string化)
  85. // onProxyReq: (proxyReq, req, res, options) => {
  86. // if (req.body) {
  87. // const bodyData = JSON.stringify(req.body)
  88. // // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
  89. // proxyReq.setHeader('Content-Type', 'application/json')
  90. // proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
  91. // // stream the content
  92. // proxyReq.write(bodyData)
  93. // }
  94. // }
  95. }
  96. }
  97. },
  98. configureWebpack: {
  99. // provide the app's title in webpack's name field, so that
  100. // it can be accessed in index.html to inject the correct title.
  101. name: name,
  102. resolve: {
  103. alias: {
  104. '@': resolve('src')
  105. }
  106. }
  107. },
  108. css: {
  109. loaderOptions: {
  110. // vue cli默认使用node-sass作为sass预处理器,使用下面的选项可以使用sass包作为预处理器
  111. // 用于解决node-sass需要从外网下载依赖的卡顿问题
  112. sass: {
  113. implementation: require('sass')
  114. }
  115. }
  116. },
  117. chainWebpack(config) {
  118. config.plugins.delete('preload') // TODO: need test
  119. config.plugins.delete('prefetch') // TODO: need test
  120. // 配置加载 xlsx 文件
  121. config.module
  122. .rule('excel')
  123. .test(/\.xlsx$/)
  124. .use('file-loader')
  125. .loader('file-loader')
  126. .end()
  127. // set svg-sprite-loader
  128. config.module
  129. .rule('svg')
  130. .exclude.add(resolve('src/icons'))
  131. .end()
  132. config.module
  133. .rule('file-loader')
  134. .test(/\.(mkv)(\?.*)?$/)
  135. .use('file-loader')
  136. .loader('file-loader')
  137. .end()
  138. config.module
  139. .rule('icons')
  140. .test(/\.svg$/)
  141. .include.add(resolve('src/icons'))
  142. .end()
  143. .use('svg-sprite-loader')
  144. .loader('svg-sprite-loader')
  145. .options({
  146. symbolId: 'icon-[name]'
  147. })
  148. .end()
  149. // set preserveWhitespace
  150. config.module
  151. .rule('vue')
  152. .use('vue-loader')
  153. .loader('vue-loader')
  154. .tap(options => {
  155. options.compilerOptions.preserveWhitespace = true
  156. return options
  157. })
  158. .end()
  159. config
  160. .when(process.env.NODE_ENV !== 'development',
  161. config => {
  162. config
  163. .plugin('ScriptExtHtmlWebpackPlugin')
  164. .after('html')
  165. .use('script-ext-html-webpack-plugin', [{
  166. // `runtime` must same as runtimeChunk name. default is `runtime`
  167. inline: /runtime\..*\.js$/
  168. }])
  169. .end()
  170. config
  171. .optimization.splitChunks({
  172. chunks: 'all',
  173. cacheGroups: {
  174. libs: {
  175. name: 'chunk-libs',
  176. test: /[\\/]node_modules[\\/]/,
  177. priority: 10,
  178. chunks: 'initial' // only package third parties that are initially dependent
  179. },
  180. elementUI: {
  181. name: 'chunk-elementUI', // split elementUI into a single package
  182. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  183. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  184. },
  185. commons: {
  186. name: 'chunk-commons',
  187. test: resolve('src/components'), // can customize your rules
  188. minChunks: 3, // minimum common number
  189. priority: 5,
  190. reuseExistingChunk: true
  191. }
  192. }
  193. })
  194. config.optimization.runtimeChunk('single')
  195. }
  196. )
  197. }
  198. }