Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created February 18, 2014 13:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hail2u/9070532 to your computer and use it in GitHub Desktop.
Save hail2u/9070532 to your computer and use it in GitHub Desktop.
Load Grunt plugin config from `.grunt/config/*.json` and load Grunt tasks from `package.json`.
{
"css": {
"src": [".grunt/tmp/*.css"]
},
"js": {
"src": [".grunt/tmp/*.js"]
}
}
{
"css": {
"expand": true,
"cwd": ".grunt/css/",
"src": ["*.css"],
"dest": ".grunt/tmp/"
},
"js": {
"expand": true,
"cwd": ".grunt/js/",
"src": ["*.js"],
"dest": ".grunt/tmp/"
}
}
{
"main": {
"expand": true,
"cwd": ".grunt/tmp/",
"src": ["*.css"],
"dest": "styles/",
"ext": ".min.css"
}
}
/
├─.grunt/
│ ├─css/
│ │ └─style.css
│ ├─js/
│ │ └─script.js
│ ├─tmp/
│ └─config/
│ ├─clean.json
│ ├─copy.json
│ ├─cssmin.json
│ └─uglify.json
├─scripts/
│ └─scripts.min.js
├─style/
│ └─style.mincss
└─Gruntfile.js
'use strcit';
var path = require('path');
module.exports = function (grunt) {
var config = {
pkg: grunt.file.readJSON('package.json')
};
grunt.file.expand('.grunt/config/*.json').forEach(function (file) {
config[path.basename(file, '.json')] = grunt.file.readJSON(file);
});
grunt.initConfig(config);
for (var devDependency in grunt.config.data.pkg.devDependencies) {
if (devDependency.match(/^grunt-/)) {
grunt.loadNpmTasks(devDependency);
}
}
grunt.util.linefeed = '\n';
grunt.registerTask('rebuild:css', [
'clean:css',
'copy:css',
'cssmin'
]);
grunt.registerTask('rebuild:js', [
'clean:js',
'copy:js',
'uglify'
]);
};
{
"options": {
"beautify": {
"ascii_only": true
},
"preserveComments": "some"
},
"main": {
"expand": true,
"cwd": ".grunt/tmp/",
"src": ["*.js"],
"dest": "scripts/",
"ext": ".min.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment