Comments (4)
Please use this code after fork in your development.
module.exports = function (grunt) {
grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function () {
var Comb = require('csscomb'),
path = require('path'),
defaultConfig = require('../node_modules/csscomb/.csscomb.json');
// Get config file from task's options:
var config = grunt.task.current.options().sortOrder;
// Check if config file is set and exists. If not, use default one:
if (config && grunt.file.exists(config)) {
grunt.log.ok('Using custom config file "' + config + '"...');
config = grunt.file.readJSON(config);
} else {
config = defaultConfig;
}
this.files.forEach(function(f) {
// Create a new instance of csscomb and configure it:
var comb = new Comb();
comb.configure(config);
var destDir = path.dirname(f.dest);
var ext = path.extname(f.dest);
var targetStr = path.basename(f.dest, ext);
f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).forEach(function(src){
var fileName = path.basename(src, ext);
var replacedName = targetStr.replace(/\*/, fileName);
var fileDest = destDir + '/'+ replacedName + ext;
// Get CSS from a source file:
var css = grunt.file.read(src);
// Comb it:
grunt.log.ok('Sorting file "' + src + '"...');
var combed = comb.processString(css);
grunt.file.write(fileDest, combed);
});
});
});
};
You can specify as follows.
csscomb: {
main: {
files: {
'test/fixtures/resorted_*.css': ['test/fixtures/*.css'],
}
}
}
from grunt-csscomb.
Sorry, we can do using dynamic mapping more easily. Try it 👍
https://github.com/csscomb/grunt-csscomb#dynamic-mappings
from grunt-csscomb.
Just a note on the dynamic mapping - I couldn't get it to work using dynamic mapping, but this setup worked -
csscomb: {
default: {
options: {
config: '.csscomb.json',
},
files: [{
expand: true,
cwd: 'assets/css/',
src: ['**/*.css','!**/frameworks/**/*.css'],
dest: 'assets/css/',
ext: '.css'
}]
}
}
from grunt-csscomb.
Thanks #iabw
from grunt-csscomb.
Related Issues (20)
- Suport for sass/scss HOT 2
- Maximum call stack size exceeded in 1.2.0 HOT 5
- Not sure how to make CSSComb plugin sort without unminifying the CSS HOT 4
- Dynamic mapping - overwriting same file HOT 3
- task not sorting, what I'm doing wrong? HOT 3
- Ignoring indentations HOT 1
- Publish new version to npm HOT 5
- 3.0.0-1 issue HOT 2
- @include parse error in SASS (SCSS) HOT 2
- loop tasks
- Lint option is not available HOT 2
- Multiple sources do not work as expected
- console.warn stops CSScomb HOT 1
- In SASS, I can't @extend from a class with a number in it
- Cannot read property of undefined error for SASS files HOT 1
- Large files not running task
- Lift up property "border-color" above "border-bottom" (for example). HOT 3
- Cannot support the latest grunt version v1.0.0 HOT 1
- Security warning in [email protected] - Update csscomb package HOT 1
- Version 4.0.0 is not available using npm HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-csscomb.