Browserify transform that strips console.log
lines from your code.
This module for browserify will remove console.log
, console.info
, console.warn
, console.error
, debugger
and friends from your js files.
For example.js:
var foo = "bar"
console.log(foo + " bar")
foo = "foo"
then on the command line:
browserify -t stripify example.js > bundle.js
or with the api:
var browserify = require("browserify")
, fs = require("fs")
var b = browserify("example.js")
b.transform("stripify")
b.bundle().pipe(fs.createWriteStream("bundle.js"))
the bundle file output is:
var foo = "bar"
foo = "foo"
npm install stripify
As with all browserify transforms, stripify returns a through/transform stream.
var fs = require("fs")
, stripify = require("stripify")
, src = "/path/to/file.js"
, dest = "/path/to/file-transformed.js"
, ts = stripify(src)
fs.createReadStream(src).pipe(ts).pipe(fs.createWriteStream(dest))
You can use stripify on the command line as well:
npm install -g stripify
stripify /path/to/file.js
Output is written to stdout.
Stripify will remove console.log
statements by default. If you've put a log statement in a weird place, removing it could cause a syntax error. The replacement
option allows you to specify a replacement statement.
e.g.
echo "console.log('foo')" | stripify -r '(0)' # Outputs (0)
browserify main.js -t [stripify -r '(0)']
var stripify = require("stripify")
stripify("file.js", {replacement: '(0)'})