Strip js, css, and html comments.
npm install strip-comment --save
mocha
<style>
p {
color: red;
/* Css line comment */
text-align: center;
}
/*
* Css block comment
*/
</style>
<!-- html comment -->
<p>This is a paragraph.</p>
// html content
<script>
/*
* Js block comemnt
*/
function displayMsg() {
// Js line comment
alert("Hello World!")
}
</script>
var fs = require('fs');
var html = fs.readFileSync('./index.html', { encoding: 'utf8' });
var strip = require('strip-comment');
strip(html); // Strip js css and html comments.
Strip html css and js comments
- {string}
code
required - {boolean}
keep
[keep = false]
Keep the source code lines and columns
Strip js comments
- {string}
code
required - {boolean}
keep
[keep = false]
var js = 'var a = 3; // comment'
strip.js(js);
strip.js(js, true); // keep code lines
Strip css comments
- {string}
code
required - {boolean}
keep
[keep = false]
var css = 'h2 { /* comment */ font-size : 18px; }'
strip.css(css);
Strip html comments
- {string}
code
required - {boolean}
keep
[keep = false]
var html = '<!-- html comment --><div></div>'
strip.html(html);