Right now when I use ionic serve
it runs the gulp startup tasks in my ionic.project. Are there gulp tasks run on ionic build? I’d love to run a task to replace base urls for my api calls when I build but I don’t see a way to do that. I know I can just call gulp [whatever]
then call ionic build
but I’d prefer it would be automated.
you have to use cordova hooks to run some code on build
Hi,
I had to do exactly what you’re asking for, and after a little research, I came out with something that works:
- create a hook file inside /hooks/appropriate_phase/xy_hook_name.js
where:
- appropriate_phase must be one taken from the following list: https://cordova.apache.org/docs/en/edge/guide_appdev_hooks_index.md.html
- xy_hook_name.js is the hook file name. xy should be numbers. This is just a convention for executing hooks in a specific order. However, since node.js code is asynchronous, you’ll have to handle it if you need sequential/synchronous code execution.
-
use the following code inside the hook file you did create in step 1:
#!/usr/bin/env node
var gulp = require(‘gulp’);
var path = require(‘path’);var rootdir = process.argv[2];
var gulpfile = path.join(rootdir, ‘gulpfile.js’);process.stdout.write(’[MyHook] executing MyHook\n’);
require(gulpfile);
// execute specific gulp task
gulp.start(‘gulp-task-name’);
source: https://stackoverflow.com/questions/28308360/gulp-hook-before-cordova-build-xxx/28461521#28461521
Be Aware that the gulp.start('gulp-task-name')
method appears to be doomed to deprecation/removal. This is not a stable/long term solution. But it does work as today (17th of September 2015) with the following system information:
Cordova CLI: 5.2.0
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.0
Ionic CLI Version: 1.6.4
Ionic App Lib Version: 0.3.8
Hope that helps! Good Luck!