feat: build for esm

This commit is contained in:
Marton Lederer 2021-02-20 14:14:52 +01:00
parent 07ef3b6771
commit fd7bc89fe0
No known key found for this signature in database
GPG Key ID: 9B7FD44832ADFE95
2 changed files with 17 additions and 14 deletions

View File

@ -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");
});
})();

View File

@ -23,6 +23,7 @@
"dist"
],
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"dependencies": {
"autoprefixer": "^10.2.4",