index.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = edgeSSRLoader;
  6. var _getModuleBuildInfo = require("../get-module-build-info");
  7. var _stringifyRequest = require("../../stringify-request");
  8. async function edgeSSRLoader() {
  9. const { dev , page , buildId , absolutePagePath , absoluteAppPath , absoluteDocumentPath , absolute500Path , absoluteErrorPath , isServerComponent , stringifiedConfig , appDirLoader: appDirLoaderBase64 , pagesType , sriEnabled , } = this.getOptions();
  10. const appDirLoader = Buffer.from(appDirLoaderBase64 || "", "base64").toString();
  11. const isAppDir = pagesType === "app";
  12. const buildInfo = (0, _getModuleBuildInfo).getModuleBuildInfo(this._module);
  13. buildInfo.nextEdgeSSR = {
  14. isServerComponent: isServerComponent === "true",
  15. page: page,
  16. isAppDir
  17. };
  18. buildInfo.route = {
  19. page,
  20. absolutePagePath
  21. };
  22. const stringifiedPagePath = (0, _stringifyRequest).stringifyRequest(this, absolutePagePath);
  23. const stringifiedAppPath = (0, _stringifyRequest).stringifyRequest(this, absoluteAppPath);
  24. const stringifiedErrorPath = (0, _stringifyRequest).stringifyRequest(this, absoluteErrorPath);
  25. const stringifiedDocumentPath = (0, _stringifyRequest).stringifyRequest(this, absoluteDocumentPath);
  26. const stringified500Path = absolute500Path ? (0, _stringifyRequest).stringifyRequest(this, absolute500Path) : null;
  27. const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(1, stringifiedPagePath.length - 1)}`;
  28. const transformed = `
  29. import { adapter, enhanceGlobals } from 'next/dist/server/web/adapter'
  30. import { getRender } from 'next/dist/build/webpack/loaders/next-edge-ssr-loader/render'
  31. import Document from ${stringifiedDocumentPath}
  32. enhanceGlobals()
  33. ${isAppDir ? `
  34. const appRenderToHTML = require('next/dist/server/app-render').renderToHTMLOrFlight
  35. const pagesRenderToHTML = null
  36. const pageMod = require(${JSON.stringify(pageModPath)})
  37. ` : `
  38. const appRenderToHTML = null
  39. const pagesRenderToHTML = require('next/dist/server/render').renderToHTML
  40. const pageMod = require(${stringifiedPagePath})
  41. `}
  42. const appMod = require(${stringifiedAppPath})
  43. const errorMod = require(${stringifiedErrorPath})
  44. const error500Mod = ${stringified500Path ? `require(${stringified500Path})` : "null"}
  45. const buildManifest = self.__BUILD_MANIFEST
  46. const reactLoadableManifest = self.__REACT_LOADABLE_MANIFEST
  47. const rscManifest = self.__RSC_MANIFEST
  48. const rscCssManifest = self.__RSC_CSS_MANIFEST
  49. const subresourceIntegrityManifest = ${sriEnabled ? "self.__SUBRESOURCE_INTEGRITY_MANIFEST" : "undefined"}
  50. const render = getRender({
  51. dev: ${dev},
  52. page: ${JSON.stringify(page)},
  53. appMod,
  54. pageMod,
  55. errorMod,
  56. error500Mod,
  57. Document,
  58. buildManifest,
  59. appRenderToHTML,
  60. pagesRenderToHTML,
  61. reactLoadableManifest,
  62. serverComponentManifest: ${isServerComponent} ? rscManifest : null,
  63. serverCSSManifest: ${isServerComponent} ? rscCssManifest : null,
  64. subresourceIntegrityManifest,
  65. config: ${stringifiedConfig},
  66. buildId: ${JSON.stringify(buildId)},
  67. })
  68. export const ComponentMod = pageMod
  69. export default function(opts) {
  70. return adapter({
  71. ...opts,
  72. handler: render
  73. })
  74. }`;
  75. return transformed;
  76. }
  77. //# sourceMappingURL=index.js.map