From b8ce97e7393cfcc1500141a59d1321315d63c7ca Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 11 Sep 2020 10:44:08 +0200 Subject: [PATCH] remove duplicate code in build script --- scripts/build.mjs | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index bda86d33..c6c37b96 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -203,7 +203,7 @@ async function buildJs(inputFile, outputName) { return bundlePath; } -async function buildJsLegacy(inputFile, outputName) { +async function buildJsLegacy(inputFile, outputName, polyfillFile = null) { // compile down to whatever IE 11 needs const babelPlugin = babel.babel({ babelHelpers: 'bundled', @@ -219,9 +219,12 @@ async function buildJsLegacy(inputFile, outputName) { ] ] }); + if (!polyfillFile) { + polyfillFile = 'src/legacy-polyfill.js'; + } // create js bundle const rollupConfig = { - input: ['src/legacy-polyfill.js', inputFile], + input: [polyfillFile, inputFile], plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})] }; const bundle = await rollup(rollupConfig); @@ -235,36 +238,9 @@ async function buildJsLegacy(inputFile, outputName) { return bundlePath; } -async function buildWorkerJsLegacy(inputFile, outputName) { - // compile down to whatever IE 11 needs - const babelPlugin = babel.babel({ - babelHelpers: 'bundled', - exclude: 'node_modules/**', - presets: [ - [ - "@babel/preset-env", - { - useBuiltIns: "entry", - corejs: "3", - targets: "IE 11" - } - ] - ] - }); - // create js bundle - const rollupConfig = { - input: ['src/worker-polyfill.js', inputFile], - plugins: [multi(), commonjs(), nodeResolve(), babelPlugin, removeJsComments({comments: "none"})] - }; - const bundle = await rollup(rollupConfig); - const {output} = await bundle.generate({ - format: 'iife', - name: `${PROJECT_ID}Bundle` - }); - const code = output[0].code; - const bundlePath = resource(outputName, code); - await fs.writeFile(bundlePath, code, "utf8"); - return bundlePath; +function buildWorkerJsLegacy(inputFile, outputName) { + const polyfillFile = 'src/worker-polyfill.js'; + return buildJsLegacy(inputFile, outputName, polyfillFile); } async function buildOffline(version, assetPaths) {