-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
84 lines (74 loc) · 1.92 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 minify from 'rollup-plugin-minify-es';
import minifyHTML from 'rollup-plugin-minify-html-literals';
import resolve from 'rollup-plugin-node-resolve';
import filesize from 'rollup-plugin-filesize';
import stringPlugin from 'rollup-plugin-string';
import urlResolve from 'rollup-plugin-url-resolve';
import { readdirSync } from 'fs';
import { join } from 'path';
const getDirectories = source =>
readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const rootDir = 'src';
const outDir = 'dist';
const extras = {
'common' : {},
'notfound': {
external: [
'lit-element',
'wgnhs-common',
'wgnhs-layout',
],
globals: {
'lit-element': 'wgnhs-common',
'wgnhs-common': 'wgnhs-common',
'wgnhs-layout': 'wgnhs-layout',
}
}
}
function getExtras(name) {
return extras[name] || extras['notfound'];
}
function buildPlugins({min=false}) {
let result = [];
result.push(resolve());
result.push(urlResolve());
result.push(stringPlugin.string({
include: [
/^https:.*/,
"**/*.css"
]
}))
if (min) {
result.push(minifyHTML());
result.push(minify({
output: {
wrap_iife: true
}
}));
}
result.push(filesize());
return result;
}
function buildScripts({dir, filename='index', min=false, format='umd'}) {
let minifyToken = (min) ? '.min': '';
let result = {
input: join(rootDir, dir, `${filename}.js`),
plugins: buildPlugins({dir, min}),
external: getExtras(dir).external,
output: {
file: join(outDir, `${dir}${minifyToken}.js`),
format: format,
name: `wgnhs-${dir}`,
sourcemap: min,
globals: getExtras(dir).globals
}
}
return result;
}
export default getDirectories(join(__dirname, rootDir)).reduce((agg, name) => {
agg.push(buildScripts({dir: name}));
agg.push(buildScripts({dir: name, min: true}));
return agg;
}, []);