@@ -154,6 +154,60 @@ module.exports = {
154154 ) ;
155155 } ,
156156 } ) ,
157+ {
158+ apply ( compiler ) {
159+ const { RawSource} = compiler . webpack . sources ;
160+
161+ compiler . hooks . compilation . tap (
162+ 'CustomContentForHookScriptPlugin' ,
163+ compilation => {
164+ compilation . hooks . processAssets . tap (
165+ {
166+ name : 'CustomContentForHookScriptPlugin' ,
167+ stage : Webpack . Compilation . PROCESS_ASSETS_STAGE_DEV_TOOLING ,
168+ additionalAssets : true ,
169+ } ,
170+ assets => {
171+ // eslint-disable-next-line no-for-of-loops/no-for-of-loops
172+ for ( const [ name , asset ] of Object . entries ( assets ) ) {
173+ if ( name !== 'installHook.js.map' ) {
174+ continue ;
175+ }
176+
177+ const mapContent = asset . source ( ) . toString ( ) ;
178+ if ( ! mapContent ) {
179+ continue ;
180+ }
181+
182+ const map = JSON . parse ( mapContent ) ;
183+ map . sourcesContent = map . sources . map ( sourceName => {
184+ if ( ! sourceName . endsWith ( '/hook.js' ) ) {
185+ return null ;
186+ }
187+
188+ return (
189+ '/*\n' +
190+ ' * This is the script from React DevTools.\n' +
191+ " * You're likely here because you thought it sent an error or warning to the Console.\n" +
192+ " * React DevTools patches the Console to support features like appending component stacks. That's why this file appears as a source.\n" +
193+ ' * The console call actually came from another script.\n' +
194+ " * Since your browser DevTools weren't open yet, ignore listing wasn't applied, and now you see this script.\n" +
195+ ' * To find the real source, make sure your browser DevTools are open before these console calls happen.\n' +
196+ ' */'
197+ ) ;
198+ } ) ;
199+
200+ compilation . updateAsset (
201+ name ,
202+ new RawSource ( JSON . stringify ( map ) ) ,
203+ ) ;
204+ }
205+ } ,
206+ ) ;
207+ } ,
208+ ) ;
209+ } ,
210+ } ,
157211 ] ,
158212 module : {
159213 defaultRules : [
0 commit comments