A Grunt tasks for the Cordova/PhoneGap GapReload plugin.
- Install the Grunt CLI:
$ npm install -g grunt-cli
(you may need to usesudo
). - Install the Apache Cordova 3 CLI:
$ npm install -g cordova
(you may need to usesudo
). cd
into your project's root directory.- Create a package.json (for example using
$ npm init
). - Execute
$ npm install grunt-gapreload --save-dev
. - Create a Cordova project:
$ cordova create <path> <id> <name>
. - Add the platforms you need :
$ cd <path> && cordova platforms add <platforms>
.
grunt-gapreload comes with a bunch of useful gapreload- prefixed tasks. Execute $ grunt --help
to know more about them.
Then the only thing you really need to do is to create a file named Gruntfile.js (alongside your package.json) whose content will be something like this:
module.exports = function (grunt) {
grunt.initConfig({
watch: {
gapreload: {
files: [
'cordova/merges/**/*',
'cordova/www/**/*'
],
tasks: 'gapreload-prepare',
options: { livereload: true }
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-gapreload');
};
You can configure the task by adding some options to your grunt.initConfig
call like so (default values):
gapreload: {
options: {
// "cordova working directory", where the Cordova project is located
cwd: 'cordova',
// some platforms names to delegate to the Cordova `prepare` command
// can be an array of names or a string containing a single name
// a falsy value mean (or an empty array) means all installed
platforms: undefined,
// see the GapReload Cordova/PhoneGap plugin documentation
// for more informations about the variables below
SERVER_HOST: undefined,
SERVER_PORT: 8000,
LIVERELOAD_HOST: undefined,
LIVERELOAD_PORT: 35729
}
}
Some grunt-gapreload exposed tasks accept parameters:
Task | Parameters | Default value |
---|---|---|
gapreload-add | [:<GapReload variable>]* | See above, same order |
gapreload-serve | [:<SERVER_PORT>] | 8000 |
gapreload-prepare | [:<platform name>]* | undefined, all installed |
gapreload | [:<GapReload variable>]* | See above, same order |
For example: $ grunt gapreload-add:192.168.0.10:8888 gapreload-prepare:ios:android
.
Parameters are accessed in the following order: Per task > gapreload.options[name]
> default value. The only exeption to this rule is the LIVERELOAD_PORT
variable which can also get its value from watch.gapreload.options.livereload
(see the grunt-contrib-watch documentation for more informations).
cd
into your Cordova app folder previously created using thecordova create
command.- Execute for example
$ grunt gapreload-add:192.168.0.10
once so that the plugin is installed. - Follow GapReload usage instructions in your terminal window and you will be good to go.
- Installing grunt-gapreload will also install grunt, grunt-contrib-watch, grunt-concurrent and grunt-exec as peerDependencies.
- The watch target for grunt-gapreload have to be named gapreload.
- The grunt-gapreload task have to be loaded after calling
grunt.initConfig
.