- Automatically recognizes HTML and removes all
<!-- comments -->from it
- Does not change layout / formatting of the original document
- Removes lines that have only comments on them
- Compatible with CSS3, JSON5 and ECMAScript 6
$ npm install --save-dev gulp-strip-comments
var gulp = ;var strip = ;gulp;
See decomment for examples and more information.
let strip = require('gulp-strip-comments') // == decomment
This method first checks if the code starts with
<, as an HTML, and if so, all
<!-- comment --> entries
are removed, according to the
through [esprima] for ECMAScript 6 compliance, and to extract details about regular expressions.
If [esprima] fails to validate the code, it will throw a parsing error. When successful, this method will remove
/**/ comments according to the
options (see below).
options.safe ⇒ Boolean
false (default)- remove all multi-line comments
true- keep special multi-line comments that begin with:
<!--[if- for conditional comments in HTML
/*!- for everything else (other than HTML)
options.ignore ⇒ RegExp | [RegExp,...]
Takes either a single or an array of regular expressions to match against. All matching blocks are then skipped, as well as any comment-like content inside them.
- CSS may contain Base64-encoded strings with comment-like symbols:
You can isolate all
url(*) blocks by using:
- If you want to isolate jsDoc blocks (start with
/**, followed by a line break, end with
*/), you can use the following:
options.space ⇒ Boolean
false (default)- remove comment blocks entirely
true- replace comment blocks with white spaces where needed, in order to preserve the original line + column position of every code element.
NOTE: When this option is enabled, option
trim is ignored.
options.trim ⇒ Boolean
false (default)- do not trim comments
true- remove empty lines that follow removed full-line comments
NOTE: This option has no effect when option
space is enabled.
Unlike the default strip method, it instructs the library that
/**/ comments from it according to the
This method is good for any text file that uses syntax
/**/ for comments, such as:
Please note that while the same rules apply for the text blocks (
Unlike the default strip method, it instructs the library not to parse
or validate the input in any way, rather assume it to be HTML, and remove all
<!-- comment --> entries from it according to the
Returns End-of-Line string used within the
text, based on the occurrence frequency:
\n- for Unix-encoded text
\r\n- for Windows-encoded text
When impossible to conclude (the same or 0 occurrence), it returns the default End-of-Line for the current OS.