├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── gulpfile.babel.js ├── lib └── strip-inline-comments.es6 ├── package.json └── test ├── fixture.css ├── fixture.expect.css └── test.es6 /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015-loose", "stage-0"], 3 | "plugins": ["add-module-exports", "precompile-charcodes"] 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.{json,yml}] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "eslint-config-postcss", 4 | "rules": { 5 | "key-spacing": [2, { "align": "value" }], 6 | "complexity": [0] 7 | }, 8 | "env": { 9 | "mocha": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | 4 | node_modules/ 5 | npm-debug.log 6 | 7 | build/ 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | 3 | node_modules/ 4 | npm-debug.log 5 | 6 | build/ 7 | 8 | test/ 9 | .travis.yml 10 | 11 | gulpfile.babel.js 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "5" 5 | - "4" 6 | - "0.12" 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.5 2 | * Updated to walkComments 3 | 4 | ## 0.1 5 | * Initial release. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2013 Francis Saul 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostCSS strip inline comments [![Build Status](https://travis-ci.org/mummybot/postcss-strip-inline-comments.svg?branch=master)](https://travis-ci.org/mummybot/postcss-strip-inline-comments) 2 | 3 | 6 | 7 | A plugin to remove inline CSS comments from compilation. 8 | 9 | ```scss 10 | /* This comment will remain */ 11 | // This comment will be removed 12 | body { 13 | // This comment will also be removed 14 | background-color: black; 15 | } 16 | // And so will this one 17 | ``` 18 | 19 | ## Usage 20 | 21 | You need to have a compliant parser, currently either [postcss-scss](https://github.com/postcss/postcss-scss) or [sugarss](https://github.com/postcss/sugarss) already parsing your postcss for this plugin to work. 22 | 23 | ### Install 24 | 25 | ```npm install postcss-strip-inline-comments --save-dev``` 26 | 27 | ### Grunt 28 | 29 | ```javascript 30 | grunt.initConfig({ 31 | postcss: { 32 | options: { 33 | processors: [ 34 | require('postcss-strip-inline-comments'), 35 | ], 36 | syntax: require('postcss-scss') 37 | }, 38 | dist: { 39 | src: 'css/*.css' 40 | } 41 | } 42 | }); 43 | ``` 44 | 45 | ### Gulp 46 | 47 | ```javascript 48 | var gulp = require('gulp'); 49 | var postcss = require('gulp-postcss'); 50 | var stripInlineComments = require('postcss-strip-inline-comments'); 51 | var scss = require('postcss-scss'); 52 | 53 | gulp.task('default', function () { 54 | var processors = [stripInlineComments]; 55 | return gulp.src('in.css') 56 | .pipe(postcss(processors, {syntax: scss})) 57 | .pipe(gulp.dest('out')); 58 | }); 59 | ``` 60 | 61 | ### Webpack 62 | 63 | ```javascript 64 | var stripInlineComments = require('postcss-strip-inline-comments'); 65 | 66 | var config = { 67 | ... 68 | 69 | module: { 70 | loaders: [ 71 | { 72 | test: /\.s?css$/, 73 | loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap&importLoaders=1!postcss-loader?parser=postcss-scss') 74 | } 75 | ] 76 | }, 77 | postcss: function(webpack) { 78 | return [ 79 | stripInlineComments 80 | ]; 81 | }, 82 | ... 83 | } 84 | ``` 85 | 86 | ### Node 87 | 88 | ```javascript 89 | import postcss from 'postcss'; 90 | import syntax from 'postcss-scss'; 91 | import stripInlineComments from 'postcss-strip-inline-comments'; 92 | 93 | let css = fs.readFileSync('style.css', 'utf8'); 94 | 95 | postcss([stripInlineComments]).process(css, { parser: syntax }).then( result => { 96 | console.log(result.css); 97 | }); 98 | ``` 99 | -------------------------------------------------------------------------------- /gulpfile.babel.js: -------------------------------------------------------------------------------- 1 | import gulp from 'gulp'; 2 | 3 | gulp.task('clean', () => { 4 | let del = require('del'); 5 | return del(['build/']); 6 | }); 7 | 8 | // Build 9 | 10 | gulp.task('build:lib', ['clean'], () => { 11 | let babel = require('gulp-babel'); 12 | return gulp.src('lib/*.es6') 13 | .pipe(babel()) 14 | .pipe(gulp.dest('build/lib')); 15 | }); 16 | 17 | gulp.task('build:docs', ['clean'], () => { 18 | let ignore = require('fs').readFileSync('.npmignore').toString() 19 | .trim().split(/\n+/) 20 | .concat(['.npmignore', 'package.json', 'index.js']) 21 | .map( i => '!' + i ); 22 | return gulp.src(['*'].concat(ignore)) 23 | .pipe(gulp.dest('build')); 24 | }); 25 | 26 | gulp.task('build:package', ['clean'], () => { 27 | let editor = require('gulp-json-editor'); 28 | gulp.src('./package.json') 29 | .pipe(editor( json => { 30 | json.main = 'lib/strip-inline-comments'; 31 | for ( let i in json.dependencies ) { 32 | if ( /^babel-/.test(i) ) { 33 | json.devDependencies[i] = json.dependencies[i]; 34 | delete json.dependencies[i]; 35 | } 36 | } 37 | return json; 38 | })) 39 | .pipe(gulp.dest('build')); 40 | }); 41 | 42 | gulp.task('build', ['build:lib', 'build:docs', 'build:package']); 43 | 44 | // Lint 45 | 46 | gulp.task('lint', () => { 47 | let eslint = require('gulp-eslint'); 48 | return gulp.src(['*.js', 'lib/*.es6', 'test/*.es6']) 49 | .pipe(eslint()) 50 | .pipe(eslint.format()) 51 | .pipe(eslint.failAfterError()); 52 | }); 53 | 54 | // Test 55 | 56 | gulp.task('test', () => { 57 | require('babel-core/register')({ extensions: ['.es6'], ignore: false }); 58 | let mocha = require('gulp-mocha'); 59 | return gulp.src('test/*.es6', { read: false }).pipe(mocha()); 60 | }); 61 | 62 | gulp.task('integration', done => { 63 | require('babel-core/register')({ extensions: ['.es6'], ignore: false }); 64 | let postcss = require('postcss'); 65 | let real = require('postcss-parser-tests/real'); 66 | let scss = require('postcss-scss'); 67 | real(done, css => { 68 | return postcss().process(css, { 69 | parser: scss, 70 | map: { annotation: false } 71 | }); 72 | }); 73 | }); 74 | 75 | // Common 76 | 77 | gulp.task('default', ['lint', 'test']); 78 | -------------------------------------------------------------------------------- /lib/strip-inline-comments.es6: -------------------------------------------------------------------------------- 1 | import postcss from 'postcss'; 2 | 3 | export default postcss.plugin('postcss-strip-inline-comments', () => { 4 | return css => { 5 | css.walkComments(i => { 6 | if ( i.raws.inline ) i.remove(); 7 | }); 8 | }; 9 | }); 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-strip-inline-comments", 3 | "version": "0.1.5", 4 | "description": "Strip inline comments using the postcss-scss parser", 5 | "keywords": [ 6 | "css", 7 | "postcss", 8 | "postcss-syntax", 9 | "comments", 10 | "scss", 11 | "sass" 12 | ], 13 | "author": "Mummybot ", 14 | "license": "MIT", 15 | "repository": "mummybot/postcss-strip-inline-comments", 16 | "dependencies": { 17 | "babel-plugin-precompile-charcodes": "1.0.0", 18 | "babel-plugin-add-module-exports": "0.1.2", 19 | "babel-preset-es2015-loose": "7.0.0", 20 | "babel-preset-stage-0": "6.5.0", 21 | "babel-preset-es2015": "6.6.0", 22 | "babel-core": "6.6.5", 23 | "postcss": "^5.0.18" 24 | }, 25 | "devDependencies": { 26 | "babel-eslint": "5.0.0", 27 | "chai": "3.5.0", 28 | "chai-as-promised": "^5.2.0", 29 | "del": "2.2.0", 30 | "eslint": "2.2.0", 31 | "eslint-config-postcss": "2.0.0", 32 | "gulp": "3.9.1", 33 | "gulp-babel": "6.1.2", 34 | "gulp-eslint": "2.0.0", 35 | "gulp-json-editor": "2.2.1", 36 | "gulp-mocha": "2.2.0", 37 | "mocha": "2.4.5", 38 | "postcss-parser-tests": "5.0.6", 39 | "postcss-scss": "^0.1.7" 40 | }, 41 | "scripts": { 42 | "test": "gulp", 43 | "build": "gulp build" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/fixture.css: -------------------------------------------------------------------------------- 1 | /* 1. Comment to remain */ 2 | // 2. Comment to remove 3 | a { 4 | // 3. Comment to remove 5 | span { 6 | // 4. Comment to remove 7 | background-color: black; // 5. Comment to remove 8 | } 9 | &.test { // 6. Comment to remove 10 | // 7. Comment to remove; // 11 | background-color: black; 12 | } 13 | } 14 | // 8. Comment to remove -------------------------------------------------------------------------------- /test/fixture.expect.css: -------------------------------------------------------------------------------- 1 | /* 1. Comment to remain */ 2 | a { 3 | span { 4 | background-color: black; 5 | } 6 | &.test { 7 | background-color: black; 8 | } 9 | } -------------------------------------------------------------------------------- /test/test.es6: -------------------------------------------------------------------------------- 1 | import stripInlineComments from '../lib/strip-inline-comments'; 2 | 3 | import chai from 'chai'; 4 | import chaiAsPromised from 'chai-as-promised'; 5 | import postcss from 'postcss'; 6 | import fs from 'fs'; 7 | import syntax from 'postcss-scss'; 8 | 9 | chai.use(chaiAsPromised); 10 | let expect = chai.expect; 11 | 12 | function getFixtures(fixture) { 13 | let ret = {}; 14 | 15 | function readFS(name) { 16 | return fs.readFileSync('test/' + name + '.css', 'utf8'); 17 | } 18 | 19 | ret.test = readFS(fixture); 20 | ret.expect = readFS(fixture + '.expect'); 21 | 22 | return ret; 23 | } 24 | 25 | describe('strip single line comments', () => { 26 | 27 | it('strip stingle line comments', done => { 28 | let fixture = getFixtures('fixture'); 29 | 30 | postcss([stripInlineComments]) 31 | .process(fixture.test, { parser: syntax }).then( result => { 32 | expect(result.css).to.eql(fixture.expect); 33 | done(); 34 | }).catch(done); 35 | }); 36 | }); 37 | --------------------------------------------------------------------------------