Last active
August 29, 2015 14:04
-
-
Save jrencz/e110dbbd594c54cfd1d6 to your computer and use it in GitHub Desktop.
Grunt task to strip unnecessary imports from the sass files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerMultiTask('sassStripImports', | |
'Strips @import statements from the top of SCSS files', | |
// Stripping imports prevents code duplication yet still allows IDEs to properly resolve variables. | |
function () { | |
var options = this.options(); | |
this.files.forEach(function (mapping) { | |
grunt.file.expand(mapping.src).forEach(function (path) { | |
grunt.file.write(path, grunt.file.read(path).replace((options.pattern || /@import\s\".+\";/), '')); | |
}); | |
}); | |
} | |
); | |
grunt.initConfig({ | |
sassStripImports: { | |
options: { | |
// Don't strip imports including files starting with _partial (accessed on the same or other path) | |
pattern: /@import\s\"(?!(.*\/?)*_partial).+\";/, | |
}, | |
app: { | |
src: [ | |
'app/modules/**/_*.tmp.scss', // remember to create copies and then use them | |
], | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment