vue.config.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. '/bi-api': {
  70. target: define.BIAPIURl,
  71. changeOrigin: true,
  72. pathRewrite: {
  73. '^/bi-api': ''
  74. }
  75. }
  76. }
  77. },
  78. configureWebpack: {
  79. // provide the app's title in webpack's name field, so that
  80. // it can be accessed in index.html to inject the correct title.
  81. name: name,
  82. resolve: {
  83. alias: {
  84. '@': resolve('src'),
  85. 'static': resolve('static') // 增加这一行代码
  86. }
  87. },
  88. plugins: [
  89. new MonacoWebpackPlugin({
  90. // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
  91. languages: ['javascript', 'css', 'html', 'typescript', 'json', 'java', 'sql']
  92. })
  93. ]
  94. },
  95. chainWebpack(config) {
  96. config.externals({
  97. // 'monaco-editor': 'monaco-editor',
  98. 'echarts': 'echarts'
  99. })
  100. // it can improve the speed of the first screen, it is recommended to turn on preload
  101. config.plugin('preload').tap(() => [{
  102. rel: 'preload',
  103. // to ignore runtime.js
  104. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  105. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  106. include: 'initial'
  107. }])
  108. // when there are many pages, it will cause too many meaningless requests
  109. config.plugins.delete('prefetch')
  110. // set svg-sprite-loader
  111. config.module
  112. .rule('svg')
  113. .exclude.add(resolve('src/icons'))
  114. .end()
  115. config.module
  116. .rule('icons')
  117. .test(/\.svg$/)
  118. .include.add(resolve('src/icons'))
  119. .end()
  120. .use('svg-sprite-loader')
  121. .loader('svg-sprite-loader')
  122. .options({
  123. symbolId: 'icon-[name]'
  124. })
  125. .end()
  126. config
  127. // https://webpack.js.org/configuration/devtool/#development
  128. .when(process.env.NODE_ENV === 'development',
  129. config => config.devtool('cheap-source-map')
  130. )
  131. config
  132. .when(process.env.NODE_ENV !== 'development',
  133. config => {
  134. config
  135. .plugin('ScriptExtHtmlWebpackPlugin')
  136. .after('html')
  137. .use('script-ext-html-webpack-plugin', [{
  138. // `runtime` must same as runtimeChunk name. default is `runtime`
  139. inline: /runtime\..*\.js$/
  140. }])
  141. .end()
  142. config
  143. .optimization.splitChunks({
  144. chunks: 'all',
  145. cacheGroups: {
  146. libs: {
  147. name: 'chunk-libs',
  148. test: /[\\/]node_modules[\\/]/,
  149. priority: 10,
  150. chunks: 'initial' // only package third parties that are initially dependent
  151. },
  152. elementUI: {
  153. name: 'chunk-elementUI', // split elementUI into a single package
  154. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  155. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  156. },
  157. commons: {
  158. name: 'chunk-commons',
  159. test: resolve('src/components'), // can customize your rules
  160. minChunks: 3, // minimum common number
  161. priority: 5,
  162. reuseExistingChunk: true
  163. }
  164. }
  165. })
  166. config.optimization.runtimeChunk('single')
  167. }
  168. )
  169. }
  170. }