systemjs.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* eslint-disable no-var, unicorn/no-typeof-undefined */
  16. "use strict";
  17. (function () {
  18. var baseLocation;
  19. if (typeof document !== "undefined") {
  20. baseLocation = new URL("./", document.currentScript.src);
  21. } else if (typeof location !== "undefined") {
  22. // Probably worker -- walking subfolders until we will reach root.
  23. baseLocation = location;
  24. while (baseLocation.href.includes("/src/")) {
  25. baseLocation = new URL("..", baseLocation);
  26. }
  27. } else {
  28. throw new Error("Cannot configure SystemJS");
  29. }
  30. var PluginBabelPath = "node_modules/systemjs-plugin-babel/plugin-babel.js";
  31. var SystemJSPluginBabelPath =
  32. "node_modules/systemjs-plugin-babel/systemjs-babel-browser.js";
  33. var PluginBabelCachePath = "external/systemjs/plugin-babel-cached.js";
  34. var isCachingPossible =
  35. typeof indexedDB !== "undefined" &&
  36. typeof TextEncoder !== "undefined" &&
  37. typeof crypto !== "undefined" &&
  38. typeof crypto.subtle !== "undefined";
  39. // When we create a bundle, webpack is run on the source and it will replace
  40. // require with __webpack_require__. When we want to use the real require,
  41. // __non_webpack_require__ has to be used.
  42. // In this target, we don't create a bundle, so we have to replace the
  43. // occurrences of __non_webpack_require__ ourselves.
  44. function babelPluginReplaceNonWebPackRequire(babel) {
  45. return {
  46. visitor: {
  47. Identifier(path, state) {
  48. if (path.node.name === "__non_webpack_require__") {
  49. path.replaceWith(babel.types.identifier("require"));
  50. }
  51. },
  52. },
  53. };
  54. }
  55. SystemJS.config({
  56. packages: {
  57. "": {
  58. defaultExtension: "js",
  59. },
  60. },
  61. paths: {
  62. pdfjs: new URL("src", baseLocation).href,
  63. "pdfjs-web": new URL("web", baseLocation).href,
  64. "pdfjs-test": new URL("test", baseLocation).href,
  65. "pdfjs-lib": new URL("src/pdf", baseLocation).href,
  66. "core-js": new URL("node_modules/core-js", baseLocation).href,
  67. "web-streams-polyfill": new URL(
  68. "node_modules/web-streams-polyfill",
  69. baseLocation
  70. ).href,
  71. },
  72. meta: {
  73. "*": {
  74. scriptLoad: false,
  75. esModule: true,
  76. babelOptions: {
  77. env: false,
  78. plugins: [babelPluginReplaceNonWebPackRequire],
  79. },
  80. },
  81. },
  82. map: {
  83. "plugin-babel": new URL(PluginBabelPath, baseLocation).href,
  84. "systemjs-babel-build": new URL(SystemJSPluginBabelPath, baseLocation)
  85. .href,
  86. "plugin-babel-cached": new URL(PluginBabelCachePath, baseLocation).href,
  87. },
  88. transpiler: isCachingPossible ? "plugin-babel-cached" : "plugin-babel",
  89. });
  90. })();