compression.js 861 B

1234567891011121314151617181920212223242526272829
  1. import compression from 'vite-plugin-compression'
  2. export default function createCompression(env) {
  3. const {VITE_BUILD_COMPRESS} = env
  4. const plugin = []
  5. console.debug(VITE_BUILD_COMPRESS);
  6. if (VITE_BUILD_COMPRESS) {
  7. const compressList = VITE_BUILD_COMPRESS.split(',')
  8. if (compressList.includes('gzip')) {
  9. // 静的ファイルを解凍する方法
  10. plugin.push(
  11. compression({
  12. ext: '.gz',
  13. deleteOriginFile: false
  14. })
  15. )
  16. }
  17. if (compressList.includes('brotli')) {
  18. plugin.push(
  19. compression({
  20. ext: '.br',
  21. algorithm: 'brotliCompress',
  22. deleteOriginFile: false
  23. })
  24. )
  25. }
  26. }
  27. return plugin
  28. }