Yeomanã®generator-angularã¨Railsã®çµã¿åããã§ã®éçºç°å¢æ§ç¯
grunt-connect-proxyã使ã£ã¦ãrails server ã¨ãgrunt serve ã®2ã¤ãå©ãã¦LiveReloadã§éçºåºæ¥ãããã«ãããã¨ãã話ã
ãã¨ããã³ãå´ããã«ãããã¨Railsã®publicãã£ã¬ã¯ããªã«éçãã¡ã¤ã«ã¨ãã¦é
åããããã«ã
Railsã®Asset Pipelineã«AngularJSãè¼ããããããªãã¦ããµã¼ãã¼ãµã¤ã(Rails)ã¨ã¯ã©ã¤ã¢ã³ããµã¤ã(AngularJS)ãåé¢ãã¦ã®éçºã®è©±ã
ããããäºâ
理想的な Rails, AngularJS 環境の構築 - ボクココ
åæ
Railsã¢ããªä½æãã¦ãapiã®namespaceã§APIãä½ææ¸ã¿ãRailsã¢ããªã®ã«ã¼ãã«ngappã¨ããã£ã¬ã¯ããªä½ã£ã¦ãyo angular --coffee ã§ããã³ãã¨ã³ãé¨ãçææ¸ã¿ã¨ããã*1
ä½æ¥
% cd ngapp
% npm install -D grunt-connect-proxy
# Gruntfile.coffee "use strict" proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest # â追å module.exports = (grunt) -> require("load-grunt-tasks")(grunt) require("time-grunt")(grunt) # Configurable paths for the application appConfig = app: require("./bower.json").appPath or "app" dist: "../public" # âä¿®æ£. railsã®publicãdistã« # Define the configuration for all the tasks grunt.initConfig # Project settings yeoman: appConfig # ................................çç¥................................. connect: options: port: 9000 # Change this to '0.0.0.0' to access the server from outside. hostname: "localhost" livereload: 35729 livereload: options: open: true middleware: (connect) -> [ proxySnippet #<- 追å connect.static(".tmp") connect().use("/bower_components", connect.static("./bower_components")) connect.static(appConfig.app) ] proxies: [ #<- proxies: [...] 追å context: '/api' host: 'localhost' port: '3000' ] # ................................çç¥................................. grunt.registerTask "serve", "Compile then start a connect web server", (target) -> if target is "dist" return grunt.task.run([ "build" "connect:dist:keepalive" ]) grunt.task.run [ "clean:server" "wiredep" "concurrent:server" "configureProxies" #<- 追å "autoprefixer" "connect:livereload" "watch" ] # ................................çç¥.................................
% bundle exec rails server
% grunt serve
ããã§ãlocalhost:9000/ã«ã¢ã¯ã»ã¹ããã¨ããã³ãå´ãlocalhost:9000/apiãRailsã®APIå´ã«*2ã
APIã¨ã¯å¥ã«ã管çç³»ã¨ããæ®éã«Railsã¢ããªã¨ãã¦ä½ã£ã¦åãããã¸ã§ã¯ãä¸ã«ããå ´åã¯ãRailsã®ãä½æ³ã«åããlocalhost:3000/ä¸ã«ã¢ã¯ã»ã¹ã§ããã¨æãã
ãã«ãã¯,--forceãå¿ããã«
grunt build --force
2014/8/23追è¨
Vagrantã®å ´åâ Yeomanのgenerator-angularで作ったプロジェクトをVagrant環境で開発する場合の設定 - 仙台 Ruby Vim JavaScript 社長