-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
rollup.config.js
74 lines (69 loc) · 1.97 KB
/
rollup.config.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import cleanup from 'rollup-plugin-cleanup';
import copy from 'rollup-plugin-copy';
import dts from 'rollup-plugin-dts';
import { minify } from 'terser';
// last ECMA version compatible with node.js 12
const ecma = 2019;
export default [
// remove comments from d.ts file
{
input: 'src/index.d.ts',
output: [
{
file: 'dist/index.d.ts',
format: 'es',
},
],
plugins: [
cleanup({ extensions: ['ts'] }),
dts(),
],
},
{
input: 'src/index.js',
output: [
{
intro: '/* Auto generated by rollup.\nUse `npm run build` to create new version. */',
exports: 'named',
file: './dist/index.js',
format: 'cjs',
},
],
plugins: [
replace({
preventAssignment: false, // allow modifying exports
// the order of exports is other than is needed
'exports.Ansis = Ansis': 'module.exports = ansis', // firstly must be defined default export
'exports.default = ansis': 'module.exports.Ansis = Ansis', // then on the next line can be named export
}),
terser({
ecma,
compress: {
ecma,
passes: 2,
},
toplevel: true,
}),
copy({
targets: [
{
src: 'src/index.mjs',
dest: 'dist/',
transform: async (contents, name) => (await minify(contents.toString(), { ecma: 2015 })).code,
},
// minify d.ts file generated after cleanup
{
src: 'dist/index.d.ts',
dest: 'dist/',
transform: (contents, name) => { return contents.toString().replaceAll(/\n/g, '');},
},
{ src: 'package.npm.json', dest: 'dist/', rename: 'package.json' },
{ src: 'README.npm.md', dest: 'dist/', rename: 'README.md' },
{ src: 'LICENSE', dest: 'dist/' },
],
}),
],
},
];