-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
92 lines (86 loc) · 2.25 KB
/
rollup.config.mjs
File metadata and controls
92 lines (86 loc) · 2.25 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import { minify } from 'terser';
// Helpers
//
// - Display the size of a directory's content:
// find ./dist -type f -exec stat -f"%z" {} + | awk '{s+=$1} END {print s}'
// https://github.com/terser/terser#compress-options
const terserOptions = (ecma) => ({
ecma,
compress: false, // do not perform any compression
mangle: false, // do not mangle variable names
format: {
comments: false, // remove all comments
beautify: true, // keep code readable
indent_level: 1, // use single space as base
}
});
/**
* Convert leading spaces to tabs.
*
* @return {{name: string, generateBundle(*, *): void}}
*/
const indentToTabsPlugin = function () {
return {
name: 'indent-to-tabs',
generateBundle(options, bundle) {
for (const file of Object.values(bundle)) {
if (file.type === 'chunk') {
// replace leading spaces in every line with tabs
file.code = file.code.replace(/^ +/gm, (match) => '\t'.repeat(match.length));
}
}
},
};
}
function buildConfig({ ecma }) {
return {
input: 'src/index.js',
output: {
file: `dist/index.js`,
format: 'cjs',
strict: false,
esModule: false,
exports: 'auto',
},
// not to bundle these modules
external: [
'path',
'ansis',
],
plugins: [
resolve(),
commonjs(),
terser(terserOptions(ecma)),
copy({
targets: [
{
src: 'src/index.js',
dest: `dist/`,
transform: async (contents) => (
await minify(
contents.toString(),
{ ecma }
)
).code,
},
{
src: 'src/index.d.ts',
dest: `dist/`,
rename: 'index.d.ts',
},
{ src: `package.npm.json`, dest: `dist/`, rename: 'package.json' },
{ src: `README.npm.md`, dest: `dist/`, rename: 'README.md' },
{ src: 'LICENSE', dest: `dist/` },
],
}),
indentToTabsPlugin(),
],
};
}
export default [
buildConfig({ ecma: 2018 }),
];