-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
45 lines (42 loc) · 975 Bytes
/
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
"use strict";
const babel = require("@babel/core");
const path = require("path");
const rollup = require("rollup");
const vm = require("vm");
function evaluate(file, code) {
return rollup
.rollup({
input: file,
plugins: [{ load: () => code }]
})
.then(bundle => bundle.generate({ format: "iife", name: "$$$module" }))
.then(({ code }) => {
const sandbox = vm.createContext();
vm.runInContext(code, sandbox);
return `export default ${JSON.stringify(sandbox.$$$module)}`;
});
}
module.exports = {
input: "src/irt.js",
plugins: [
{
transform(code, id) {
code = babel.transform(code, { filename: id, comments: false });
return id === path.resolve("./src/prior.js")
? evaluate(id, code)
: code;
}
}
],
output: [
{
file: "dist/irt.js",
format: "cjs"
},
{
file: "dist/irt.umd.js",
name: "IRT",
format: "umd"
}
]
};