mondaychen / devtools-ignore-webpack-plugin

A Webpack plugin to ignore-list part of sourcemap in Chrome DevTools
MIT License
7 stars 1 forks source link

Support overridden file extension to look for #4

Closed broksonic21 closed 1 month ago

broksonic21 commented 1 month ago

Plugin works great for a number of our projects - thanks @mondaychen!

One issue on a project we have:

Right now, the plugin looks for all assets with a .map extension:

https://github.com/mondaychen/devtools-ignore-webpack-plugin/blob/main/src/index.ts#L61-L63

It then loads it as JSON:

https://github.com/mondaychen/devtools-ignore-webpack-plugin/blob/main/src/index.ts#L71

However, that fails/errors if you have a .map file that isn't a sourcemap (or not in JSON) - as the JSON can fail to process

This can give an error like:

<e> SyntaxError: Unexpected token REDACTED... is not valid JSON
<e>     at JSON.parse (<anonymous>)
<e>     at <anonymous> (/Users/REDACTED/REDACTED/REDACTED/node_modules/devtools-ignore-webpack-plugin/src/index.ts:71:30)
<e>     at fn (/Users/REDACTED/REDACTED/REDACTED/node_modules/webpack/lib/Compilation.js:486:10)
<e>     at _next4 (eval at create (/Users/REDACTED/REDACTED/REDACTED/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:151:1)
<e>     at eval (eval at create (/Users/REDACTED/REDACTED/REDACTED/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:165:1)
<e>     at /Users/REDACTED/REDACTED/REDACTED/node_modules/webpack/lib/Compilation.js:529:10
<e>     at /Users/REDACTED/REDACTED/REDACTED/node_modules/html-webpack-plugin/lib/cached-child-compiler.js:323:53

In our case, we'd prefer this plugin looks for.js.map to avoid this issue, but alternatively, would love an option to pass in the extension to look for. Thinking something like status_map_extension which defaults to .map but could be overridden (in our case, to .js.map but others might have different needs). Bonus points if it accepts an array.

I'm happy to key up a PR, would that be okay?

mondaychen commented 1 month ago

Yes, that makes sense! Would love to see your PR :)

broksonic21 commented 1 month ago

@mondaychen - feel free to propose alternate names or suggestions, but here you go: https://github.com/mondaychen/devtools-ignore-webpack-plugin/pull/5

Would love to get this in, thanks!