install node.js
tar xf node-v0.12.0.tar.gz
cd node-v0.12.0
./configure
make
sudo make install
update npm
sudo npm install npm -g
install Grunt CLI
sudo npm install -g grunt-cli
install Grunt bake
cd path/to/your/project
npm install grunt-bake --save-dev
create Gruntfile.js in your project root
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig( {
bake: {
your_target: {
files: {
// files to: from, ...:
"index.html": "app/index.html",
"mobile.html": "app/mobile.html"
}
},
},
});
// Load the plugin
grunt.loadNpmTasks( "grunt-bake" );
// Default task(s).
grunt.registerTask('default', ['bake']);
};
create app/index.html
<!--(bake includes/head.html title="おらホームページ")-->
<!--(bake includes/foot.html)-->
create app/includes/head.html
<!--(bake contents.html)-->
create app/includes/foot.html
create app/includes/contents.html
<div id="container">hello
</div>
run grunt
$ grunt
and this bake task will create index.html:
<div id="container">hello
</div>
参考
grunt-rsync
npm install grunt-rsync
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig( {
bake: {
// bake config
},
rsync: {
options: {
exclude: ['app',
'node_modules',
'README.txt',
'package.json',
'Gruntfile.js',
'.htaccess'],
recursive: true,
syncDest: false, // コピー先に存在しないファイルを削除しない
},
dist: {
options: {
src: "./", // コピー元ディレクトリ
dest: "~/www", // コピー先ディレクトリ
host: "username@host", // コピー先ホスト
// private-key を使えるようにしておく ~/.ssh/id_rsa
}
},
}
});
grunt.loadNpmTasks('grunt-rsync');
// Default task(s).
grunt.registerTask('default', ['bake', 'rsync']);
};
最終更新:2015年02月20日 22:07