vue.config.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 = defaultSettings.title || '智慧党建管理平台' // 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 methods:
  12. // port = 9528 npm run dev OR npm run dev --port = 9528
  13. const port = process.env.port || process.env.npm_config_port || 9528 // 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: '/ldb-pass-management/back',
  24. outputDir: 'back',
  25. assetsDir: 'static',
  26. lintOnSave: process.env.NODE_ENV === 'development',
  27. productionSourceMap: false,
  28. // devServer: {
  29. // port: port,
  30. // open: true,
  31. // overlay: {
  32. // warnings: false,
  33. // errors: true
  34. // },
  35. // // 关闭mock
  36. // // before: require('./mock/mock-server.js')
  37. // },
  38. devServer: {
  39. port: port,
  40. open: true,
  41. overlay: {
  42. warnings: false,
  43. errors: true
  44. },
  45. disableHostCheck: true, // 内网穿透
  46. // proxy: {
  47. // 第一台服务器配置
  48. // '/admin': {
  49. // target:'https://fyzd.gzdata.com.cn:9100/fyzd',//这里填写项目真实的后台接口地址
  50. // pathRewrite: { '^/admin': '/admin' },
  51. // changeOrigin: true //设置允许跨域
  52. // },
  53. // 第二台服务器配置
  54. // '/accessPhoto': {
  55. // // target: 'http://hanghui.oss-cn-gz-ysgzlt-d01-a.ltops.gzdata.com.cn',//这里填写项目真实的后台接口地址
  56. // target: 'https://www.xiaofeifeiwangyiping.com/yx-fyzd',//这里填写项目真实的后台接口地址
  57. // //这个重写不可省略!因为我们真正请求的地址包含 /rshy
  58. // pathRewrite: { '^/accessPhoto': '/' },
  59. // changeOrigin: true //设置允许跨域
  60. // }
  61. // },
  62. },
  63. configureWebpack: {
  64. // provide the app's title in webpack's name field, so that
  65. // it can be accessed in index.html to inject the correct title.
  66. devtool: process.env.NODE_ENV === 'development'?'source-map': false, // 关系到构建后行列信息映射到源码的信息
  67. name: name,
  68. resolve: {
  69. alias: {
  70. '@': resolve('src'),
  71. }
  72. }
  73. },
  74. chainWebpack(config) {
  75. // it can improve the speed of the first screen, it is recommended to turn on preload
  76. config.plugin('preload').tap(() => [
  77. {
  78. rel: 'preload',
  79. // to ignore runtime.js
  80. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  81. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  82. include: 'initial'
  83. }
  84. ])
  85. // when there are many pages, it will cause too many meaningless requests
  86. config.plugins.delete('prefetch')
  87. // set svg-sprite-loader
  88. config.module
  89. .rule('svg')
  90. .exclude.add(resolve('src/icons'))
  91. .end()
  92. config.module
  93. .rule('icons')
  94. .test(/\.svg$/)
  95. .include.add(resolve('src/icons'))
  96. .end()
  97. .use('svg-sprite-loader')
  98. .loader('svg-sprite-loader')
  99. .options({
  100. symbolId: 'icon-[name]'
  101. })
  102. .end()
  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. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  139. config.optimization.runtimeChunk('single')
  140. }
  141. )
  142. }
  143. }