@@ -18,6 +18,7 @@ var trim = require("lodash.trim");
1818var format = require ( "util" ) . format ;
1919
2020var defaults = {
21+ skipComments : true ,
2122 extensions : null ,
2223 includePaths : [ ] ,
2324 filter : null ,
@@ -55,6 +56,21 @@ module.exports = function cssImport(options) {
5556 var promises = [ ] ;
5657 var contents = vinyl . contents . toString ( ) ;
5758 while ( ( match = importRe . exec ( contents ) ) !== null ) {
59+ if ( options . skipComments ) {
60+ var matchIndex = match . index ;
61+ // Check comment symbols 1.
62+ var startCommentPosition = contents . lastIndexOf ( '/*' , matchIndex ) ;
63+ var endCommentPosition = contents . lastIndexOf ( '*/' , matchIndex ) ;
64+ if ( ! ( endCommentPosition > startCommentPosition ) && startCommentPosition !== - 1 ) {
65+ continue ;
66+ }
67+ // Check comment symbols 2.
68+ var startCommentPosition2 = contents . lastIndexOf ( '//' , matchIndex ) ;
69+ var endCommentPosition2 = contents . lastIndexOf ( '\n' , matchIndex ) ;
70+ if ( startCommentPosition2 > endCommentPosition2 && startCommentPosition2 !== - 1 ) {
71+ continue ;
72+ }
73+ }
5874 var match2 = / @ i m p o r t \s + (?: u r l \( ) ? ( .+ (? = [ ' " \) ] ) ) (?: \) ) ? .* / ig. exec ( match [ 0 ] ) ;
5975 var importPath = trim ( match2 [ 1 ] , "'\"" ) ;
6076 if ( ! isMatch ( importPath , options ) ) {
@@ -76,7 +92,7 @@ module.exports = function cssImport(options) {
7692 var pathDirectory = path . dirname ( vinyl . path ) ;
7793 var importFile = resolveImportFile ( pathDirectory , importPath , options . includePaths ) ;
7894 if ( ! importFile ) {
79- var err = new Error ( ` Cannot find file '${ importPath } ' from '${ pathDirectory } ' (includePaths: ${ options . includePaths } )` ) ;
95+ var err = new Error ( " Cannot find file '" + importPath + " ' from '" + pathDirectory + " ' (includePaths: " + options . includePaths + ")" ) ;
8096 callback ( new gutil . PluginError ( PLUGIN_NAME , err ) ) ;
8197 }
8298 promises . push ( readFile ( importFile , "utf8" ) . then ( function ( contents ) {
0 commit comments