5.0.0 • Published 4 years ago

strip-css-comments v5.0.0

Weekly downloads
47,231
License
MIT
Repository
github
Last release
4 years ago

strip-css-comments

Strip comments from CSS

Also available as a Gulp/Grunt/Broccoli plugin.

Usage

$ npm install strip-css-comments

Usage

import stripCssComments from 'strip-css-comments';

// By default important comments `/*!` are preserved
stripCssComments('/*! <copyright> */ body { /* unicorns */color: hotpink; }');
//=> '/*! <copyright> */ body { color: hotpink; }'

// `preserve: false` will strip all comments including `/*!`
stripCssComments(
	'/*! <copyright> */ body { /* unicorns */color: hotpink; }',
	{preserve: false}
);
//=> 'body { color: hotpink; }'

// Preserve comments based on a regex
stripCssComments(
	'/*# preserved */ body { /* unicorns */color: hotpink; }',
	{preserve: /^#/}
);
//=> '/*# preserved */ body { color: hotpink; }'

// Preserve comments based on the return value of the supplied function
stripCssComments(
	'/*# preserved */ body { /* unicorns */color: hotpink; }',
	{
		preserve: comment => comment.charAt(0) === '#'
	}
);
//=> '/*# preserved */ body { color: hotpink; }'

API

stripCssComments(cssString, options?)

cssString

Type: string

String with CSS.

options

Type: object

preserve

Type: boolean | RegExp | Function\ Default: true

  • true - Preserve important comments /*! */.
  • false - Strip all comments.
  • RegExp - Preserve comments where the comment body matches a regular expression.
  • Function - Preserve comments for which a function returns true. The function is called on each comment, gets the comment body as the first argument, and is expected to return a boolean of whether to preserve the comment.

whitespace

Type: boolean\ Default: true

Replace comments with whitespace instead of stripping them entirely.

Benchmark

$ npm run bench

Related

@alotool/bloggerpack@alotool/alotool-clissr-engine@infinitebrahmanuniverse/nolb-strip@everything-registry/sub-chunk-2837tachyons-generatortaskerifytach-stripvvpay-loadervux-fix-loadervux-loadervux-loader-cli4vux-loader-stzhangvux-loader88888vux-lvya-loadervux-plus-loaderwxparcel-corexf-vux-loadervant-theme-generator-new@cmep/vux-loader@compai/themes@compai/mqify@cake-hub/showroom@bpiwek/frontbox-kss-styleguide@blueprintjs/node-build-scripts@blueprint-modernized/node-build-scriptsjrmf-loaderkaixin-vux-loaderk12vux-loaderstrip-css-comments-cliukx-loaderumi-theme-generator@arcanis-inc/tachyons-generator@alotool/bl-pack@alotool/blogger-pack@beautycss/vux-loader@ad2302/antd-theme-webpack-plugin@coffeekraken/sugaryihan-vux-loaderzhdsh-loaderztuidev-loaderztui-loaderzzr-loaderwebpack-resource-localize-pluginwebrenderuplanapp-loaderupanapp-loaderv3-platform-utilsvaadin-flow-bomzdsh-loaderzing-vux-loaderzkui-loaderzingvux11@hai-ui/node-build-scripts@foundbyte/antd-theme-generator@lotsof/sugar@holokit/node-build-scripts@omneedia/cli@patarapolw/scope-cssmqifymyvuxloadeross-ui-theme-webpack-pluginscope-cssrruntnext-antd-dark-modeng-stamy-plugin-themeppd-themeshane-sfdx-pluginssindredashsindresorhus.jsgrunt-strip-css-commentsgulp-rb-validate-cssgulp-rb-validate-minifiedgulp-strip-css-commentsgulp-js-sasshomedtvux-loaderless-imports-extractormbake@vux/loader@vtex/tachyons-generator@xyezir/vux-loader@steelydylan/scope-cssantd-theme-full-generatorantd-theme-generatorantd-theme-generator-fit5antd-theme-generator-gant-theme-generatorcfg-toolkit-nextcfa-toolkit-nextcc-antd-theme-generatorcorex-theme-generatorcss2stringcss-concat-loadercss-prefixerbloggerpackbrowserify-cssbroccoli-strip-css-commentsdt-vux-loaderfix-less-antd-theme-generatorgatsby-plugin-uncss
5.0.0

4 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.0

10 years ago

2.1.0

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.1

11 years ago

1.0.0

11 years ago