valueInjectionLoader.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. /**
  3. * Set values on the global/window object at the start of a module.
  4. *
  5. * Options:
  6. * - `values`: An object where the keys correspond to the keys of the global values to set and the values
  7. * correspond to the values of the values on the global object. Values must be JSON serializable.
  8. */
  9. function valueInjectionLoader( userCode) {
  10. // We know one or the other will be defined, depending on the version of webpack being used
  11. const { values } = 'getOptions' in this ? this.getOptions() : this.query;
  12. // We do not want to cache injected values across builds
  13. this.cacheable(false);
  14. // Define some global proxy that works on server and on the browser.
  15. let injectedCode =
  16. 'var _sentryCollisionFreeGlobalObject = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};\n';
  17. Object.entries(values).forEach(([key, value]) => {
  18. injectedCode += `_sentryCollisionFreeGlobalObject["${key}"] = ${JSON.stringify(value)};\n`;
  19. });
  20. return `${injectedCode}\n${userCode}`;
  21. }
  22. exports.default = valueInjectionLoader;
  23. //# sourceMappingURL=valueInjectionLoader.js.map