Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
8d75e603
Commit
8d75e603
authored
Aug 29, 2025
by
devjiwonchoi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lets break
parent
ee164dae
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
60 deletions
+3
-60
loader.ts
packages/next/src/build/next-config-ts/loader.ts
+3
-60
No files found.
packages/next/src/build/next-config-ts/loader.ts
View file @
8d75e603
...
@@ -6,8 +6,7 @@ import type {
...
@@ -6,8 +6,7 @@ import type {
}
from
'module'
}
from
'module'
import
type
{
CompilerOptions
}
from
'typescript'
import
type
{
CompilerOptions
}
from
'typescript'
import
path
from
'path'
import
{
extname
}
from
'path'
import
{
existsSync
}
from
'fs'
import
{
readFile
}
from
'fs/promises'
import
{
readFile
}
from
'fs/promises'
import
{
fileURLToPath
}
from
'url'
import
{
fileURLToPath
}
from
'url'
import
{
resolveSWCOptions
}
from
'./transpile-config.js'
import
{
resolveSWCOptions
}
from
'./transpile-config.js'
...
@@ -37,40 +36,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
...
@@ -37,40 +36,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
return
nextResolve
(
specifier
,
context
)
return
nextResolve
(
specifier
,
context
)
}
}
const
ext
=
path
.
extname
(
specifier
)
const
ext
=
extname
(
specifier
)
// If the specifier has no extension, try to resolve it as a TS file.
// This is mainly to prevent a breaking change for ESM projects that use
// "next.config.ts", and also to keep the TS file behavior consistent with
// the rest of the project files.
if
(
ext
===
''
)
{
const
possibleTsFileURL
=
new
URL
(
specifier
+
'.ts'
,
context
.
parentURL
)
if
(
existsSync
(
possibleTsFileURL
))
{
return
{
format
:
'typescript'
as
ModuleFormat
,
shortCircuit
:
true
,
url
:
possibleTsFileURL
.
href
,
}
}
if
(
existsSync
(
new
URL
(
specifier
+
'.js'
,
context
.
parentURL
)))
{
return
nextResolve
(
specifier
+
'.js'
,
context
)
}
return
nextResolve
(
specifier
,
context
)
}
// This allows not to write type: "with" assertions for JSON imports.
// This is mainly to prevent a breaking change for ESM projects that use
// "next.config.ts", and also to keep the TS file behavior consistent with
// the rest of the project files.
if
(
ext
===
'.json'
)
{
return
{
format
:
'json'
as
ModuleFormat
,
shortCircuit
:
true
,
url
:
new
URL
(
specifier
,
context
.
parentURL
).
href
,
}
}
// Node.js resolver can take care of the rest of the non-TS files.
// Node.js resolver can take care of the rest of the non-TS files.
if
(
!
tsExts
.
has
(
ext
))
{
if
(
!
tsExts
.
has
(
ext
))
{
return
nextResolve
(
specifier
,
context
)
return
nextResolve
(
specifier
,
context
)
...
@@ -84,10 +50,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
...
@@ -84,10 +50,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
}
}
export
const
load
:
LoadHook
=
async
(
url
,
context
,
nextLoad
)
=>
{
export
const
load
:
LoadHook
=
async
(
url
,
context
,
nextLoad
)
=>
{
if
(
if
(
context
.
format
!==
(
'typescript'
as
ModuleFormat
))
{
context
.
format
!==
(
'typescript'
as
ModuleFormat
)
&&
context
.
format
!==
(
'json'
as
ModuleFormat
)
)
{
return
nextLoad
(
url
,
context
)
return
nextLoad
(
url
,
context
)
}
}
...
@@ -104,26 +67,6 @@ export const load: LoadHook = async (url, context, nextLoad) => {
...
@@ -104,26 +67,6 @@ export const load: LoadHook = async (url, context, nextLoad) => {
)
)
}
}
if
(
context
.
format
===
(
'json'
as
ModuleFormat
))
{
const
rawSource
=
await
readFile
(
fileURLToPath
(
url
),
'utf-8'
)
const
jsonData
=
JSON
.
parse
(
rawSource
)
let
source
=
`export default (
${
rawSource
}
);`
// Add named exports for object properties
if
(
!
Array
.
isArray
(
jsonData
))
{
const
namedExports
=
Object
.
keys
(
jsonData
)
.
map
((
key
)
=>
`export const
${
key
}
= (
${
rawSource
}
).
${
key
}
;`
)
.
join
(
'
\
n'
)
source
=
`
${
namedExports
}
\n
${
source
}
`
}
return
{
format
:
'module'
,
shortCircuit
:
true
,
source
,
}
}
const
rawSource
=
await
readFile
(
fileURLToPath
(
url
),
'utf-8'
)
const
rawSource
=
await
readFile
(
fileURLToPath
(
url
),
'utf-8'
)
// Lazy load swc to reduce the initial loader registration time.
// Lazy load swc to reduce the initial loader registration time.
const
{
transform
}
=
await
import
(
'../swc/index.js'
)
const
{
transform
}
=
await
import
(
'../swc/index.js'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment