Files
test-repo/scripts/build/rollup-plugins/evaluate.js
T

28 lines
568 B
JavaScript
Raw Normal View History

"use strict";
2020-03-21 22:07:52 +02:00
module.exports = function () {
return {
name: "evaluate",
transform(_text, id) {
if (!/\.evaluate\.js$/.test(id)) {
return null;
}
const json = JSON.stringify(
require(id.replace(/^\0commonjs-proxy:/, "")),
(_, v) => {
if (typeof v === "function") {
2020-01-14 18:58:20 +08:00
throw new Error("Cannot evaluate functions.");
}
return v;
}
);
return {
code: `var json = ${json}; export default json;`,
2020-03-21 22:07:52 +02:00
map: { mappings: "" },
};
2020-03-21 22:07:52 +02:00
},
};
};