-
Notifications
You must be signed in to change notification settings - Fork 84
/
build-examples.js
40 lines (33 loc) · 944 Bytes
/
build-examples.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
const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const fs = require('fs');
const path = require('path');
async function build(example) {
console.log('Building ' + example);
const inputOptions = {
input: path.resolve(`./examples/${example}/script.js`),
plugins: [
resolve(),
commonjs()
]
}
const outputOptions = {
format: 'iife',
file: path.resolve(`./examples/${example}/build.js`),
name: example.replace(/-/g, ''),
}
// create a bundle
const bundle = await rollup.rollup(inputOptions);
// write bundle
await bundle.write(outputOptions);
console.log('Built ' + example);
}
const examples = fs.readdirSync('./examples');
Promise.all(examples.map(build))
.then(()=> console.log('Success!'))
.catch(err => {
console.error('Failed!');
console.error(err);
process.exit(1);
});