vue.config.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. publicPath: '/vuepay2', //部署路径后缀
  8. assetsDir: 'static', // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  9. indexPath: 'index.html', // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径。
  10. filenameHashing: true, // 文件名hash,默认
  11. lintOnSave: false, // 开发环境下通过 eslint-loader 在每次保存时 lint 代码
  12. productionSourceMap: false, // 关闭生产环境的 source map
  13. devServer: {
  14. overlay: {
  15. // 让浏览器 overlay 同时显示警告和错误
  16. warnings: true,
  17. errors: true
  18. },
  19. //host: '172.16.120.200',
  20. host: '0.0.0.0',
  21. port: 8080, // 端口号
  22. // https: false, // https:{type:Boolean}
  23. open: true, // 配置自动启动浏览器
  24. hotOnly: true, // 热更新
  25. proxy: {
  26. // 配置多个跨域
  27. '/': {
  28. target: 'https://smartpark.caih.com/dxapi/', //东信
  29. //target: 'https://smartpark.caih.com/dxapi/', //本地
  30. changeOrigin: false,
  31. pathRewrite: {
  32. '': '/'
  33. }
  34. }
  35. },
  36. headers: {
  37. 'Access-Control-Allow-Origin': '*',
  38. }
  39. },
  40. configureWebpack: {
  41. performance: {
  42. hints: 'warning',
  43. // 入口起点的最大体积
  44. maxEntrypointSize: 50000000,
  45. // 生成文件的最大体积
  46. maxAssetSize: 30000000,
  47. // 只给出 js 文件的性能提示
  48. assetFilter: function(assetFilename) {
  49. return assetFilename.endsWith('.js')
  50. }
  51. }
  52. },
  53. css: {
  54. loaderOptions: {
  55. postcss: {
  56. plugins: [
  57. require('postcss-px-to-viewport')({
  58. unitToConvert: 'px', // 需要转换的单位,默认为"px"
  59. viewportWidth: 375, // 设计稿的视口宽度
  60. unitPrecision: 5, // 单位转换后保留的精度
  61. propList: ['*'], // 能转化为vw的属性列表
  62. viewportUnit: 'vw', // 希望使用的视口单位
  63. fontViewportUnit: 'vw', // 字体使用的视口单位
  64. selectorBlackList: [], // 需要忽略的CSS选择器
  65. minPixelValue: 1, // 最小的转换数值,如果为1的话,只有大于1的值会被转换
  66. mediaQuery: false, // 媒体查询里的单位是否需要转换单位
  67. replace: true, // 是否直接更换属性值,而不添加备用属性
  68. exclude: /node_modules/, // 忽略某些文件夹下的文件或特定文件
  69. include: undefined, // 如果设置了include,那将只有匹配到的文件才会被转换,例如只转换 'src/mobile' 下的文件 (include: /\/src\/mobile\//)
  70. landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
  71. landscapeUnit: 'vw', // 横屏时使用的单位
  72. landscapeWidth: 667 // 横屏时使用的视口宽度
  73. })
  74. ]
  75. }
  76. }
  77. },
  78. chainWebpack(config) {
  79. // it can improve the speed of the first screen, it is recommended to turn on preload
  80. config.plugin('preload').tap(() => [{
  81. rel: 'preload',
  82. // to ignore runtime.js
  83. // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
  84. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  85. include: 'initial'
  86. }])
  87. // when there are many pages, it will cause too many meaningless requests
  88. config.plugins.delete('prefetch')
  89. // set svg-sprite-loader
  90. config.module
  91. .rule('svg')
  92. .exclude.add(resolve('src/assets/icons'))
  93. .end()
  94. config.module
  95. .rule('icons')
  96. .test(/\.svg$/)
  97. .include.add(resolve('src/assets/icons'))
  98. .end()
  99. .use('svg-sprite-loader')
  100. .loader('svg-sprite-loader')
  101. .options({
  102. symbolId: 'icon-[name]'
  103. })
  104. .end()
  105. config
  106. .when(process.env.NODE_ENV !== 'development',
  107. config => {
  108. config
  109. .plugin('ScriptExtHtmlWebpackPlugin')
  110. .after('html')
  111. .use('script-ext-html-webpack-plugin', [{
  112. // `runtime` must same as runtimeChunk name. default is `runtime`
  113. inline: /runtime\..*\.js$/
  114. }])
  115. .end()
  116. config
  117. .optimization.splitChunks({
  118. chunks: 'all',
  119. cacheGroups: {
  120. libs: {
  121. name: 'chunk-libs',
  122. test: /[\\/]node_modules[\\/]/,
  123. priority: 10,
  124. chunks: 'initial' // only package third parties that are initially dependent
  125. },
  126. elementUI: {
  127. name: 'chunk-elementUI', // split elementUI into a single package
  128. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  129. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  130. },
  131. commons: {
  132. name: 'chunk-commons',
  133. test: resolve('src/components'), // can customize your rules
  134. minChunks: 3, // minimum common number
  135. priority: 5,
  136. reuseExistingChunk: true
  137. }
  138. }
  139. })
  140. // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
  141. config.optimization.runtimeChunk('single')
  142. }
  143. )
  144. }
  145. };