rollup.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import replace from "@rollup/plugin-replace";
  2. import { terser } from "rollup-plugin-terser";
  3. import fs from "fs";
  4. const bundledTerserOptions = {
  5. compress: {
  6. unsafe: true,
  7. unsafe_arrows: true,
  8. unsafe_comps: true,
  9. unsafe_symbols: true,
  10. unsafe_proto: true,
  11. keep_fargs: false,
  12. passes: 3,
  13. ecma: "2020"
  14. }
  15. };
  16. const inlineTerserOptions = {
  17. compress: {
  18. unsafe: true,
  19. unsafe_arrows: true,
  20. unsafe_comps: true,
  21. unsafe_math: true,
  22. unsafe_symbols: true,
  23. unsafe_proto: true,
  24. keep_fargs: false,
  25. passes: 3,
  26. ecma: "2020"
  27. },
  28. mangle: {
  29. properties: {
  30. reserved: ["codecType", "config", "salt", "iterations", "keys", "password", "encryptionStrength", "encrypted", "signed", "compressed", "level", "zipCrypto", "passwordVerification"]
  31. }
  32. }
  33. };
  34. const GLOBALS = "const { Array, Object, String, BigInt, Math, Date, Map, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, FileReader, document, crypto, btoa } = globalThis;";
  35. const GLOBALS_WORKER = "const { Array, Object, Math, Error, Uint8Array, Uint16Array, Uint32Array, Int32Array, DataView, TextEncoder, crypto, postMessage } = globalThis;";
  36. export default [{
  37. input: "lib/z-worker.js",
  38. output: [{
  39. intro: GLOBALS_WORKER,
  40. file: "lib/z-worker-inline.js",
  41. format: "es",
  42. plugins: [terser(inlineTerserOptions)]
  43. }]
  44. }, {
  45. input: "lib/z-worker-inline-template.js",
  46. output: [{
  47. file: "lib/z-worker-inline.js",
  48. format: "es"
  49. }],
  50. plugins: [
  51. replace({
  52. preventAssignment: true,
  53. "__workerCode__": () => fs.readFileSync("lib/z-worker-inline.js").toString()
  54. }),
  55. terser(bundledTerserOptions)
  56. ]
  57. }, {
  58. input: ["lib/zip.js"],
  59. output: [{
  60. intro: GLOBALS,
  61. file: "dist/zip.min.js",
  62. format: "umd",
  63. name: "zip",
  64. plugins: [terser(bundledTerserOptions)]
  65. }, {
  66. intro: GLOBALS,
  67. file: "dist/zip.js",
  68. format: "umd",
  69. name: "zip"
  70. }]
  71. }, {
  72. input: ["lib/zip-full.js"],
  73. output: [{
  74. intro: GLOBALS,
  75. file: "dist/zip-full.min.js",
  76. format: "umd",
  77. name: "zip",
  78. plugins: [terser(bundledTerserOptions)]
  79. }, {
  80. intro: GLOBALS,
  81. file: "dist/zip-full.js",
  82. format: "umd",
  83. name: "zip"
  84. }]
  85. }, {
  86. input: "lib/zip-no-worker.js",
  87. output: [{
  88. intro: GLOBALS,
  89. file: "dist/zip-no-worker.min.js",
  90. format: "umd",
  91. name: "zip",
  92. plugins: [terser(bundledTerserOptions)]
  93. }]
  94. }, {
  95. input: "lib/zip-no-worker-deflate.js",
  96. output: [{
  97. intro: GLOBALS,
  98. file: "dist/zip-no-worker-deflate.min.js",
  99. format: "umd",
  100. name: "zip",
  101. plugins: [terser(bundledTerserOptions)]
  102. }]
  103. }, {
  104. input: "lib/zip-no-worker-inflate.js",
  105. output: [{
  106. intro: GLOBALS,
  107. file: "dist/zip-no-worker-inflate.min.js",
  108. format: "umd",
  109. name: "zip",
  110. plugins: [terser(bundledTerserOptions)]
  111. }]
  112. }, {
  113. input: "lib/zip-fs.js",
  114. output: [{
  115. intro: GLOBALS,
  116. file: "dist/zip-fs.min.js",
  117. format: "umd",
  118. name: "zip",
  119. plugins: [terser(bundledTerserOptions)]
  120. }, {
  121. intro: GLOBALS,
  122. file: "dist/zip-fs.js",
  123. format: "umd",
  124. name: "zip"
  125. }]
  126. }, {
  127. input: "index.js",
  128. output: [{
  129. intro: GLOBALS,
  130. file: "dist/zip-fs-full.min.js",
  131. format: "umd",
  132. name: "zip",
  133. plugins: [terser(bundledTerserOptions)]
  134. }, {
  135. intro: GLOBALS,
  136. file: "dist/zip-fs-full.js",
  137. format: "umd",
  138. name: "zip"
  139. }]
  140. }, {
  141. input: "lib/z-worker-bootstrap-pako.js",
  142. output: [{
  143. intro: GLOBALS_WORKER,
  144. file: "dist/z-worker-pako.js",
  145. format: "iife",
  146. plugins: [terser(bundledTerserOptions)]
  147. }]
  148. }, {
  149. input: "lib/z-worker-bootstrap-fflate.js",
  150. output: [{
  151. intro: GLOBALS_WORKER,
  152. file: "dist/z-worker-fflate.js",
  153. format: "iife",
  154. plugins: [terser(bundledTerserOptions)]
  155. }]
  156. }, {
  157. input: "lib/z-worker.js",
  158. output: [{
  159. intro: GLOBALS_WORKER,
  160. file: "dist/z-worker.js",
  161. format: "iife",
  162. plugins: [terser(bundledTerserOptions)]
  163. }]
  164. }];