-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostbuild.js
39 lines (32 loc) · 1.1 KB
/
postbuild.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
31
32
33
34
35
36
37
38
39
import path from 'path';
import fs from 'fs-extra';
// eslint-disable-next-line no-undef
const packagePath = process.cwd();
const buildPath = path.join(packagePath, './build');
const packageJsonData = await fs.readFile(path.resolve(packagePath, './package.json'), 'utf8');
const packageJson = JSON.parse(packageJsonData);
// Modify the package.json object
packageJson.main = 'cjs/index.js';
packageJson.module = 'index.js';
packageJson.types = 'index.d.ts';
packageJson.exports = {
'.': {
import: './index.js',
require: './cjs/index.js'
},
'./*.js': {
import: './*.js',
require: './cjs/*.js'
},
'./*': {
import: './*.js',
require: './cjs/*.js'
}
};
// Remove devDependencies
delete packageJson.devDependencies;
delete packageJson.scripts;
// Write the modified package.json to the build folder
fs.writeJsonSync(path.resolve(buildPath, './package.json'), packageJson, { spaces: 2 });
fs.writeJsonSync(path.resolve(path.join(buildPath, 'cjs'), './package.json'), { "type": "commonjs" }, { spaces: 2 });
console.log('package.json has been modified and copied to the build folder.');