You should already have NodeJS installed. To install Gulp:
- Open command prompt
On Windows, run the command:
$ npm install gulp -g
On OSx, run the command:
$ sudo npm install gulp -g
To add the gulp-inject module to the package.json file as a development dependency you need to install gulp-inject with the –save-dev argument. From your Ionic project directory run the command:
$ npm install gulp-inject --save-dev
Adding Inject Task to gulpfile.js
- Open the gulpfile.js
Add gulp-inject as a required module. Name the variable used inject.
var inject = require('gulp-inject');
Next we need to add a new gulp task called index (could be called anything).
Next add the index task to the gulp default task
gulp.task('default', ['sass', 'index']);
Setting up index.html to Accept Inject
- Open up the index.html file
In the head tag, replace all of the script tags for your controllers and services with the inject:js comment below. Make sure to leaveLeave the app.js script tag.
<!-- inject:js --> <!-- endinject -->
Replace the css tag for the style.css with the inject:css command below
<!-- inject:css --> <!-- endinject -->
Manually Running It
Running it with Ionic serve
Open the ionic.project file and add the gulp index task to the gulpStartUpTasks. If you don’t have a gulpStartupTasks section, go ahead and add it without the sass task.
"gulpStartupTasks": [ "index", "watch", "sass" ],
Section 12.5: Further Reading
There is a lot of different options for the gulp-inject package. If you want to read about all of the different options and see examples, the documentation is available at https://www.npmjs.com/package/gulp-inject