Skip to content

Commit

Permalink
Use import to load page and layout
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Nov 2, 2022
1 parent 0c2404a commit 83ea1a1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/next/build/webpack/loaders/next-app-loader.ts
Expand Up @@ -69,7 +69,7 @@ async function createTreeCodeFromPath({
// Use '' for segment as it's the page. There can't be a segment called '' so this is the safest way to add it.
props[parallelKey] = `['', {}, {layoutOrPagePath: ${JSON.stringify(
resolvedPagePath
)}, page: () => require(${JSON.stringify(resolvedPagePath)})}]`
)}, page: () => import(${JSON.stringify(resolvedPagePath)})}]`
continue
}

Expand Down Expand Up @@ -108,7 +108,7 @@ async function createTreeCodeFromPath({
file === FILE_TYPES.layout
? `layoutOrPagePath: ${JSON.stringify(filePath)},`
: ''
}'${file}': () => require(${JSON.stringify(filePath)}),`
}'${file}': () => import(${JSON.stringify(filePath)}),`
})
.join('\n')}
}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-alias.test.ts
Expand Up @@ -22,6 +22,9 @@ describe('app-dir alias handling', () => {
'@types/react': 'latest',
'@types/node': 'latest',
},
packageJson: {
type: 'module',
},
})
})
afterAll(() => next.destroy())
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app-alias/.vscode/settings.json
@@ -0,0 +1,4 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
3 changes: 1 addition & 2 deletions test/e2e/app-dir/app-alias/next.config.js
@@ -1,6 +1,5 @@
module.exports = {
export default {
experimental: {
appDir: true,
transpileModules: ['ui'],
},
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-alias/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}

0 comments on commit 83ea1a1

Please sign in to comment.