gulpfile.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /******************************************************************************
  2. * Gulpfile
  3. * Be sure to run `npm install` for `gulp` and the following tasks to be
  4. * available from the command line. All tasks are run using `gulp taskName`.
  5. ******************************************************************************/
  6. var gulp = require('gulp');
  7. var path = require('path');
  8. var config = require('./ionic.config');
  9. /******************************************************************************
  10. * gulp watch
  11. * Build the styles, and rebuild when source files change.
  12. ******************************************************************************/
  13. gulp.task('watch', ['sass', 'fonts'], function(done) {
  14. var watch = require('gulp-watch');
  15. var sassFiles = path.join(config.paths.wwwDir, config.paths.appDir, config.paths.appSassWatch);
  16. watch(sassFiles, function(){
  17. gulp.start('sass');
  18. });
  19. });
  20. /******************************************************************************
  21. * gulp build
  22. * Build the styles once, without watching for source file changes.
  23. ******************************************************************************/
  24. gulp.task('build', ['sass', 'fonts']);
  25. /******************************************************************************
  26. * gulp sass
  27. * Convert Sass files to a single bundled CSS file. Uses auto-prefixer
  28. * to automatically add required vendor prefixes when needed.
  29. ******************************************************************************/
  30. gulp.task('sass', function(){
  31. var sass = require('gulp-sass');
  32. var autoprefixer = require('gulp-autoprefixer');
  33. var sassSrcFiles = [];
  34. config.paths.appSassSrc.forEach(function(sassSrc) {
  35. sassSrcFiles.push( path.join(config.paths.wwwDir, config.paths.appDir, sassSrc) );
  36. });
  37. gulp.src(sassSrcFiles)
  38. .pipe(sass({
  39. includePaths: [path.join(config.paths.ionicDir, config.paths.ionicSassDir)],
  40. }))
  41. .on('error', function(err){
  42. console.error(err.message);
  43. this.emit('end');
  44. })
  45. .pipe(autoprefixer(config.autoPrefixerOpts))
  46. .pipe(gulp.dest(
  47. path.join(config.paths.wwwDir, config.paths.buildDir, config.paths.buildCSSDir)
  48. ));
  49. });
  50. /******************************************************************************
  51. * gulp fonts
  52. * Copy Ionic font files to build directory.
  53. ******************************************************************************/
  54. gulp.task('fonts', function() {
  55. return gulp.src(path.join(config.paths.ionicDir, config.paths.ionicFontFiles))
  56. .pipe(gulp.dest(path.join(config.paths.wwwDir, config.paths.buildDir, config.paths.buildFontsDir)));
  57. });
  58. /******************************************************************************
  59. * gulp clean
  60. * Delete previous build files.
  61. ******************************************************************************/
  62. gulp.task('clean', function(done) {
  63. var del = require('del');
  64. del([config.paths.buildDir], done);
  65. });