Currently doing front-end development of the students may be familiar with Grunt,fis such as the automation of building tools, in fact, in HYBRIDAPP development we can also use these tools to simplify our work, Gulp is a more advanced than Grunt,fis building tools, With good gulp, we can simplify our work flow and improve the quality of our products. This article will explain in detail the experience of using our mobile app Project Gulp, and some of the gulp introductions are from foreign websites.
Gulp is a new Nodejs-based build system released by fractal, with the goal of replacing Grunt as the most popular JavaScript task runner. Currently, the default build tool for the Ionic framework is gulp,ionic using the Gulp-sass plugin to compile the CSS.
According to Gulp's documentation, the main features it strives to implement are:
- Easy to use: With code better than configuration strategies, Gulp keeps simple things simple and complex tasks manageable.
- efficient: by leveraging node. JS's powerful stream, you don't need to write intermediate files to disk, Builds can be completed faster.
- high quality: Gulp Strict plug-in guidelines, Make sure the plug-in is simple and works the way you want.
- easy to learn: by minimizing the API, You can learn to gulp in a short period of time. The build work is the same as you would imagine: a series of flow pipelines.
Gulp simplifies task writing by streaming and code better than configuration policies. This looks like a "jquery" approach, which strings together to create a build task. In the early days of UNIX, the flow already existed. Streams also play an important role in the node. JS ecosystem, so writing tasks with Gulp can also be seen as writing tasks with node. js. When using a stream, Gulp removes the intermediate file and writes only the last output to the disk, so the process becomes faster. Gulp uses code that is better than configured policies to keep simple things simple and to make complex tasks manageable.
As with other task runtimes, each task can be a simple unit of work, and the following code is the Ionic framework's own compiled SCSS for CSS:
Gulp.task (' sass ', function (done) {gulp.src ('./scss/ionic.app.scss '). Pipe (Sass ()). Pipe (Gulp.dest ('./www/css/')). Pipe (Minifycss ({keepspecialcomments:0})). Pipe (Rename ({extname: '. Min.css '}). Pipe (Gulp.dest ('./www/css/')). On (' End ', done);}); Gulp.task (' Watch ', function () {Gulp.watch (paths.sass, [' sass ']);});
With regard to grunt, complaints about it are too lengthy, and include a lot of plugins doing the jobs they shouldn't. Mark Goodyear cited an example in a blog post that grunt's Imagemin plugin not only compresses images, but also includes caching capabilities. In gulp, he says, the cache is another plug-in that can be used by other plugins, which facilitates the reusability of plugins.
Looking at the code base activities of gulp and the number of people you are interested in, you can see that the build system is starting to gain momentum. It also attracted interest from the JavaScript community: Yeoman's chief developer, Addy Osmani, submitted a issue to introduce Gulp to team members and evaluate their replacement of the current build system. Sindre Sorhus, a member of the Yeoman Research and development team and a major contributor to NPM, wrote a blog about Gulp and mentioned gulp on Twitter: "Faster than Grunt and less configured".
Our project uses Gulp script to pre-release the app before the work, including CSS compression, ANGULARJS pre-compression preprocessing, JS remove log,js compression, do not need to package the file deletion, file content replacement, etc., with the plug-in mainly Gulp-util,bower, Gulp-concat,gulp-sass,gulp-minify-css,gulp-raname,shelljs,gulp-ngmin,gulp-uglify,gulp-rimraf,gulp-replace and so on.
As long as you run Ionic build iOS in the project directory before the project is released, gulp Publish is ready and then packaged and released in Xcode.
To Xcode, run Project---Archive, in the pop-up Organizer window, select the newly generated Archive, click Distribute, check the second release of the enterprise distribution version, (then you can choose to fill in some information to generate the Plist file, No, this file is a text file that you can edit directly.
The code attached to the Gulp project configuration file Gulpfile.js
var gulp = require (' gulp '), var gutil = require (' Gulp-util '), var bower = require (' bower '); var concat = require (' Gulp-concat var sass = require (' Gulp-sass '), var minifycss = require (' gulp-minify-css '); var rename = require (' gulp-rename '); var sh = Require (' Shelljs '); var paths = {sass: ['./scss/**/*.scss ']};gulp.task (' Default ', [' sass ']); Gulp.task (' sass '); function (done) {gulp.src ('./scss/ionic.app.scss '). Pipe (Sass ()). Pipe (Gulp.dest ('./www/css/')). Pipe (Minifycss ({ keepspecialcomments:0}). Pipe (Rename ({extname: '. Min.css ')). Pipe (Gulp.dest ('./www/css/')). On (' End ', done);}); Gulp.task (' Watch ', function () {Gulp.watch (paths.sass, [' sass ']);}); Gulp.task (' Install ', [' git-check '], function () {return Bower.commands.install (). On (' Log ', function (data) {Gutil.log ( ' Bower ', Gutil.colors.cyan (data.id), data.message);}); Gulp.task (' Git-check ', function (done) {if (!sh.which (' Git ')}) {Console.log (' + gutil.colors.red (' Git is not installed. ') , ' \ n Git, the version control system, is required to download IOnic ', ' \ n Download git here: ', Gutil.colors.cyan (' http://git-scm.com/downloads ') + '. ', ' \ n Once git is installed, run \ ' + Gutil.colors.cyan (' Gulp install ') + ' \ ' again. '); Process.exit (1);} Done ();}); /prvar ngmin = require (' gulp-ngmin '); Gulp.task (' Ngmin ', function () {return gulp.src ('./www/js/*.js '). Pipe (Ngmin ({ Dynamic:false}). Pipe (Gulp.dest (' dist ');}); var stripdebug = require (' Gulp-strip-debug '), var uglify = require (' gulp-uglify '); Gulp.task (' Compress ', function () { Gulp.src ('./www/js/**/*.js '). Pipe (Stripdebug ()). Pipe (Uglify ({outsourcemap:false})). Pipe (Gulp.dest ('./platforms /ios/www/js/')}); var Rimraf = require (' Rimraf '); Rimraf directlygulp.task (' delete ', function (CB) {Rimraf ('./platforms/ios/www/mock ', CB); Rimraf ('./platforms/ios/ Www/templates/statics ', CB);//Rimraf ('./platforms/ios/www/lib ', CB);//Rimraf ('./platforms/ios/www/lib/ionic/js/ Ionic.bundle.js ', CB);}); var Grimraf = require (' Gulp-rimraf '); Gulp.task (' Del ', function () {gulp.src ('./platforms/ios/www/mock '), {read: false})//much faster//. Pipe (Ignore (' node_modules/** ')). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/templates /statics ', {read:false})//Much faster.pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/res ', {read:false}). Pipe (Grim RAF ()); Gulp.src ('./platforms/ios/www/css/ionic.app.css ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ Ios/www/lib/angular ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/angular-animate ', {read: False}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/angular-sanitize ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/angular-ui-router ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/ Www/lib/angular-ui-router ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic/scss ', {read: False}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic/css ', {read:false}). Pipe (Grimraf ()); Gulp.src ('. /platforms/ios/www/lib/ionic/js/ionic-angular.js ', {read:false}). Pipe (Grimraf (); Gulp.src ('./platforms/ios/www/lib/ionic/js/ionic-angular.min.js ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./ Platforms/ios/www/lib/ionic/js/ionic.js ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic /js/ionic.min.js ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic/js/ionic.bundle.js ', { Read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic/css ', {read:false}). Pipe (Grimraf ()); Gulp.src ('./platforms/ios/www/lib/ionic/readme.md ', {read:false}). Pipe (Grimraf ());}); var replace = require (' Gulp-replace '); Gulp.task (' Rep ', function () {gulp.src ('./www/index.html '). Pipe (replace (" Ionic.bundle.js "," Ionic.bundle.min.js ")). Pipe (replace (" Ionic.app.css "," Ionic.app.min.css ")). Pipe (Gulp.dest ('./ platforms/ios/www/');}); Gulp.task (' Publish ', [' sass ', ' compress ', ' del ', ' rep ']);