-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathafter-build.js
30 lines (22 loc) · 855 Bytes
/
after-build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from "fs";
fixCjsExport();
createPackageJsonFiles();
function fixCjsExport() {
let cjsContent = fs.readFileSync("./dist/cjs/index.js", "utf8");
// Make sure the CommonJS build can be imported without using .default
cjsContent = cjsContent.replace("exports.default = ", "module.exports = ");
cjsContent = cjsContent.replace('Object.defineProperty(exports, "__esModule", { value: true });', "");
fs.writeFileSync("./dist/cjs/index.js", cjsContent);
}
function createPackageJsonFiles() {
// Create package.json for CommonJS
const cjsPackageJson = {
type: "commonjs"
};
fs.writeFileSync("./dist/cjs/package.json", JSON.stringify(cjsPackageJson, null, 2));
// Create package.json for ES modules
const mjsPackageJson = {
type: "module"
};
fs.writeFileSync("./dist/esm/package.json", JSON.stringify(mjsPackageJson, null, 2));
}