-
Notifications
You must be signed in to change notification settings - Fork 10
/
rollup.config.mjs
56 lines (54 loc) · 1.68 KB
/
rollup.config.mjs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import typescript from '@rollup/plugin-typescript';
import assert from 'assert';
import { readFile } from 'fs/promises';
import { defineConfig } from 'rollup';
const distPackagePrefix = './dist/package/';
const removeDistPackage = (withDistPackage) => {
assert(withDistPackage.startsWith(distPackagePrefix));
return `./${withDistPackage.substring(distPackagePrefix.length)}`;
};
export default defineConfig({
output: [
{
format: 'cjs',
file: './dist/package/index.cjs',
},
{
format: 'es',
file: './dist/package/index.js',
},
],
input: './src/index.ts',
plugins: [
typescript(),
{
name: 'package',
async buildStart() {
const pkg = JSON.parse(await readFile('./package.json', 'utf8'));
delete pkg.private;
delete pkg.devDependencies;
delete pkg.scripts;
delete pkg.husky;
delete pkg.commitlint;
delete pkg.files;
pkg.typings = removeDistPackage(pkg.typings);
pkg.main = removeDistPackage(pkg.main);
pkg.module = removeDistPackage(pkg.module);
pkg.exports.types = removeDistPackage(pkg.exports.types);
pkg.exports.require = removeDistPackage(pkg.exports.require);
pkg.exports.default = removeDistPackage(pkg.exports.default);
this.emitFile({ type: 'asset', fileName: 'package.json', source: JSON.stringify(pkg) });
this.emitFile({
type: 'asset',
fileName: 'README.md',
source: await readFile('README.md', 'utf-8'),
});
this.emitFile({
type: 'asset',
fileName: 'LICENSE',
source: await readFile('LICENSE', 'utf-8'),
});
},
},
],
});