rollup-es5.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { babel } from "@rollup/plugin-babel";
  2. import resolve from "@rollup/plugin-node-resolve";
  3. import commonjs from "@rollup/plugin-commonjs";
  4. import replace from "@rollup/plugin-replace";
  5. import { terser } from "rollup-plugin-terser";
  6. import fs from "fs";
  7. const bundledTerserOptions = {
  8. compress: {
  9. unsafe: true,
  10. unsafe_comps: true,
  11. unsafe_symbols: true,
  12. unsafe_proto: true,
  13. keep_fargs: false,
  14. passes: 3,
  15. ecma: "5"
  16. }
  17. };
  18. const inlineTerserOptions = {
  19. compress: {
  20. unsafe: true,
  21. unsafe_comps: true,
  22. unsafe_math: true,
  23. unsafe_symbols: true,
  24. unsafe_proto: true,
  25. keep_fargs: false,
  26. passes: 3,
  27. ecma: "5"
  28. },
  29. mangle: {
  30. properties: {
  31. reserved: ["codecType", "config", "salt", "iterations", "keys", "password", "encryptionStrength", "encrypted", "signed", "compressed", "level", "zipCrypto", "passwordVerification"]
  32. }
  33. }
  34. };
  35. const babelPresets = [
  36. [
  37. "@babel/preset-env",
  38. {
  39. corejs: 3,
  40. modules: false,
  41. useBuiltIns: "usage",
  42. targets: {
  43. ie: "11",
  44. safari: "10"
  45. }
  46. }
  47. ]
  48. ];
  49. const bundledPlugins = [
  50. commonjs(),
  51. resolve(),
  52. babel({
  53. babelHelpers: "bundled",
  54. babelrc: false,
  55. exclude: "node_modules/**",
  56. presets: babelPresets,
  57. compact: false,
  58. plugins: [["babel-plugin-transform-async-to-promises", { externalHelpers: true }]]
  59. })
  60. ];
  61. const inlinePlugins = [
  62. commonjs(),
  63. resolve(),
  64. babel({
  65. babelHelpers: "inline",
  66. babelrc: false,
  67. exclude: "node_modules/**",
  68. presets: babelPresets,
  69. compact: false
  70. })
  71. ];
  72. export default [{
  73. input: "lib/z-worker.js",
  74. output: [{
  75. file: "lib/z-worker-inline.js",
  76. format: "es",
  77. plugins: [terser(inlineTerserOptions)]
  78. }],
  79. plugins: inlinePlugins
  80. }, {
  81. input: "lib/z-worker-inline-template-base64.js",
  82. output: [{
  83. file: "lib/z-worker-inline.js",
  84. format: "es"
  85. }],
  86. plugins: [
  87. replace({
  88. preventAssignment: true,
  89. "__workerCode__": () => JSON.stringify(fs.readFileSync("lib/z-worker-inline.js", { encoding: "base64" }))
  90. }),
  91. terser(bundledTerserOptions)
  92. ]
  93. }, {
  94. input: ["lib/zip.js"],
  95. output: [{
  96. file: "dist/zip-es5.min.js",
  97. format: "umd",
  98. name: "zip",
  99. plugins: [terser(bundledTerserOptions)]
  100. }, {
  101. file: "dist/zip-es5.js",
  102. format: "umd",
  103. name: "zip"
  104. }],
  105. plugins: bundledPlugins
  106. }, {
  107. input: ["lib/zip-full.js"],
  108. output: [{
  109. file: "dist/zip-full-es5.min.js",
  110. format: "umd",
  111. name: "zip",
  112. plugins: [terser(bundledTerserOptions)]
  113. }, {
  114. file: "dist/zip-full-es5.js",
  115. format: "umd",
  116. name: "zip"
  117. }],
  118. plugins: bundledPlugins
  119. }, {
  120. input: "lib/zip-no-worker.js",
  121. output: [{
  122. file: "dist/zip-no-worker-es5.min.js",
  123. format: "umd",
  124. name: "zip",
  125. plugins: [terser(bundledTerserOptions)]
  126. }],
  127. plugins: bundledPlugins
  128. }, {
  129. input: "lib/zip-no-worker-deflate.js",
  130. output: [{
  131. file: "dist/zip-no-worker-deflate-es5.min.js",
  132. format: "umd",
  133. name: "zip",
  134. plugins: [terser(bundledTerserOptions)]
  135. }],
  136. plugins: bundledPlugins
  137. }, {
  138. input: "lib/zip-no-worker-inflate.js",
  139. output: [{
  140. file: "dist/zip-no-worker-inflate-es5.min.js",
  141. format: "umd",
  142. name: "zip",
  143. plugins: [terser(bundledTerserOptions)]
  144. }],
  145. plugins: bundledPlugins
  146. }, {
  147. input: "lib/zip-fs.js",
  148. output: [{
  149. file: "dist/zip-fs-es5.min.js",
  150. format: "umd",
  151. name: "zip",
  152. plugins: [terser(bundledTerserOptions)]
  153. }, {
  154. file: "dist/zip-fs-es5.js",
  155. format: "umd",
  156. name: "zip"
  157. }],
  158. plugins: bundledPlugins
  159. }, {
  160. input: "index.js",
  161. output: [{
  162. file: "dist/zip-fs-full-es5.min.js",
  163. format: "umd",
  164. name: "zip",
  165. plugins: [terser(bundledTerserOptions)]
  166. }, {
  167. file: "dist/zip-fs-full-es5.js",
  168. format: "umd",
  169. name: "zip"
  170. }],
  171. plugins: bundledPlugins
  172. }, {
  173. input: "lib/z-worker-bootstrap-pako.js",
  174. output: [{
  175. file: "dist/z-worker-pako-es5.js",
  176. format: "iife",
  177. plugins: [terser(bundledTerserOptions)]
  178. }],
  179. plugins: inlinePlugins
  180. }, {
  181. input: "lib/z-worker-bootstrap-fflate.js",
  182. output: [{
  183. file: "dist/z-worker-fflate-es5.js",
  184. format: "iife",
  185. plugins: [terser(bundledTerserOptions)]
  186. }],
  187. plugins: inlinePlugins
  188. }, {
  189. input: "lib/z-worker.js",
  190. output: [{
  191. file: "dist/z-worker-es5.js",
  192. format: "iife",
  193. plugins: [terser(bundledTerserOptions)]
  194. }],
  195. plugins: inlinePlugins
  196. }];