Skip to content

Instantly share code, notes, and snippets.

@jrencz
Last active August 29, 2015 14:04
Show Gist options
  • Save jrencz/e110dbbd594c54cfd1d6 to your computer and use it in GitHub Desktop.
Save jrencz/e110dbbd594c54cfd1d6 to your computer and use it in GitHub Desktop.
Grunt task to strip unnecessary imports from the sass files
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