UNPKG

next

Version:

The React Framework

25 lines (24 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _path = require("path"); class NextJsSsrImportPlugin { apply(compiler) { compiler.hooks.compilation.tap('NextJsSSRImport', (compilation)=>{ compilation.mainTemplate.hooks.requireEnsure.tap('NextJsSSRImport', (code, chunk)=>{ // Update to load chunks from our custom chunks directory const outputPath = (0, _path).resolve('/'); const pagePath = (0, _path).join('/', (0, _path).dirname(chunk.name)); const relativePathToBaseDir = (0, _path).relative(pagePath, outputPath); // Make sure even in windows, the path looks like in unix // Node.js require system will convert it accordingly const relativePathToBaseDirNormalized = relativePathToBaseDir.replace(/\\/g, '/'); return code.replace('require("./"', `require("${relativePathToBaseDirNormalized}/"`).replace('readFile(join(__dirname', `readFile(join(__dirname, "${relativePathToBaseDirNormalized}"`); }); }); } } exports.default = NextJsSsrImportPlugin; //# sourceMappingURL=nextjs-ssr-import.js.map