Created
April 16, 2013 14:48
-
-
Save fnobi/5396523 to your computer and use it in GitHub Desktop.
grunt-pluginの作り方と解剖 ref: http://qiita.com/items/5590e7e92b4f2bd81d04
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
var grunt = require('grunt'); | |
grunt.registerTask('sample', 'sample task', function () { | |
console.log('this is sample task!'); | |
}); |
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 sample | |
this is sample task! |
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
var fs = require('fs'); | |
module.exports = function (grunt) { | |
grunt.registerTask('sample', 'sample task', function () { | |
// 環境名の取得 | |
var target = this.target; | |
// 非同期タスクにする(doneにcallback関数が入る) | |
var done = grunt.async(); | |
// configから"filename"を取得 | |
var filename = grunt.config('sample')[target].filename; | |
fs.readFile(filename, 'utf8', function (err, data) { | |
// ファイルをreadするのを待って、出力したら終了 | |
console.log(data); | |
done(); | |
}); | |
}); | |
}; |
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 simple:dev | |
hogehoge | |
% grunt simple:prod | |
moge | |
% grunt simple | |
hogehoge | |
moge |
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
var grant = require('grunt'); | |
module.exports = function () { | |
grunt.initConfig({ | |
sample: { | |
dev: { // 開発環境 | |
hoge: 'hogehoge' | |
}, | |
prod: { // 本番環境 | |
hoge: 'moge' | |
} | |
} | |
}); | |
grunt.loadNpmTask('grunt-sample'); | |
}; |
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
{ | |
"name": "grunt-sample", | |
"version": "0.0.1", | |
"description": "sample grunt plugin", | |
"keywords": [ | |
"gruntplugin" | |
], | |
"devDependencies": { | |
"grunt": "~0.4.1" | |
} | |
} |
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
module.exports = function (grunt) { | |
grunt.registerTask('sample', 'sample task', function () { | |
console.log('this is sample task!'); | |
}); | |
}; |
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
module.exports = function (grunt) { | |
grunt.registerMultiTask('sample', 'sample task', function () { | |
// 環境名の取得 | |
var target = this.target; | |
// configから"hoge"を取得 | |
var hoge = grunt.config('sample')[target].hoge; | |
console.log(hoge); | |
}); | |
}; |
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-sample | |
├── package.json | |
└── tasks | |
└── sample.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment