From 83ef26ead14ff7164e3cc66efc4c497d797717c6 Mon Sep 17 00:00:00 2001 From: Xmader Date: Sun, 1 Dec 2019 16:25:13 -0500 Subject: [PATCH] include worker --- .gitignore | 2 + package.json | 1 + rollup.config.js | 119 ++++++++++++++++++++++++++++------------------- 3 files changed, 73 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index bc1e25f..38e321f 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,5 @@ typings/ package-lock.json 1.* + +dist/cache diff --git a/package.json b/package.json index 85ba9bc..3897bcc 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@types/pdfkit": "^0.10.4", "rollup": "^1.26.3", "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-multi-entry": "^2.1.0", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-node-resolve": "^5.2.0", diff --git a/rollup.config.js b/rollup.config.js index 412d94f..60e9184 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,6 +5,7 @@ import builtins from "rollup-plugin-node-builtins" import nodeGlobals from "rollup-plugin-node-globals" import json from "@rollup/plugin-json" import fs from "fs" +import multiEntry from "rollup-plugin-multi-entry" const getBannerText = () => { const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8")) @@ -14,54 +15,74 @@ const getBannerText = () => { return bannerText } -export default { - input: "src/main.ts", - output: { - file: "dist/main.js", - format: "iife", - sourcemap: false, - banner: getBannerText, - // 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" - }, - plugins: [ - typescript({ - target: "ES6", - sourceMap: false, - allowJs: true, - lib: [ - "ES6", - "dom" - ], - }), - resolve({ - preferBuiltins: true, - jsnext: true, - extensions: [".js", ".ts"] - }), - commonjs({ - extensions: [".js", ".ts"] - }), - json(), - builtins(), - nodeGlobals({ - dirname: false, - filename: false, - baseDir: false, - }), - { - /** - * remove tslib license comments - * @param {string} code - * @param {string} id - */ - transform(code, id) { - if (id.includes("tslib")) { - code = code.split(/\r?\n/g).slice(15).join("\n") - } - return { - code - } +const plugins = [ + typescript({ + target: "ES6", + sourceMap: false, + allowJs: true, + lib: [ + "ES6", + "dom" + ], + }), + resolve({ + preferBuiltins: true, + jsnext: true, + extensions: [".js", ".ts"] + }), + commonjs({ + extensions: [".js", ".ts"] + }), + json(), + builtins(), + nodeGlobals({ + dirname: false, + filename: false, + baseDir: false, + }), + { + /** + * remove tslib license comments + * @param {string} code + * @param {string} id + */ + transform(code, id) { + if (id.includes("tslib")) { + code = code.split(/\r?\n/g).slice(15).join("\n") } + return { + code + } + } + }, +] + +export default [ + { + input: "src/worker.ts", + output: { + file: "dist/cache/worker.js", + format: "iife", + name: "PDFWorker", + sourcemap: false, }, - ] -} + plugins, + }, + { + input: [ + "dist/cache/worker.js", + "src/main.ts", + ], + output: { + file: "dist/main.js", + format: "iife", + sourcemap: false, + banner: getBannerText, + // 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" + }, + plugins:[ + ...plugins, + multiEntry({ exports: false }), + ], + }, +]