grunt-wiredep使用の環境でangular-i18nをbowerでインストールしたら注入できないとメッセージ
AngularJSリファレンス購入して読了。これは良い本。
で、フィルタのi18nの項をみて、早速いれてみたら、grunt-wiredepを使っているGruntのタスクで注入出来ないとメッセージが出て、htmlファイルのコメントの間にi18nへのscriptタグが挿入されない。
ちなみにgenerator-angularで作ったプロジェクトで、bowerでi18nを入れての話。
% bower install angular-i18n --save % grunt serve # .......略............... Running "wiredep:app" (wiredep) task app/index.html modified. angular-i18n was not injected in your file. Please go take a look in "/home/vagrant/myApp/client/bower_components/angular-i18n" for the file you need, then manually include it in your file. Running "wiredep:sass" (wiredep) task angular-i18n was not injected in your file. Please go take a look in "/home/vagrant/myApp/client/bower_components/angular-i18n" for the file you need, then manually include it in your file.
index.html
<!-- bower:js --> <!-- 略 --> <script src="bower_components/angular-i18n/angular-locale_ja-jp.js"></script> <!-- ↑これが入って欲しいが入らない --> <!-- endbower -->
angular-i18nのbower.jsonを確認するとmainが指定されていない。 まあ色々な言語のパッケージが入ってるし、勝手にロケールを解決してくれるとも思えないので、そりゃそうか。 なので、bower.jsonにこうした。
//bower.json "overrides": { "angular-i18n": { "main": "angular-locale_ja-jp.js" } }
これでgrunt serveなりwiredepのタスクが含まれたタスクを実行すると…OK.注入された。
index.html
<!-- bower:js --> <!-- 略 --> <script src="bower_components/angular-i18n/angular-locale_ja-jp.js"></script> <!-- endbower -->
Vagrant環境下でのgrunt watchでファイル監視の反映に時間がかかるので、webstormの自動保存を無効にした
↓ こちらのとおりです。
WebStorm/PhpStorm メモ - 自動保存を停止したい - {u:b}
うーん、あまり変わらない気がする。別のところに原因がありそう。
Vagrant環境でload-grunt-taskを使ったGruntのtaskが遅いのでjit-gruntに変えた
インストール
% npm install jit-grunt -D % npm uninstall load-grunt-tasks -D
jit-gruntを使うようにGruntfile.coffeeを書き換え。
後、watchにspawn: falseも追加しといた。
#Gruntfile.coffee module.exports = (grunt) -> # Load grunt tasks automatically - require("load-grunt-tasks")(grunt) + require('jit-grunt')(grunt) + grunt.loadNpmTasks('grunt-connect-proxy') + grunt.loadNpmTasks('grunt-protractor-runner') + grunt.loadNpmTasks('grunt-google-cdn') + grunt.loadNpmTasks('grunt-usemin') # Time how long tasks take. Can help when optimizing build times require("time-grunt")(grunt) # ----------------省略------------------ # Watches files for changes and runs tasks based on the changed files watch: + options: + spawn: false
# package.json "grunt-wiredep": "^1.7.0", + "jit-grunt": "^0.8.0", "jshint-stylish": "^0.2.0", # ----------------省略------------------ "karma-spec-reporter": "0.0.13", - "load-grunt-tasks": "^0.4.0", "protractor": "^1.0.0",
jit-gruntは load-grunt-tasksだと読み込んでくれてたものを読み込んでくれないパッケージがある*1ので、読み込んでくれないパッケージは明示的にloadNpmTasksする。 どれが読み込まれないのかよくわからなかったら、差し替えてtaskを実行してみれば見つからないと表示してくれるので、それを読みこめばOK.
jit-grunt: Plugin for the "useminPrepare" task not found. If you have installed the plugin already, please setting the static mapping. See https://github.com/shootaroo/jit-grunt#static-mappings
早くなりました。
参考
*1:読み込み規則がちがう
deprecatedが出ていたngminからng-annotateへ切り替え
AngularJSのminify対策をしてくれるアレ。
例によって、generator-angularで作ったプロジェクトでの話。
grunt-ng-annotateをインストールしてgrunt-ngminを外して、記述をngminからngAnnotateにしただけでいけました。
% npm install grunt-ng-annotate -D
diff --git a/package.json b/package.json index 77190a9..e1f2b1a 100644 --- a/ngapp/package.json +++ b/ngapp/package.json @@ -25,7 +25,7 @@ "grunt-google-cdn": "^0.4.0", "grunt-karma": "^0.8.3", "grunt-newer": "^0.7.0", - "grunt-ngmin": "^0.0.3", + "grunt-ng-annotate": "^0.3.2", "grunt-protractor-runner": "^1.1.0", "grunt-svgmin": "^0.4.0", "grunt-usemin": "^2.1.1",
-- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -300,10 +300,7 @@ module.exports = (grunt) -> dest: "<%= yeoman.dist %>" ] - # ngmin tries to make the code safe for minification automatically by - # using the Angular long form for dependency injection. It doesn't work on - # things like resolve or inject so those have to be done manually. - ngmin: + ngAnnotate: dist: files: [ expand: true @@ -443,7 +440,7 @@ module.exports = (grunt) -> "concurrent:dist" "autoprefixer" "concat" - "ngmin" + "ngAnnotate" "copy:dist" "cdnify" "cssmin"
CoffeeScriptでAngularJSのテスト書いている時に暗黙的に最後の行を returnする仕様に気をつける
まんまこれ↓
CoffeeScript で AngularJS のテストを書くときに気をつけること - Qiita
'use strict' describe 'Service: AwesomeInterceptor', -> httpProvider = {} # load the service's module beforeEach module 'myApp',($httpProvider)-> httpProvider= $httpProvider return # <- つけた #.........
Karma-Jasmineの出力結果表示形式をRspec風にしたい
そっけないです.....
karma-spec-reporterをインストールして設定する。
% npm install karma-spec-reporter -D
# karma.conf.coffee plugins: [ 'karma-phantomjs-launcher' 'karma-jasmine' 'karma-coffee-preprocessor' + 'karma-spec-reporter' 'karma-coverage' ] - reporters: ['progress','coverage'] + reporters: ['spec','coverage']
OK.