Skip to content

Commit ac03a39

Browse files
authored
fix(nextjs): Match loader files exactly (#6013)
1 parent c60b6cb commit ac03a39

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ export function constructWebpackConfigFunction(
8686
// if `pages` is present in the root directory"
8787
// - https://nextjs.org/docs/advanced-features/src-directory
8888
const shouldIncludeSrcDirectory = !fs.existsSync(path.resolve(projectDir, 'pages'));
89+
const pagesDirectory = shouldIncludeSrcDirectory // We're intentionally not including slashes in the paths because we wanne let node do the path resolution for Windows
90+
? path.resolve(projectDir, 'src', 'pages')
91+
: path.resolve(projectDir, 'pages');
8992

9093
// Default page extensions per https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161
9194
const pageExtensions = userNextConfig.pageExtensions || ['tsx', 'ts', 'jsx', 'js'];
9295
const pageExtensionRegex = pageExtensions.map(escapeStringForRegex).join('|');
9396

9497
newConfig.module.rules.push({
9598
// Nextjs allows the `pages` folder to optionally live inside a `src` folder
96-
test: new RegExp(
97-
`${escapeStringForRegex(projectDir)}${
98-
shouldIncludeSrcDirectory ? '/src' : ''
99-
}/pages/.*\\.(${pageExtensionRegex})`,
100-
),
99+
test: new RegExp(`^${escapeStringForRegex(pagesDirectory)}.*\\.(${pageExtensionRegex})$`),
101100
use: [
102101
{
103102
loader: path.resolve(__dirname, 'loaders/proxyLoader.js'),

0 commit comments

Comments
 (0)