-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
61 lines (49 loc) · 1.53 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
import { loadConfigFile } from 'rollup/loadConfigFile';
export default async cliOptions => {
return (await Promise.all([
'utils',
'preoutdent',
'web',
'UITable-Runner',
'Scriptable',
'node',
].map(async packagesDir => {
const emptyConfig = { watch: { clearScreen: false } };
const dir = `packages/${packagesDir}`;
const configFile = `${dir}/rollup.config.js`;
const cliOpts = { ...cliOptions, configPathPrefix: dir };
const config = await (async () => {
try {
const { options, warnings } = await loadConfigFile(configFile, cliOpts);
warnings.flush();
return options;
} catch (e) {
console.error('unable to load config', configFile, e.message ? e.message : e);
return emptyConfig;
}
})();
if (config === emptyConfig) return config;
try {
return modifyConfig(config, configFile);
} catch (e) {
console.error(e);
return emptyConfig;
}
}))).flat();
};
function modifyConfig(rawConfig, configFile) {
if (Array.isArray(rawConfig))
return rawConfig.map(config => modifyConfig(config, configFile));
const newConfig = { ...rawConfig };
if (!Array.isArray(newConfig.plugins)) {
console.warn('.plugins is not an array; unable to add watch-included-config plugin');
} else {
newConfig.plugins.push({
name: 'watch-included-config',
buildStart(options) { // eslint-disable-line @typescript-eslint/no-unused-vars
this.addWatchFile(configFile);
},
});
}
return newConfig;
}