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
2c75fa0d
Unverified
Commit
2c75fa0d
authored
Jan 01, 2021
by
Joe Haddad
Committed by
GitHub
Jan 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(source map): correctly generate source maps (#20672)
Fixes #20500
parent
9ded7aa9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
12 deletions
+26
-12
webpack-config.ts
packages/next/build/webpack-config.ts
+1
-3
base.ts
packages/next/build/webpack/config/blocks/base.ts
+2
-2
index.js
.../build/webpack/plugins/terser-webpack-plugin/src/index.js
+4
-6
index.test.js
...egration/production-browser-sourcemaps/test/index.test.js
+19
-1
No files found.
packages/next/build/webpack-config.ts
View file @
2c75fa0d
...
@@ -211,8 +211,6 @@ export default async function getBaseWebpackConfig(
...
@@ -211,8 +211,6 @@ export default async function getBaseWebpackConfig(
rewrites
:
Rewrite
[]
rewrites
:
Rewrite
[]
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
productionBrowserSourceMaps
=
config
.
productionBrowserSourceMaps
&&
!
isServer
let
plugins
:
PluginMetaData
[]
=
[]
let
plugins
:
PluginMetaData
[]
=
[]
let
babelPresetPlugins
:
{
dir
:
string
;
config
:
any
}[]
=
[]
let
babelPresetPlugins
:
{
dir
:
string
;
config
:
any
}[]
=
[]
...
@@ -1216,7 +1214,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1216,7 +1214,7 @@ export default async function getBaseWebpackConfig(
isServer
,
isServer
,
assetPrefix
:
config
.
assetPrefix
||
''
,
assetPrefix
:
config
.
assetPrefix
||
''
,
sassOptions
:
config
.
sassOptions
,
sassOptions
:
config
.
sassOptions
,
productionBrowserSourceMaps
,
productionBrowserSourceMaps
:
config
.
productionBrowserSourceMaps
,
})
})
let
originalDevtool
=
webpackConfig
.
devtool
let
originalDevtool
=
webpackConfig
.
devtool
...
...
packages/next/build/webpack/config/blocks/base.ts
View file @
2c75fa0d
...
@@ -35,8 +35,8 @@ export const base = curry(function base(
...
@@ -35,8 +35,8 @@ export const base = curry(function base(
config
.
devtool
=
'eval-source-map'
config
.
devtool
=
'eval-source-map'
}
}
}
else
{
}
else
{
// Enable browser sourcemaps
// Enable browser sourcemaps
:
if
(
ctx
.
productionBrowserSourceMaps
)
{
if
(
ctx
.
productionBrowserSourceMaps
&&
ctx
.
isClient
)
{
config
.
devtool
=
'source-map'
config
.
devtool
=
'source-map'
}
else
{
}
else
{
config
.
devtool
=
false
config
.
devtool
=
false
...
...
packages/next/build/webpack/plugins/terser-webpack-plugin/src/index.js
View file @
2c75fa0d
...
@@ -226,11 +226,9 @@ class TerserPlugin {
...
@@ -226,11 +226,9 @@ class TerserPlugin {
return
traceAsyncFn
(
assetSpan
,
async
()
=>
{
return
traceAsyncFn
(
assetSpan
,
async
()
=>
{
if
(
!
output
)
{
if
(
!
output
)
{
let
inputSourceMap
const
{
const
{
source
:
sourceFromInputSource
,
source
:
sourceFromInputSource
,
map
,
map
:
inputSourceMap
,
}
=
inputSource
.
sourceAndMap
()
}
=
inputSource
.
sourceAndMap
()
const
input
=
Buffer
.
isBuffer
(
sourceFromInputSource
)
const
input
=
Buffer
.
isBuffer
(
sourceFromInputSource
)
...
@@ -240,7 +238,7 @@ class TerserPlugin {
...
@@ -240,7 +238,7 @@ class TerserPlugin {
const
options
=
{
const
options
=
{
name
,
name
,
input
,
input
,
inputSourceMap
:
map
,
inputSourceMap
,
terserOptions
:
{
...
this
.
options
.
terserOptions
},
terserOptions
:
{
...
this
.
options
.
terserOptions
},
}
}
...
@@ -337,8 +335,8 @@ class TerserPlugin {
...
@@ -337,8 +335,8 @@ class TerserPlugin {
})
})
const
handleHashForChunk
=
(
hash
,
chunk
)
=>
{
const
handleHashForChunk
=
(
hash
,
chunk
)
=>
{
// increment '
b
' to invalidate cache
// increment '
c
' to invalidate cache
hash
.
update
(
'
b
'
)
hash
.
update
(
'
c
'
)
}
}
if
(
isWebpack5
)
{
if
(
isWebpack5
)
{
...
...
test/integration/production-browser-sourcemaps/test/index.test.js
View file @
2c75fa0d
/* eslint-env jest */
/* eslint-env jest */
import
fs
from
'fs-extra'
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
{
nextBuild
}
from
'next-test-utils'
import
{
nextBuild
,
getPageFileFromBuildManifest
}
from
'next-test-utils'
import
{
recursiveReadDir
}
from
'next/dist/lib/recursive-readdir'
import
{
recursiveReadDir
}
from
'next/dist/lib/recursive-readdir'
jest
.
setTimeout
(
1000
*
60
*
2
)
jest
.
setTimeout
(
1000
*
60
*
2
)
...
@@ -24,6 +24,24 @@ function runTests() {
...
@@ -24,6 +24,24 @@ function runTests() {
expect
(
browserFiles
.
includes
(
`
${
file
}
.map`
)).
toBe
(
true
)
expect
(
browserFiles
.
includes
(
`
${
file
}
.map`
)).
toBe
(
true
)
})
})
})
})
it
(
'correctly generated the source map'
,
async
()
=>
{
const
map
=
JSON
.
parse
(
await
fs
.
readFile
(
join
(
appDir
,
'.next'
,
(
await
getPageFileFromBuildManifest
(
appDir
,
'/static'
))
+
'.map'
),
'utf8'
)
)
expect
(
map
.
sources
).
toContainEqual
(
expect
.
stringMatching
(
/pages
[/\\]
static
\.
js/
)
)
expect
(
map
.
names
).
toContainEqual
(
'StaticPage'
)
})
}
}
describe
(
'Production browser sourcemaps'
,
()
=>
{
describe
(
'Production browser sourcemaps'
,
()
=>
{
...
...
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