serverPluginJson.js 754 B

1234567891011121314151617181920
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.jsonPlugin = void 0;
  4. const utils_1 = require("../utils");
  5. const pluginutils_1 = require("@rollup/pluginutils");
  6. exports.jsonPlugin = ({ app }) => {
  7. app.use(async (ctx, next) => {
  8. await next();
  9. // handle .json imports
  10. // note ctx.body could be null if upstream set status to 304
  11. if (ctx.path.endsWith('.json') && utils_1.isImportRequest(ctx) && ctx.body) {
  12. ctx.type = 'js';
  13. ctx.body = pluginutils_1.dataToEsm(JSON.parse((await utils_1.readBody(ctx.body))), {
  14. namedExports: true,
  15. preferConst: true
  16. });
  17. }
  18. });
  19. };
  20. //# sourceMappingURL=serverPluginJson.js.map