昨日のつづき
Lessãã³ãã³ãã©ã¤ã³ããã³ã³ãã¤ã«ããæ¹æ³ã調ã¹å§ãã¦ãåºæ¬çãªã³ã³ãã¤ã«ã¯lesscã§ã§ãããã©ããã¡ã¤ã«ãç£è¦ããæ©è½ããªããã¨ãããã£ãã
ãã¡ã¤ã«æ´æ°ãããã³ã³ãã¤ã«ãã¦ã»ããï¼ï¼ï¼
Lessãã¡ã¤ã«ãwatchããã«ã¯è²ã
ããããã©
less-watch
less を自動コンパイルしたい - 人生いきあたりばったりで生きてます@はてな
ãã£ããã®æ©ä¼ãªã®ã§ãååã ãèãã¦ããGruntã使ã£ã¦ã¿ããã¨æã£ãã
Sass+Compassç¹éã§ãã¾ãã¾ä»æè²·ã£ãWEB+DB PRESSã«id:naoyaããã®Gruntè¨äºããã£ããï¼
- ä½è : ä¸å·å樹,å±±å æ²ç,èå´å¥æ²»,åèç¥ä¸,ä»äºé太,å «æ¨æ©å¾¹å¹³,å®å·å¥å¤ª,è¿è¤å®æºæ,奥éå¹¹ä¹,天éç¥ä»,è³æã«ã¤,ä¼è¤ç´ä¹,ä½å·è£å²³,åå·è²´ä¹ ,è åä¸å¿,å¾è¤ç§å®£,ä¹ æ£®éé,ç»å°¾å¾³èª ,渡éæµå¤ª,ä¸å³¶è¡,A-Listers,å°ä¿£è£ä¸,ã¯ã¾ã¡ã2,å·æ·»è²´ç,ç³æ¬å å¸,èéç¥ä¸,æ²ç°é¦å¤«,澤ææ£æ¨¹,åé¨æå¹³,åè¤åè¨,çå±±æé,å¹³å±±æ¯ ,WEB+DB PRESSç·¨éé¨
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/10/24
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (2件) ãè¦ã
ããããGruntã¨ã¯
Gruntã¯ããã³ãã¨ã³ãã主ã«ã¯JavascriptãCSSå¨ãã®ä½æ¥ãèªååããããã®ã¿ã¹ã¯ã©ã³ãã¼ãã¼ã«ã§ã
(WEB+DB PRESS Vol.77 Gruntã«ããããã³ãã¨ã³ãéçºä½æ¥ã®èªåå P138)
Lessãã¡ã¤ã«ã®æ´æ°ãæ¤ç¥ãã â Lessãã¡ã¤ã«ãã³ã³ãã¤ã«ãã â æå®ãããã£ã¬ã¯ããªã«cssãã¡ã¤ã«ãåºåãã
ã¨ããã¨ãããèªååãã¦ãããããã«ä½¿ãã
Gruntã®ã¤ã³ã¹ãã¼ã«
$ npm install -g grunt-cli $ grunt -v $ grunt -v grunt-cli: The grunt command line interface. (v0.1.9) Fatal error: Unable to find local grunt. If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started
npm installã®-gãªãã·ã§ã³ã¯ãç¾å¨ãããã£ã¬ã¯ããªã ãã§ã¯ãªãå
¨ä½ã§ä½¿ããããã®ããããã¨ã(global)ã«ã¤ãããªãã·ã§ã³ã
ã¨ã©ã¼ãåºã¦ããã®ã¯ãLessãç£è¦ããããã®ããã¸ã§ã¯ã(ãã£ã¬ã¯ããª)ã«å¥éGruntãå
¥ããå¿
è¦ãããããã
ãµã³ãã«ã«ä»¥ä¸ã®ãã£ã¬ã¯ããªã¨ãã¡ã¤ã«ãç¨æ âââ sandbox â  âââ css â  âââ less â  ã  âââ default.css â  ã  âââ default.less # ãã£ã¬ã¯ããªã«ç§»å $ cd sandbox $ npm install grunt $ ls css less node_modules
ããã¸ã§ã¯ããã¨ã«gruntã使ãã®ã§ãä»åº¦ã¯-gãªãã·ã§ã³ãã¤ããã«gruntãã¤ã³ã¹ãã¼ã«ã
ããããã¨ãã£ã¬ã¯ããªã®ä¸ã«node_modulesãã¡ã¤ã«ãçæãããã
ã¿ã¹ã¯ã®è¨å®(ãã©ã°ã¤ã³ã®å°å ¥ã¨Grunt.jsã®ä½æ)
Gruntèªä½ã¯ã¿ã¹ã¯èªååãã¼ã«ãªã®ã§ããªã«ãããã®ãæ示ãããªãã¨ãããªãã
ã¿ã¹ã¯ãæ¸ãããjsãã¡ã¤ã«ããã©ã°ã¤ã³ã¨ãã¦å
¬éããã¦ããã
gruntjs/grunt-contrib · GitHub
ãã©ã°ã¤ã³ã«"contrib"ã¨æ¸ããã¦ãããã®ã¯ãå
¬å¼ã®ãã®ãããã
Gruntã®å®è¡ã«ã¯ãGruntfile.jsã¨ãããã¡ã¤ã«ãå¿
è¦ã«ãªãã
Gruntfile.jsã®æ¸ãæ¹ããã¥ã¡ã³ãã¯ä»¥ä¸ãä»ã¯å
¨ç¶ããããªãããã©ãä»å¾ã®ããã«ããã¨ãã
Configuring tasks - Grunt: The JavaScript Task Runner
ä½ãããªãGruntfile.jsãä½æãã¦ãããã¸ã§ã¯ãã®ä¸çªä¸ã®ãã£ã¬ã¯ããªã«ä¿åãã
module.exports = function(grunt){ //è¨å® grunt.initConfig({}); //å®è¡æã®ãã¼ã¯ã¼ã grunt.registerTask("default", []); }
grunt-contrib-lessãã¤ãã£ã¦Lessãã¡ã¤ã«ãã³ã³ãã¤ã«ãã
ã¾ãlessãã¡ã¤ã«ãã³ã³ãã¤ã«ããããã«ãgrunt-contrib-lessããããã
$ npm install grunt-contrib-less
Gruntfile.jsãå¤æ´ããã
module.exports = function(grunt){ // grunt-contrib-lessãã©ã°ã¤ã³ãèªã¿è¾¼ã grunt.loadNpmTasks("grunt-contrib-less"); // è¨å® grunt.initConfig({ less: { //éçºçã®ã¨ã development: { files: { "./css/sample.css": "./less/default.less" } }, //製åçã®ã¨ã production: { options: { cleancss: true }, files: { "./css/sample.css": "./less/default.less" } } } }); //å¼æ°ããªã«ãã¤ããªãã§gruntãå®è¡ããã¨ãã¯ãdevelopmentã®ã¨ãã®è¨å®ã§å®è¡ãã grunt.registerTask("default", ["less:development"]); }
$ cd sandbox $ grunt Running "less:development" (less) task File ./css/sample.css created. Done, without errors.
ã³ã³ãã¤ã«ã§ããï¼
productionã§ã³ã³ãã¤ã«ãããã¨ãã¯
$ grunt less:production
Running "less:production" (less) task
File ./css/sample.css created.
Done, without errors.
developmentã¨ãproductionã¨ãå ´ååãããªããã¦ã¿ããã¨æã£ãããå®è¡ã§ãããã©cssãã¡ã¤ã«ãçæããã¦ããªãããªãã§ã ãã
// 以ä¸ã®ã³ã¼ãã ã¨cssãåºåãããªã... module.exports = function(grunt){ grunt.loadNpmTasks("grunt-contrib-less"); grunt.initConfig({ less: { options: { cleancss: true }, files: { "./css/sample.css": "./less/default.less" } } } }); grunt.registerTask("default", []); }
$ grunt
Done, without errors.
# cssãã¡ã¤ã«ãä½æãããªã
grunt-contrib-watchãã¤ãã£ã¦ãã¡ã¤ã«ã®ç£è¦ããã
grunt-contrib-lessããããã
$ npm install grunt-contrib-watch
Gruntfile.jsãå¤æ´ããã
module.exports = function(grunt){ // ãã©ã°ã¤ã³èªã¿è¾¼ã¿ grunt.loadNpmTasks("grunt-contrib-less"); grunt.loadNpmTasks("grunt-contrib-watch"); // è¨å® grunt.initConfig({ less: { //éçºçã®ã¨ã development: { files: { "./css/sample.css": "./less/default.less" } }, //製åçã®ã¨ã production: { options: { cleancss: true }, files: { "./css/sample.css": "./less/default.less" } } }, watch: { //ç£è¦å¯¾è±¡ã¨ãããã¡ã¤ã« files: "./less/default.less", //å¤æ´ããã£ããlessã³ã³ãã¤ã«ã®éçºçãå®è¡ãã tasks: ['less:development'] }, }); //å¼æ°ããªã«ãã¤ããªãã§gruntãå®è¡ããã¨ãã¯ãwatchãå®è¡ãã grunt.registerTask("default", ["watch"]); }
gruntå®è¡
$ grunt Running "watch" task Waiting...[1] 1435 bus error grunt
ãµãã£ã
調ã¹ãããOS 10.9ã§ã®ã¨ã©ã¼ã¿ãã....ãMavericksã«ãã¦ãããããã¨ããã¾ãªããã ãã©ã
https://github.com/gruntjs/grunt-contrib-watch/issues/228
node.jsã®0.10.21ã§bugfixããã¦ããã¿ãããªã®ã§ãnode.jsã®ã¢ãããã¼ããããã
$ brew update node $ node -v v0.10.21 $ grunt Running "watch" task Waiting...OK >> File "less/default.less" changed. Running "less:development" (less) task File ./css/sample.css created. Done, without errors. Completed in 0.424s at Thu Oct 31 2013 19:13:44 GMT+0900 (JST) - Waiting...
ã§ããã¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
control + c ã§watchãæ¢ããã
éç¨
æ®æ®µã¯watchãã¦ã³ã³ãã¤ã«ããã¦ãæçµçã®ã¨ãã«less:productionã§ã³ã³ãã¤ã«ãã¦ã³ãããããã
package.jsonã«ã¤ãã¦ãæ¸ããã¨æã£ããã©ãä»æ¥ã¯ããã§åå°½ããã
æ¨æ¥ããé·ãã£ã....ã
- ä½è : ä¸å·å樹,å±±å æ²ç,èå´å¥æ²»,åèç¥ä¸,ä»äºé太,å «æ¨æ©å¾¹å¹³,å®å·å¥å¤ª,è¿è¤å®æºæ,奥éå¹¹ä¹,天éç¥ä»,è³æã«ã¤,ä¼è¤ç´ä¹,ä½å·è£å²³,åå·è²´ä¹ ,è åä¸å¿,å¾è¤ç§å®£,ä¹ æ£®éé,ç»å°¾å¾³èª ,渡éæµå¤ª,ä¸å³¶è¡,A-Listers,å°ä¿£è£ä¸,ã¯ã¾ã¡ã2,å·æ·»è²´ç,ç³æ¬å å¸,èéç¥ä¸,æ²ç°é¦å¤«,澤ææ£æ¨¹,åé¨æå¹³,åè¤åè¨,çå±±æé,å¹³å±±æ¯ ,WEB+DB PRESSç·¨éé¨
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/10/24
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (2件) ãè¦ã
ãã¨ã¯ãã¯ãããã®ç¤¾å ã®æ å ±å ±æãçºä¿¡ã®è¨äºãèå³æ·±ãã£ãã