简体   繁体   English

科尔多瓦/ Gulp最佳做法

[英]Cordova / Gulp best practice

I'm trying to setup a Cordova develop/deployment chain using Gulp. 我正在尝试使用Gulp建立Cordova开发/部署链。 I ended with this gulpfile.js, but I'm not really satisfied since I need to kill "gulp watch" task in order to run "gulp deploy" task. 我以gulpfile.js结尾,但是我并不满意,因为我需要杀死“ gulp watch”任务才能运行“ gulp deploy”任务。

var gulp = require('gulp'),
gutil = require('gulp-util'),
exec = require('gulp-exec');
var spawn = require('child_process').spawn;
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');

/**
* Config ogj
*/
var config = {
    jsDir: 'www/assets/js',
    jsDirBrowser: 'platforms/browser/www/assets/js',
    production: !!gutil.env.production
};

/**
* Automatically run 'cordova prepare browser' after any modification 
* into the www directory - really useful for development/deplyment purpose
* 
* @see watch task
*/
gulp.task('prepare', function () {
    gutil.log('Prepare browser');
    var options = {
        continueOnError: false, // default = false, true means don't emit error event 
        pipeStdout: false, // default = false, true means stdout is written to file.contents 
        customTemplatingThing: "test" // content passed to gutil.template() 
    };
    var reportOptions = {
        err: true, // default = true, false means don't write err 
        stderr: true, // default = true, false means don't write stderr 
        stdout: true // default = true, false means don't write stdout 
    }
    return gulp.src('./**/**')
    .pipe(exec('cordova prepare browser', options))
    .pipe(exec.reporter(reportOptions));

});

/**
* Watch for changes in www
*/
gulp.task('watch', function () {
    gulp.watch('www/**/*', ['prepare']);
});

/**
* Default task
*/
gulp.task('default', ['prepare']);


/**
* Javascript production depolyment.
*/
gulp.task('deploy-js', function () {
    gutil.log('Deploy');
    return gulp.src(config.jsDir + '/*.js')
    .pipe(stripDebug())
    .pipe(uglify())
    .pipe(gulp.dest(config.jsDirBrowser));
});

/**
* Production deployment
* To be run before uploading files to the server with no gulp instaces running
*/
gulp.task('deploy', ['deploy-js']);

Which could be a best practice for develop and deply a Cordova project using Gulp? 哪个是使用Gulp开发和部署Cordova项目的最佳实践?

[EDIT] I think the problem is in the "prepare" task: it never returns, probably due a gulp-exec issue, but I really don't know how to debug it. [编辑]我认为问题出在“准备”任务中:它永远不会返回,可能是由于gulp-exec问题引起的,但是我真的不知道如何调试它。

From what I've understood the only issue is that gulp command does not return control to you for you to execute gulp deploy 据我了解,唯一的问题是gulp命令不会将控制权交gulp deploy您以执行gulp deploy

the prepare task never returns because of the behavior of the watch feature - you've passed control to watch the files so it will return only when you stop watching. 由于watch功能的行为,prepare任务永远不会返回-您已经通过控制来watch文件,因此只有在停止监视时它才会返回。 It is the expected behavior and not a probably due a gulp-exec issue . 这是预期的行为,而不可能probably due a gulp-exec issue

The solution I would adopt in this situation is to run the gulp task in the background, using the native nohup gulp & so that the watching is moved to the background for me to execute deploy . 在这种情况下,我将采用的解决方案是使用本机的nohup gulp &在后台运行gulp任务,以便将watching转移到后台以供我执行deploy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM