vue.config.js 5.4 KB

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