stripify

Browserify transform that strips console.log lines from your code

MIT 9 个版本
安装
npm install stripify
yarn add stripify
pnpm add stripify
bun add stripify
README

stripify Build Status Dependency Status

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.

Example

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"

Usage

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))

Command line

You can use stripify on the command line as well:

npm install -g stripify
stripify /path/to/file.js

Output is written to stdout.

Options

--replacement=STATEMENT, -r STATEMENT

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)'})
版本列表
6.0.0 2016-09-20
5.0.0 2016-09-19
4.0.0 2016-01-12
3.0.0 2015-03-06
2.0.0 2014-12-05
1.2.0 2014-04-02
1.1.0 2014-04-01
1.0.0 2014-04-01
0.0.0 2014-04-01