-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.ts
More file actions
48 lines (41 loc) · 1.35 KB
/
rollup.config.ts
File metadata and controls
48 lines (41 loc) · 1.35 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
import { Plugin, RollupOptions } from 'rollup';
// rollup plugins
import * as typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import * as styles from 'rollup-plugin-styles';
import * as del from 'rollup-plugin-delete';
// custom plugins
import { cleanComments, metadata } from './rollup.plugin';
// libraries to extract YAML config
import * as yaml from 'js-yaml';
import * as fs from 'fs-extra';
// list of available plugins during build process
const plugins = {
typescript,
nodeResolve,
terser,
styles,
del,
cleanComments,
metadata,
};
// rollup config from YAML file
const rc: RollupOptions[] = yaml.load(
fs.readFileSync('./rollup.config.yml', 'utf8'),
);
// rebuild config array to switch plugins values from config by plugins functions
const config: RollupOptions[] = rc.map((_: RollupOptions) =>
Object.assign({}, _, {
plugins: []
// check if we have declared plugins in config file
.concat(!!_.plugins ? _.plugins : [])
// check if plugin is imported and declared inside plugins functions list
.filter((plugin: Plugin) => !!plugins[plugin.name])
// switch config value to function
.map((plugin: Plugin) =>
plugins[plugin.name](Object.assign({}, plugin.api)),
),
}),
);
export default config;