gulp-mu-js-cleanup
v1.3.0
Published
Cleaning up JavaScript / PHP / C# source files by removing empty lines, single-line and MULTI-LINE block comments (JSDoc / PHPDoc / C# XML doc), and stray log()/console.log() statements.
Maintainers
Readme
gulp-mu-js-cleanup
Cleans up source files (JavaScript / PHP / C#) for release builds.
A line-based, conservative source cleaner for any language using // line
comments and /* ... */ block comments. In release mode it:
- removes empty / whitespace-only lines,
- removes single-line
//comments (covers C#///XML doc), - removes single-line block comments
/* ... */, - removes multi-line block comments
/** ... */(JSDoc / PHPDoc / C# XML doc) via a small state machine, - removes stray
log(...)/console.log(...)debug statements, - trims leading whitespace.
Comment markers are only matched at the start/end of a trimmed line, so string
literals like "// not a comment" or PHP 8 attributes (#[Route(...)]) are left
intact.
Install
npm install --save-dev gulp-mu-js-cleanupUsage
import jsCleanup from 'gulp-mu-js-cleanup';
function scripts() {
return gulp.src('./src/**/*.js')
.pipe(jsCleanup(isReleaseBuild))
.pipe(gulp.dest('./dist/'));
}API
jsCleanup(isReleaseBuild, removeLineFeeds = false)
| Parameter | Type | Default | Description |
| ----------------- | --------- | ------- | ------------------------------------------------------------------------------------ |
| isReleaseBuild | boolean | — | When true, performs the full cleanup. When false, the source is passed through. |
| removeLineFeeds | boolean | false | When true, also strips line breaks (in release mode, or standalone in debug mode). |
Streams are not supported; pipe buffered files only.
License
MIT
