A Grunt tasks for the Cordova/PhoneGap GapReload plugin.
$ npm install -g grunt-cli
(you may need to use sudo
).$ npm install -g cordova
(you may need to use sudo
).cd
into your project's root directory.$ npm init
).$ npm install grunt-gapreload --save-dev
.$ cordova create <path> <id> <name>
.$ 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 | [:\ |
See above, same order |
gapreload-serve | [:\ |
8000 |
gapreload-prepare | [:\ |
undefined, all installed |
gapreload | [:\ |
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 the cordova create
command.$ grunt gapreload-add:192.168.0.10
once so that the plugin is installed.grunt.initConfig
.