forked from adrium/easypass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkerLoader.js
43 lines (38 loc) · 960 Bytes
/
workerLoader.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
/*
* This Source Code is subject to the terms of the Mozilla Public License
* version 2.0 (the "License"). You can obtain a copy of the License at
* http://mozilla.org/MPL/2.0/.
*/
"use strict";
const rollup = require("rollup");
module.exports = function(regexp)
{
return {
name: "worker-loader",
buildStart(options)
{
this._plugins = options.plugins;
},
load(id)
{
if (!regexp.test(id))
return null;
return rollup.rollup({
input: id,
plugins: this._plugins.filter(p => p.name != "worker-loader")
}).then(bundle =>
{
return bundle.generate({
name: "worker",
format: "cjs",
compact: true
});
}).then(({output}) =>
{
if (output.length != 1 || !output[0].code)
throw new Error("Unexpected rollup output");
return "export default function(){" + output[0].code + "}";
});
}
};
};