-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
50 lines (45 loc) · 1.23 KB
/
index.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
const mergeTrees = require('broccoli-merge-trees');
const rollup = require('broccoli-rollup');
const { buildWorkerTrees } = require('./lib/worker-tree');
const fs = require('fs');
const path = require('path');
const { default: nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const treeFactory = (workerPath) => {
const workerList = fs.readdirSync(workerPath);
return workerList.map((workerName) =>
rollup(workerPath, {
rollup: {
input: workerName,
output: [
{
name: workerName,
dir: `assets/workers`,
format: 'umd',
},
],
plugins: [
nodeResolve({
extensions: ['.js'],
browser: true,
preferBuiltIns: false,
}),
commonjs({
include: [/node_modules/],
}),
],
},
}),
);
};
module.exports = {
name: require('./package').name,
treeForPublic(tree) {
const workerPath = path.join(this.project.root, 'workers');
const joinedTrees = [
...buildWorkerTrees(workerPath, treeFactory),
tree,
].filter(Boolean);
return mergeTrees(joinedTrees, { overwrite: true });
},
};