vue.config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 || 'ferry' // 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. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
  15. const target = 'https://mantest.dayaedu.com'
  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: 'web',
  27. assetsDir: 'static/web',
  28. lintOnSave: false, // 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. // change xxx-api/login => mock/login
  39. // detail: https://cli.vuejs.org/config/#devserver-proxy
  40. // http://47.99.212.176:8000
  41. // http://192.168.3.28:8000
  42. // http://192.168.3.134
  43. // http://47.114.176.40:8000
  44. // let target = 'http://dev.dayaedu.com'
  45. // 'http://dev.dayaedu.com'
  46. '/api-auth': {
  47. target: target,
  48. // target : target,
  49. changeOrigin: true,
  50. pathRewrite: {
  51. '^api-auth': ''
  52. }
  53. },
  54. '/api-task': {
  55. target: target,
  56. changeOrigin: true,
  57. pathRewrite: {
  58. '^api-task': ''
  59. }
  60. },
  61. '/api-oa': {
  62. target: target,
  63. changeOrigin: true,
  64. pathRewrite: {
  65. '^api-task': ''
  66. }
  67. },
  68. '/api-web': {
  69. target: target,
  70. changeOrigin: true,
  71. pathRewrite: {
  72. '^api-web': ''
  73. }
  74. },
  75. '/api-cms': {
  76. target: target,
  77. changeOrigin: true,
  78. pathRewrite: {
  79. '^api-cms': ''
  80. }
  81. },
  82. '/api-teacher': {
  83. target: target,
  84. changeOrigin: true,
  85. pathRewrite: {
  86. '^api-teacher': ''
  87. }
  88. },
  89. '/jiari': {
  90. target: 'http://tool.bitefu.net',
  91. changeOrigin: true
  92. },
  93. },
  94. },
  95. configureWebpack: {
  96. plugins: [
  97. new MonacoWebpackPlugin()
  98. ],
  99. name: name,
  100. resolve: {
  101. alias: {
  102. '@': resolve('src')
  103. }
  104. }
  105. },
  106. chainWebpack(config) {
  107. config.plugins.delete('preload') // TODO: need test
  108. config.plugins.delete('prefetch') // TODO: need test
  109. // set svg-sprite-loader
  110. config.module
  111. .rule('svg')
  112. .exclude.add(resolve('src/icons'))
  113. .end()
  114. config.module
  115. .rule('icons')
  116. .test(/\.svg$/)
  117. .include.add(resolve('src/icons'))
  118. .end()
  119. .use('svg-sprite-loader')
  120. .loader('svg-sprite-loader')
  121. .options({
  122. symbolId: 'icon-[name]'
  123. })
  124. .end()
  125. // set preserveWhitespace
  126. config.module
  127. .rule('vue')
  128. .use('vue-loader')
  129. .loader('vue-loader')
  130. .tap(options => {
  131. options.compilerOptions.preserveWhitespace = true
  132. return options
  133. })
  134. .end()
  135. config
  136. // https://webpack.js.org/configuration/devtool/#development
  137. .when(process.env.NODE_ENV === 'development',
  138. config => config.devtool('cheap-source-map')
  139. )
  140. config
  141. .when(process.env.NODE_ENV !== 'development',
  142. config => {
  143. config
  144. .plugin('ScriptExtHtmlWebpackPlugin')
  145. .after('html')
  146. .use('script-ext-html-webpack-plugin', [{
  147. // `runtime` must same as runtimeChunk name. default is `runtime`
  148. inline: /runtime\..*\.js$/
  149. }])
  150. .end()
  151. config
  152. .optimization.splitChunks({
  153. chunks: 'all',
  154. cacheGroups: {
  155. libs: {
  156. name: 'chunk-libs',
  157. test: /[\\/]node_modules[\\/]/,
  158. priority: 10,
  159. chunks: 'initial' // only package third parties that are initially dependent
  160. },
  161. elementUI: {
  162. name: 'chunk-elementUI', // split elementUI into a single package
  163. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  164. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  165. },
  166. commons: {
  167. name: 'chunk-commons',
  168. test: resolve('src/components'), // can customize your rules
  169. minChunks: 3, // minimum common number
  170. priority: 5,
  171. reuseExistingChunk: true
  172. }
  173. }
  174. })
  175. config.optimization.runtimeChunk('single')
  176. }
  177. )
  178. }
  179. }