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