vue.config.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const define = require('./src/utils/define.js')
  5. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || '数字化运营平台' // 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 = 3000 npm run dev OR npm run dev --port = 3000
  15. const port = 1888 // 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: '/work/',
  26. outputDir: 'dist',
  27. assetsDir: 'static',
  28. // lintOnSave: process.env.NODE_ENV === 'development',
  29. lintOnSave: false,
  30. productionSourceMap: false,
  31. devServer: {
  32. port: port,
  33. open: false,
  34. overlay: {
  35. warnings: false,
  36. errors: true
  37. },
  38. // before: require('./mock/mock-server.js'),
  39. // 接口转发
  40. proxy: {
  41. '/api': {
  42. target: define.APIURl,
  43. changeOrigin: true,
  44. pathRewrite: {
  45. '^/api': ''
  46. }
  47. },
  48. // '/paas': {
  49. // target: define.WLAPIURl,
  50. // changeOrigin: true,
  51. // pathRewrite: {
  52. // '^/paas': ''
  53. // }
  54. // },
  55. '/visual-api': {
  56. target: define.CSAPIURl,
  57. changeOrigin: true,
  58. pathRewrite: {
  59. '^/visual-api': ''
  60. }
  61. },
  62. '/flow-api': {
  63. target: define.FlowAPIURl,
  64. changeOrigin: true,
  65. pathRewrite: {
  66. '^/flow-api': ''
  67. }
  68. },
  69. '/nocode-api': {
  70. target: define.NOAPIURl,
  71. changeOrigin: true,
  72. pathRewrite: {
  73. '^/nocode-api': ''
  74. }
  75. },
  76. '/bi-api': {
  77. target: define.BIAPIURl,
  78. changeOrigin: true,
  79. pathRewrite: {
  80. '^/bi-api': ''
  81. }
  82. }
  83. }
  84. },
  85. configureWebpack: {
  86. // provide the app's title in webpack's name field, so that
  87. // it can be accessed in index.html to inject the correct title.
  88. name: name,
  89. resolve: {
  90. alias: {
  91. '@': resolve('src'),
  92. 'static': resolve('static') // 增加这一行代码
  93. }
  94. },
  95. plugins: [
  96. new MonacoWebpackPlugin({
  97. // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
  98. languages: ['javascript', 'css', 'html', 'typescript', 'json', 'java', 'sql']
  99. })
  100. ]
  101. },
  102. chainWebpack(config) {
  103. config.externals({
  104. // 'monaco-editor': 'monaco-editor',
  105. 'echarts': 'echarts'
  106. })
  107. // it can improve the speed of the first screen, it is recommended to turn on preload
  108. config.plugin('preload').tap(() => [{
  109. rel: 'preload',
  110. // to ignore runtime.js
  111. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  112. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  113. include: 'initial'
  114. }])
  115. // when there are many pages, it will cause too many meaningless requests
  116. config.plugins.delete('prefetch')
  117. // set svg-sprite-loader
  118. config.module
  119. .rule('svg')
  120. .exclude.add(resolve('src/icons'))
  121. .end()
  122. config.module
  123. .rule('icons')
  124. .test(/\.svg$/)
  125. .include.add(resolve('src/icons'))
  126. .end()
  127. .use('svg-sprite-loader')
  128. .loader('svg-sprite-loader')
  129. .options({
  130. symbolId: 'icon-[name]'
  131. })
  132. .end()
  133. config
  134. // https://webpack.js.org/configuration/devtool/#development
  135. .when(process.env.NODE_ENV === 'development',
  136. config => config.devtool('cheap-source-map')
  137. )
  138. config
  139. .when(process.env.NODE_ENV !== 'development',
  140. config => {
  141. config
  142. .plugin('ScriptExtHtmlWebpackPlugin')
  143. .after('html')
  144. .use('script-ext-html-webpack-plugin', [{
  145. // `runtime` must same as runtimeChunk name. default is `runtime`
  146. inline: /runtime\..*\.js$/
  147. }])
  148. .end()
  149. config
  150. .optimization.splitChunks({
  151. chunks: 'all',
  152. cacheGroups: {
  153. libs: {
  154. name: 'chunk-libs',
  155. test: /[\\/]node_modules[\\/]/,
  156. priority: 10,
  157. chunks: 'initial' // only package third parties that are initially dependent
  158. },
  159. elementUI: {
  160. name: 'chunk-elementUI', // split elementUI into a single package
  161. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  162. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  163. },
  164. commons: {
  165. name: 'chunk-commons',
  166. test: resolve('src/components'), // can customize your rules
  167. minChunks: 3, // minimum common number
  168. priority: 5,
  169. reuseExistingChunk: true
  170. }
  171. }
  172. })
  173. config.optimization.runtimeChunk('single')
  174. }
  175. )
  176. }
  177. }