vue.config.js 5.5 KB

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