vue.config.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = '病案数据治理与服务管理平台' // page title
  8. // If your port is set to 80,
  9. // use administrator privileges to execute the command line.
  10. // For example, Mac: sudo npm run
  11. // You can change the port by the following method:
  12. // port = 9527 npm run dev OR npm run dev --port = 9527
  13. const port = process.env.port || process.env.npm_config_port || 9527 // dev port
  14. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  15. module.exports = {
  16. /**
  17. * You will need to set publicPath if you plan to deploy your site under a sub path,
  18. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  19. * then publicPath should be set to "/bar/".
  20. * In most cases please use '/' !!!
  21. * Detail: https://cli.vuejs.org/config/#publicpath
  22. */
  23. publicPath: './',
  24. outputDir: 'dist',
  25. assetsDir: 'static',
  26. lintOnSave: process.env.NODE_ENV === 'development',
  27. productionSourceMap: false,
  28. transpileDependencies: ['element-ui'],
  29. css: {
  30. loaderOptions: {
  31. scss: {
  32. prependData: `@import "@/styles/variables.scss";`, // 不同版本的 sass,此属性不同:data、prependData、additionalData
  33. sassOptions: { outputStyle: 'expanded' } // fix: 解决 element-ui 图标 icon 偶现乱码问题
  34. }
  35. }
  36. },
  37. devServer: {
  38. proxy: {
  39. [process.env.VUE_APP_BASE_API]: {
  40. target: 'http://182.44.10.206:8083',
  41. changeOrigin: true,
  42. pathRewrite: {
  43. ['^' + process.env.VUE_APP_BASE_API]: '/admin/'
  44. }
  45. },
  46. [process.env.VUE_APP_BASE_API2]: {
  47. target: 'http://182.44.10.206:8083',
  48. changeOrigin: true,
  49. pathRewrite: {
  50. ['^' + process.env.VUE_APP_BASE_API2]: '/bazb/'
  51. }
  52. },
  53. [process.env.VUE_APP_BASE_API3]: {
  54. target: 'http://182.44.10.206:8083',
  55. changeOrigin: true,
  56. pathRewrite: {
  57. ['^' + process.env.VUE_APP_BASE_API3]: '/api/'
  58. }
  59. },
  60. },
  61. port: port,
  62. open: true,
  63. overlay: {
  64. warnings: false,
  65. errors: true
  66. },
  67. // before: require('./mock/mock-server.js')
  68. },
  69. configureWebpack: {
  70. // provide the app's title in webpack's name field, so that
  71. // it can be accessed in index.html to inject the correct title.
  72. name: name,
  73. resolve: {
  74. alias: {
  75. '@': resolve('src')
  76. }
  77. }
  78. },
  79. chainWebpack(config) {
  80. // it can improve the speed of the first screen, it is recommended to turn on preload
  81. // it can improve the speed of the first screen, it is recommended to turn on preload
  82. config.plugin('preload').tap(() => [
  83. {
  84. rel: 'preload',
  85. // to ignore runtime.js
  86. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  87. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  88. include: 'initial'
  89. }
  90. ])
  91. // when there are many pages, it will cause too many meaningless requests
  92. config.plugins.delete('prefetch')
  93. // set svg-sprite-loader
  94. config.module
  95. .rule('svg')
  96. .exclude.add(resolve('src/icons'))
  97. .end()
  98. config.module
  99. .rule('icons')
  100. .test(/\.svg$/)
  101. .include.add(resolve('src/icons'))
  102. .end()
  103. .use('svg-sprite-loader')
  104. .loader('svg-sprite-loader')
  105. .options({
  106. symbolId: 'icon-[name]'
  107. })
  108. .end()
  109. // set preserveWhitespace
  110. config.module
  111. .rule('vue')
  112. .use('vue-loader')
  113. .loader('vue-loader')
  114. .tap(options => {
  115. options.compilerOptions.preserveWhitespace = true
  116. return options
  117. })
  118. .end()
  119. config
  120. .when(process.env.NODE_ENV !== 'development',
  121. config => {
  122. config
  123. .plugin('ScriptExtHtmlWebpackPlugin')
  124. .after('html')
  125. .use('script-ext-html-webpack-plugin', [{
  126. // `runtime` must same as runtimeChunk name. default is `runtime`
  127. inline: /runtime\..*\.js$/
  128. }])
  129. .end()
  130. config
  131. .optimization.splitChunks({
  132. chunks: 'all',
  133. cacheGroups: {
  134. libs: {
  135. name: 'chunk-libs',
  136. test: /[\\/]node_modules[\\/]/,
  137. priority: 10,
  138. chunks: 'initial' // only package third parties that are initially dependent
  139. },
  140. elementUI: {
  141. name: 'chunk-elementUI', // split elementUI into a single package
  142. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  143. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  144. },
  145. commons: {
  146. name: 'chunk-commons',
  147. test: resolve('src/components'), // can customize your rules
  148. minChunks: 3, // minimum common number
  149. priority: 5,
  150. reuseExistingChunk: true
  151. }
  152. }
  153. })
  154. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  155. config.optimization.runtimeChunk('single')
  156. }
  157. )
  158. }
  159. }