vue.config.js 7.2 KB

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