Skip to content

Commit

Permalink
Simplify imports path in virtual client entry
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 15, 2022
1 parent 3017b60 commit 14e217e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/next/build/webpack/plugins/client-entry-plugin.ts
Expand Up @@ -75,10 +75,23 @@ export class ClientEntryPlugin {
const clientComponentImports: string[] = []

function filterClientComponents(dependency: any) {
const module = compilation.moduleGraph.getResolvedModule(dependency)
if (!module) return
const mod = compilation.moduleGraph.getResolvedModule(dependency)
if (!mod) return

// Keep client imports as simple
// js module: -> raw request, e.g. next/head
// client js: -> relative imports
// TODO-APP: applied loaders for css
// *.css (with loaders applied): -> relative css imports

const { relativePath } = mod.resourceResolveData || {}
const modRequest =
mod.rawRequest &&
!mod.rawRequest.startsWith('.') &&
!mod.rawRequest.startsWith('/')
? mod.rawRequest
: relativePath || mod.userRequest

const modRequest = module.userRequest
if (visited.has(modRequest)) return
visited.add(modRequest)

Expand All @@ -90,7 +103,7 @@ export class ClientEntryPlugin {
}

compilation.moduleGraph
.getOutgoingConnections(module)
.getOutgoingConnections(mod)
.forEach((connection: any) => {
filterClientComponents(connection.dependency)
})
Expand Down

0 comments on commit 14e217e

Please sign in to comment.