@@ -154,6 +154,59 @@ module.exports = {
154
154
) ;
155
155
} ,
156
156
} ) ,
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 script is 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, \n' +
193
+ ' * so this file appears as a source. However, the console call actually came from another script.\n' +
194
+ " * To remove this script from stack traces, open your browser's DevTools (to enable source mapping) before these console calls happen.\n" +
195
+ ' */'
196
+ ) ;
197
+ } ) ;
198
+
199
+ compilation . updateAsset (
200
+ name ,
201
+ new RawSource ( JSON . stringify ( map ) ) ,
202
+ ) ;
203
+ }
204
+ } ,
205
+ ) ;
206
+ } ,
207
+ ) ;
208
+ } ,
209
+ } ,
157
210
] ,
158
211
module : {
159
212
defaultRules : [
0 commit comments