-
Notifications
You must be signed in to change notification settings - Fork 49
/
rollup.config.js
84 lines (77 loc) · 1.57 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
75
76
77
78
79
80
81
82
83
84
import terser from '@rollup/plugin-terser';
import pkg from './scripts/package.js';
const input = 'src/index.js';
const banner = `/**
* ${pkg.name}
* ${pkg.homepage}
* @version ${pkg.version}
* @author ${pkg.author.name}
* @license ${pkg.license}
*/`;
const outputModule = {
banner,
format: 'es'
};
const outputUMD = {
banner,
format: 'umd',
name: 'lil',
exports: 'named'
};
export default [
{
input,
output: { ...outputModule, file: pkg.module },
plugins: [ stylesheet(), strip() ]
},
{
input,
output: { ...outputModule, file: pkg.module.replace( '.js', '.min.js' ) },
plugins: [ stylesheet( true ), terser( { module: true } ) ]
},
{
input,
output: { ...outputUMD, file: pkg.main },
plugins: [ stylesheet(), strip() ]
},
{
input,
output: { ...outputUMD, file: pkg.main.replace( '.js', '.min.js' ) },
plugins: [ stylesheet( true ), terser( { module: false } ) ]
}
];
function stylesheet( min = false ) {
const path = min ? pkg.config.styleMin : pkg.config.style;
return {
name: 'stylesheet',
resolveId( source ) {
return source === 'stylesheet' ? path : null;
},
transform( content, id ) {
if ( id !== path ) return;
return {
code: `export default \`${content.trim()}\`;`,
map: { mappings: '' }
};
}
};
}
function strip() {
const regexps = [
/^\n?\t*\/\*\* @module.*\n/gm,
/^\n?\t*\/\* eslint-.*\n/gm,
/^\t*\/\/ eslint-.*\n/gm
];
return {
name: 'strip',
renderChunk( code ) {
regexps.forEach( re => {
code = code.replace( re, '' );
} );
return {
code,
map: { mappings: '' }
};
}
};
}