vue.config.js 5.5 KB

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