massick / gulp-strip-code

A gulp plugin to remove parts of code based on regular expressions.
MIT License
25 stars 6 forks source link

Code is not stripped when comment has an exclamation, such as /*! #4

Closed edtalmadge closed 8 years ago

edtalmadge commented 8 years ago

For example, the following example code is not removed as expected:

/*! start-removeMe */
.helloWorld {color: red;}
/*! end-removeMe */

But, if I were to remove the exclamation points, it is removed just fine.

I need the exclamation points because my goal is to run gulp-strip-code on my files after gulp-sass is done with them. And, gulp-sass only preserves comments that have an exclamation point.

edtalmadge commented 8 years ago

I was able to resolve the issue by updating the default pattern. Added a couple instances of "!? ": var pattern = options.pattern || new RegExp("([\\t ]*\\/\\*\!? ?" + options.start_comment + " ?\\*\\/)[\\s\\S]*?(\\/\\*\!? ?" + options.end_comment + " ?\\*\\/[\\t ]*\\n?)", "g");

edtalmadge commented 8 years ago

I added a pull request:

6

massick commented 8 years ago

I tried and I was able to achieve what you want using: start_comment: "! start-removeMe", end_comment: "! end-removeMe" If the problem is different just provide me an example how to reproduce your case. @edtalmadge

edtalmadge commented 8 years ago

Thanks @massick, here is an example.

To summarize: I have a gulp task which first compiles the sass file style.scss, then runs gulp-strip-code. The gulp-strip-code comment markers are in backgrounds.scss, which is imported by style.scss.

Gulp Task:

gulp.task("sass", function () {

    gulp.src(['sass/style.scss'])
        .pipe(sass({ outputStyle: 'expanded' }))
        .pipe(stripCode({
            start_comment: "start-stripFromNR",
            end_comment: "end-stripFromNR"
        }))
        .pipe(gulp.dest('sass/css/'));
}

style.scss (processed by the above task):

@import "../sass/mixins/_backgrounds.scss";

backgrounds.scss (imported in the above style.scss):

/*! start-stripFromNR */

.helloWorld { color: red; }

/*! end-stripFromNR */
massick commented 8 years ago

yes, but what about using

start_comment: "! start-stripFromNR",
end_comment: "! end-stripFromNR"

if you want to strip out the code in between?

edtalmadge commented 8 years ago

You are right, that works. I was able to update my code and verify.

massick commented 8 years ago

Cool, I will close the PR then!