Reputation: 1578
The following is my simple gulp task:
gulp.src
is getting script.js
as inputscript.js
and saves script.min.js
console.log
from both script.js
and script.min.js
script.js
file and saves script.min.js
I want to simply remove console.log
from a minified file (or script.min.js
) not from script.js
, and I am failing. I am looking for a way to run .pipe(gulpRemoveLogging...
only on a minified file (i.e. script.min.js
) and do not modify anything from script.js
var gulp = require("gulp"),
minify = require("gulp-minify"),
gulpRemoveLogging = require("gulp-remove-logging");
var _dist_path = "./dist/"; // relative path
// minify JS files
gulp.task("minify-js", function() {
return gulp.src(path.join(_dist_path, "/*.js"))
.pipe(minify({
ext: {
src: ".js",
min: ".min.js"
},
ignoreFiles: ["-min.js"]
}))
.pipe(gulpRemoveLogging({
namespace: ["console", "window.console"] // remove these namespaces. e.g. console.log("..."), window.console.log("...")
}))
.pipe(gulp.dest(_dist_path));
});
Upvotes: 1
Views: 80
Reputation: 1578
Solved the problem:
Added .pipe(gulpIgnore("smartsitescripts.js"))
between .pipe(minify({ ...
and .pipe(gulpRemoveLogging ...
var gulpIgnore = require("gulp-ignore");
...
.pipe(minify({
ext: {
src: ".js",
min: ".min.js"
},
ignoreFiles: ["-min.js"]
}))
.pipe(gulpIgnore("script.js")) // <---- this line solved the problem
.pipe(gulpRemoveLogging({
namespace: ["console", "window.console"] // remove these namespaces. e.g. console.log("..."), window.console.log("...")
}))
...
That line of code will exclude script.js
from stream hence stream will contain only script.min.js
.
Upvotes: 1