Well, you are developing a Cordova-based hybrid app, Gruntjs is a part of your workflow, and you are visualizing the result in your favorite browser through Ripple Emulator. Your source code is in a folder and your build in another.
But you faced a problem: Each time you modify your code source, you must trigger manually the building of your code (via a
cordova prepare) and you have to refresh Ripple tab to visualize the new render.
Let me told you this time is over. How ? By automating the workflow. We will end up with something like this:
First of all, you will need some packages:
- RVM: Install it with
curl -sSL https://get.rvm.io | bash -s stable --ruby
- Ruby: Once you’ve installed RVM, run
rvm listto list the current Ruby environnements installed. Enable the last one with
rvm use <ruby_version>. e.g:
ruby use 2.1.3.
- Rubygems: Install it with
rvm rubygems latest
- Chrome browser (Not tested but should also work with Firefox or Safari)
Let’s continue! There will be 3 steps:
- Install and configure grunt-watch
- Install and configure guard-livereload
- Install and configure livereload Chrome Extension
What is Grunt-watch?
Grunt-watch is a plugin of Grunt which allow to watch modifications on specified files and trigger a task on these events.
- Install it:
npm install grunt-contrib-watch --save-dev
Configure the tasks, by specifying the files to watch.
This tasks will watch continuously changes on files every CSS, JS files and index.html.
Spawn option set to false will speed up tasks execution time but can also make tasks suceptible to failed.
Interrupt option set to true will allow grunt-watch to stop the previous tasks if a new event happen. Which can be the case if you do a lot of
ctrl+slike me :)
Event option will trigger tasks only if a file is added or modified. This way task triggering is limited, and it should not eat all of your CPU and RAM.
- Run Grunt-watch task:
What is Guard-livereload?
Guard-livereload is a plugin of Guard a tool which allow to trigger tasks on file system modifications. This plugin add the ability to communicate with livereload browser extension
- Install it with
gem install guard-livereload
Add this to your Gemfile (maybe you need to create it):
ruby group :development do gem 'guard-livereload', require: false end
- Add guard definition for this plugin to your Guardfile :
guard init livereload
- Configure the tasks into Guardfile:
guard 'livereload' do
Here we just need to watch the entire content of the www folder.
guard start to launch the guard watching process
Livereload Chrome extension
- Install the extension. A new icon should be added next to your address bar. If you use Firefox or Safari, please refer to this page
- Switch to your Ripple emulator tab and click on the livereload icon to enable it.
Finally test your new workflow:
- Open a file watched by Grunt-watch, modify it and save it.
- The Ripple tab should be refreshed in around 3seconds (depending on your Grunt-watch triggered tasks total execution time).