vue.config.js 4.7 KB

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