2019-11-03 19:13:06 +00:00
import typescript from "rollup-plugin-typescript"
2019-12-01 07:10:51 +00:00
import resolve from "rollup-plugin-node-resolve"
import commonjs from "rollup-plugin-commonjs"
import builtins from "rollup-plugin-node-builtins"
2019-12-01 08:57:54 +00:00
import nodeGlobals from "rollup-plugin-node-globals"
2019-12-01 07:10:51 +00:00
import json from "@rollup/plugin-json"
2020-11-12 17:13:14 +00:00
import { string } from "rollup-plugin-string"
2019-11-03 19:13:06 +00:00
import fs from "fs"
2019-11-03 20:01:29 +00:00
const getBannerText = ( ) => {
const packageJson = JSON . parse ( fs . readFileSync ( "./package.json" , "utf-8" ) )
const { version } = packageJson
let bannerText = fs . readFileSync ( "./src/meta.js" , "utf-8" )
bannerText = bannerText . replace ( "%VERSION%" , version )
return bannerText
}
2019-11-03 19:13:06 +00:00
2020-11-24 18:11:19 +00:00
const basePlugins = [
2019-12-01 21:25:13 +00:00
typescript ( {
target : "ES6" ,
sourceMap : false ,
allowJs : true ,
lib : [
"ES6" ,
"dom"
] ,
} ) ,
resolve ( {
preferBuiltins : true ,
jsnext : true ,
extensions : [ ".js" , ".ts" ]
} ) ,
commonjs ( {
extensions : [ ".js" , ".ts" ]
} ) ,
json ( ) ,
2020-11-12 17:13:14 +00:00
string ( {
include : "**/*.css" ,
} ) ,
2019-12-01 21:25:13 +00:00
{
/ * *
* remove tslib license comments
* @ param { string } code
* @ param { string } id
* /
2020-11-12 17:13:14 +00:00
transform ( code , id ) {
2019-12-01 21:25:13 +00:00
if ( id . includes ( "tslib" ) ) {
code = code . split ( /\r?\n/g ) . slice ( 15 ) . join ( "\n" )
}
return {
code
2019-12-01 09:38:26 +00:00
}
2019-12-01 21:25:13 +00:00
}
} ,
]
2020-11-24 18:11:19 +00:00
const plugins = [
... basePlugins ,
builtins ( ) ,
nodeGlobals ( {
dirname : false ,
filename : false ,
baseDir : false ,
} ) ,
]
2019-12-01 21:25:13 +00:00
export default [
{
input : "src/worker.ts" ,
output : {
file : "dist/cache/worker.js" ,
format : "iife" ,
2019-12-01 21:45:38 +00:00
banner : "export const PDFWorker = function () { " ,
2020-04-28 06:46:21 +00:00
footer : "}\n" ,
2019-12-01 21:25:13 +00:00
sourcemap : false ,
2019-12-01 09:38:26 +00:00
} ,
2019-12-01 21:25:13 +00:00
plugins ,
} ,
{
2019-12-01 21:45:38 +00:00
input : "src/main.ts" ,
2019-12-01 21:25:13 +00:00
output : {
file : "dist/main.js" ,
format : "iife" ,
sourcemap : false ,
banner : getBannerText ,
2020-12-04 01:55:49 +00:00
intro : "new Promise(resolve=>{const id=''+Math.random();(typeof unsafeWindow=='object'?unsafeWindow:window)[id]=resolve;setTimeout(`window['${id}'](new Image())`)}).then(d=>{d.style.display='none';d.src='data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';d.once=false;d.setAttribute('onload','if(this.once)return;this.once=true;this.remove();(' + function a () {" ,
outro : "}.toString() + ')()');document.body.prepend(d)})"
2019-12-01 21:25:13 +00:00
} ,
2019-12-01 21:45:38 +00:00
plugins ,
2019-12-01 21:25:13 +00:00
} ,
2020-11-24 18:11:19 +00:00
{
input : "src/cli.ts" ,
output : {
file : "dist/cli.js" ,
format : "cjs" ,
2020-11-24 23:01:03 +00:00
banner : "#!/usr/bin/env node" ,
2020-11-24 18:11:19 +00:00
sourcemap : false ,
} ,
plugins : basePlugins ,
} ,
2019-12-01 21:25:13 +00:00
]