From 81e38e4a0343ab3b7beafae1ac08014ba5ba5de9 Mon Sep 17 00:00:00 2001 From: Alex Cruikshank <169613+acruikshank@users.noreply.github.com> Date: Tue, 13 Jul 2021 12:54:31 -0400 Subject: [PATCH] add cjs and ejm builds (#21) Co-authored-by: acruikshank --- esbuild.js | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/esbuild.js b/esbuild.js index e38398ab..d17665ed 100644 --- a/esbuild.js +++ b/esbuild.js @@ -1,26 +1,41 @@ +const esbuild = require('esbuild') const path = require("path") const {compressionBrowserPlugin, wasmPlugin} = require("./esbuild-plugins"); // esbuild has TypeScript support by default -const outfile = 'parquet-bundle.min.js' -require('esbuild') - .build({ - bundle: true, - entryPoints: ['parquet.js'], - outdir: path.resolve(__dirname, "dist","browser"), - define: { - "process.env.NODE_DEBUG": false, - "process.env.NODE_ENV": "\"production\"", - global: "window" - }, +const baseConfig = { + bundle: true, + entryPoints: ['parquet.js'], + define: { + "process.env.NODE_DEBUG": false, + "process.env.NODE_ENV": "\"production\"", + global: "window" + }, + inject: ['./esbuild-shims.js'], + minify: true, + platform: 'browser', // default + plugins: [compressionBrowserPlugin, wasmPlugin], + target: "es2020" // default +}; +const targets = [ + { + ...baseConfig, globalName: 'parquetjs', - inject: ['./esbuild-shims.js'], - minify: true, - platform: 'browser', // default - plugins: [compressionBrowserPlugin, wasmPlugin], - target: "esnext" // default - }) - .then(res => { - if (!res.warnings.length) { + outdir: path.resolve(__dirname, "dist","browser"), + }, + { + ...baseConfig, + format: "esm", + outfile: path.resolve(__dirname, "dist","browser","parquet.esm.js"), + }, + { + ...baseConfig, + format: "cjs", + outfile: path.resolve(__dirname, "dist","browser","parquet.cjs.js"), + } +] +Promise.all(targets.map(esbuild.build)) + .then(results => { + if (results.reduce((m,r)=>m && !r.warnings.length, true)) { console.log("built with no errors or warnings") } })