@@ -228,10 +228,62 @@ export default class EvalSourceMapDevToolPlugin {
228
228
'EvalDevToolModulePlugin' ,
229
229
( ) => 'the eval-source-map devtool is used.'
230
230
)
231
- hooks . render . tap (
232
- 'EvalSourceMapDevToolPlugin' ,
233
- ( source ) => new ConcatSource ( devtoolWarning , source )
234
- )
231
+ hooks . render . tap ( 'EvalSourceMapDevToolPlugin' , ( source , context ) => {
232
+ if (
233
+ context . chunk . id === 'webpack' ||
234
+ context . chunk . id === 'webpack-runtime'
235
+ ) {
236
+ const sourceURL = new URL (
237
+ 'webpack-internal://nextjs/' + context . chunk . id + '.js'
238
+ )
239
+ // Webpack runtime chunks are not sourcemapped.
240
+ // We insert a dummy source map that ignore-lists everything.
241
+ // The mappings will be incorrect but end-users will almost never interact
242
+ // with the webpack runtime. Users who do, can follow the instructions
243
+ // in the sources content and disable sourcemaps in their debugger.
244
+ const sourceMappingURL = new URL (
245
+ 'data:application/json;charset=utf-8;base64,' +
246
+ Buffer . from (
247
+ JSON . stringify ( {
248
+ version : 3 ,
249
+ ignoreList : [ 0 ] ,
250
+ // Minimal, parseable mappings.
251
+ mappings : 'AAAA' ,
252
+ sources : [
253
+ // TODO: This should be the original source URL so that CTRL+Click works in the terminal.
254
+ sourceURL . toString ( ) ,
255
+ ] ,
256
+ sourcesContent : [
257
+ '' +
258
+ '// This source was generated by Next.js based off of the generated webpack runtime.\n' +
259
+ '// The mappings are incorrect.\n' +
260
+ '// To get the correct line/column mappings, turn off sourcemaps in your debugger.\n' +
261
+ `// Disable sourcemaps to get the correct mappings.\n` +
262
+ '\n' +
263
+ source . source ( ) ,
264
+ ] ,
265
+ } )
266
+ ) . toString ( 'base64' )
267
+ )
268
+
269
+ return new ConcatSource (
270
+ source ,
271
+ new RawSource (
272
+ '\n//# sourceMappingURL=' +
273
+ sourceMappingURL +
274
+ // Webpack will add a trailing semicolon. Adding a newline
275
+ // ensures the semicolon is not part of the sourceURL and actually
276
+ // terminates the previous statement.
277
+ '\n'
278
+ )
279
+ // We don't need to add a sourceURL here because that's handled by
280
+ // whatever is running this script. It'll be the file in Node.js
281
+ // and the static asset path in the browser.
282
+ )
283
+ } else {
284
+ return new ConcatSource ( devtoolWarning , source )
285
+ }
286
+ } )
235
287
hooks . chunkHash . tap ( 'EvalSourceMapDevToolPlugin' , ( _chunk , hash ) => {
236
288
hash . update ( 'EvalSourceMapDevToolPlugin' )
237
289
hash . update ( '2' )
0 commit comments