From fd7bc89fe02504a037803add5a32a2d80ccca6b9 Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Sat, 20 Feb 2021 14:14:52 +0100 Subject: [PATCH] feat: build for esm --- build.js | 30 ++++++++++++++++-------------- package.json | 1 + 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build.js b/build.js index 45dc869..1aca7ec 100644 --- a/build.js +++ b/build.js @@ -1,19 +1,21 @@ const { build } = require("esbuild"), { copyFile } = require("fs"); -const production = process.env.NODE_ENV === "production"; +const production = process.env.NODE_ENV === "production", + formats = ["cjs", "esm"]; -build({ - entryPoints: ["./src/index.ts"], - watch: !production, - format: "cjs", - outfile: `./dist/index.js` -}) - .then(() => { - // copy module declarations - copyFile("./src/modules.d.ts", "./dist/modules.d.ts", (err) => { - if (err) throw err; - console.log("[modules.d.ts] copied"); +(async () => { + for (const format of formats) { + await build({ + entryPoints: ["./src/index.ts"], + watch: !production, + format, + outfile: `./dist/index${format === "cjs" ? "" : "." + format}.js` }); - }) - .catch(() => process.exit(1)); + } + + copyFile("./src/modules.d.ts", "./dist/modules.d.ts", (err) => { + if (err) throw err; + console.log("[modules.d.ts] copied"); + }); +})(); diff --git a/package.json b/package.json index 6836106..8ef895b 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "dist" ], "main": "dist/index.js", + "module": "dist/index.esm.js", "types": "dist/index.d.ts", "dependencies": { "autoprefixer": "^10.2.4",