未验证 提交 2c75fa0d 编写于 作者: J Joe Haddad 提交者: GitHub

fix(source map): correctly generate source maps (#20672)

Fixes #20500
上级 9ded7aa9
...@@ -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
......
...@@ -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
......
...@@ -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) {
......
/* 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', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册