2018-09-02 16:20:22 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
2020-03-21 22:07:52 +02:00
|
|
|
module.exports = function () {
|
2018-09-02 16:20:22 +08:00
|
|
|
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.");
|
2018-09-02 16:20:22 +08:00
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
2018-11-28 12:52:05 +08:00
|
|
|
code: `var json = ${json}; export default json;`,
|
2020-03-21 22:07:52 +02:00
|
|
|
map: { mappings: "" },
|
2018-09-02 16:20:22 +08:00
|
|
|
};
|
2020-03-21 22:07:52 +02:00
|
|
|
},
|
2018-09-02 16:20:22 +08:00
|
|
|
};
|
|
|
|
|
};
|