Unverified Commit 87d0fc9f authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

avoid using absolute paths in import/require (#29797)

Using absolute paths leads to unnecessary watched paths and tested paths for resolving
parent 77b65327
......@@ -18,14 +18,17 @@ function nextClientPagesLoader(this: any) {
pagesLoaderSpan.setAttribute('absolutePagePath', absolutePagePath)
const stringifiedAbsolutePagePath = JSON.stringify(absolutePagePath)
const stringifiedPagePath = loaderUtils.stringifyRequest(
this,
absolutePagePath
)
const stringifiedPage = JSON.stringify(page)
return `
(window.__NEXT_P = window.__NEXT_P || []).push([
${stringifiedPage},
function () {
return require(${stringifiedAbsolutePagePath});
return require(${stringifiedPagePath});
}
]);
`
......
import devalue from 'next/dist/compiled/devalue'
import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import loaderUtils from 'next/dist/compiled/loader-utils'
import { join } from 'path'
import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack'
......@@ -112,7 +113,10 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
}
const apiHandler = getApiHandler({
pageModule: require("${absolutePagePath}"),
pageModule: require(${loaderUtils.stringifyRequest(
this,
absolutePagePath
)}),
rewrites: combinedRewrites,
i18n: ${i18n || 'undefined'},
page: "${page}",
......@@ -137,12 +141,21 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
}
import { getPageHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/page-handler'
const documentModule = require("${absoluteDocumentPath}")
const documentModule = require(${loaderUtils.stringifyRequest(
this,
absoluteDocumentPath
)})
const appMod = require('${absoluteAppPath}')
const appMod = require(${loaderUtils.stringifyRequest(
this,
absoluteAppPath
)})
let App = appMod.default || appMod.then && appMod.then(mod => mod.default);
const compMod = require('${absolutePagePath}')
const compMod = require(${loaderUtils.stringifyRequest(
this,
absolutePagePath
)})
const Component = compMod.default || compMod.then && compMod.then(mod => mod.default)
export default Component
......@@ -175,9 +188,14 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
pageConfig: config,
appModule: App,
documentModule: documentModule,
errorModule: require("${absoluteErrorPath}"),
errorModule: require(${loaderUtils.stringifyRequest(
this,
absoluteErrorPath
)}),
notFoundModule: ${
absolute404Path ? `require("${absolute404Path}")` : undefined
absolute404Path
? `require(${loaderUtils.stringifyRequest(this, absolute404Path)})`
: undefined
},
pageGetStaticProps: getStaticProps,
pageGetStaticPaths: getStaticPaths,
......
......@@ -2,7 +2,7 @@ import { getOverlayMiddleware } from '@next/react-dev-overlay/lib/middleware'
import { NextHandleFunction } from 'connect'
import { IncomingMessage, ServerResponse } from 'http'
import { WebpackHotMiddleware } from './hot-middleware'
import { join } from 'path'
import { join, relative, isAbsolute } from 'path'
import { UrlObject } from 'url'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import {
......@@ -423,13 +423,22 @@ export default class HotReloader {
absolutePagePath,
}
entrypoints[bundlePath] = finalizeEntrypoint(
bundlePath,
isClientCompilation
? `next-client-pages-loader?${stringify(pageLoaderOpts)}!`
: absolutePagePath,
!isClientCompilation
)
if (isClientCompilation) {
entrypoints[bundlePath] = finalizeEntrypoint(
bundlePath,
`next-client-pages-loader?${stringify(pageLoaderOpts)}!`,
false
)
} else {
let request = relative(config.context!, absolutePagePath)
if (!isAbsolute(request) && !request.startsWith('../'))
request = `./${request}`
entrypoints[bundlePath] = finalizeEntrypoint(
bundlePath,
request,
true
)
}
})
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment