rollup.config.js (2257B)
1 import typescript from "rollup-plugin-typescript" 2 import resolve from "rollup-plugin-node-resolve" 3 import commonjs from "rollup-plugin-commonjs" 4 import builtins from "rollup-plugin-node-builtins" 5 import nodeGlobals from "rollup-plugin-node-globals" 6 import json from "@rollup/plugin-json" 7 import fs from "fs" 8 9 const getBannerText = () => { 10 const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8")) 11 const { version } = packageJson 12 let bannerText = fs.readFileSync("./src/meta.js", "utf-8") 13 bannerText = bannerText.replace("%VERSION%", version) 14 return bannerText 15 } 16 17 const plugins = [ 18 typescript({ 19 target: "ES6", 20 sourceMap: false, 21 allowJs: true, 22 lib: [ 23 "ES6", 24 "dom" 25 ], 26 }), 27 resolve({ 28 preferBuiltins: true, 29 jsnext: true, 30 extensions: [".js", ".ts"] 31 }), 32 commonjs({ 33 extensions: [".js", ".ts"] 34 }), 35 json(), 36 builtins(), 37 nodeGlobals({ 38 dirname: false, 39 filename: false, 40 baseDir: false, 41 }), 42 { 43 /** 44 * remove tslib license comments 45 * @param {string} code 46 * @param {string} id 47 */ 48 transform(code, id) { 49 if (id.includes("tslib")) { 50 code = code.split(/\r?\n/g).slice(15).join("\n") 51 } 52 return { 53 code 54 } 55 } 56 }, 57 ] 58 59 export default [ 60 { 61 input: "src/worker.ts", 62 output: { 63 file: "dist/cache/worker.js", 64 format: "iife", 65 name: "Worker", 66 banner: "export const PDFWorker = function () { ", 67 footer: "return Worker\n}\n", 68 sourcemap: false, 69 }, 70 plugins, 71 }, 72 { 73 input: "src/main.ts", 74 output: { 75 file: "dist/main.js", 76 format: "iife", 77 sourcemap: false, 78 banner: getBannerText, 79 // intro: "const global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof commonjsGlobal === 'object' && commonjsGlobal.global === commonjsGlobal ? commonjsGlobal : void 0" 80 }, 81 plugins, 82 }, 83 ]