Question

I need to replace a String someString by another anotherString in my JS files, e.g.

function someString() { ... }

should become

function anotherString() { ... }

in brunch (can be pre- or post-compilation, however I would like to avoid copying all files to a temporary location).

Running this in onCompile works, however it seems to break sourceMaps (because the Strings are not the same length).

Is there a sourceMap-safe way to do this?

Was it helpful?

Solution

I had the exact same question and wrote this little script:

https://www.npmjs.org/package/sourcemap-aware-replace

usage:

sourcemap-aware-replace --search=foo --replace=barr --in-map=test.js.map --out-file=test.replaced.js
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top