Gulp运行的同步任务不能正常运行(在设置AngularJs环境时)



我正在学习Gulp。我想用Gulpand设置AngularJS环境然后缩小并连接它们。但问题是,当我试图缩小或连接js文件,然后我认为gulp没有找到configFile.js是由"gulp-ng-config"创建的设置AngularJS环境

这是我的gulpfile.js

var gulp = require('gulp');
var bower = require('gulp-bower');
var gulpNgConfig=require('gulp-ng-config');
var rimraf = require('rimraf');
var gp_concat = require('gulp-concat');
var gp_rename = require('gulp-rename');
var gp_uglify = require('gulp-uglify');
require('gulp-run-seq');

gulp.task('setLocalEnv', function () {
    console.log("gulp test running ");
    gulp.src('configFile.json')
        .pipe(gulpNgConfig('myApp.config', {
            environment: 'local'
        }))
        .pipe(gulp.dest('./js'),function(end){
            console.log("set env",end);
        })
});
gulp.task('js-fef', function(){
    return gulp.src(['js/*','js/*/*'])
        .pipe(gp_concat('concat.js'))
        .pipe(gulp.dest('dist'))
        .pipe(gp_rename('uglify.js'))
        .pipe(gp_uglify())
        .pipe(gulp.dest('dist'));
});
gulp.task('clean', function (cb) {
    rimraf('./dist', cb);
});
gulp.task('bower', function() {
    return bower()
});
gulp.task('setProdEnv', function () {
    console.log("gulp test running ");
    gulp.src('configFile.json')
        .pipe(gulpNgConfig('myApp.config', {
            environment: 'production'
        }))
        .pipe(gulp.dest('./js'))
});
gulp.task('default', [['clean','setLocalEnv','bower','js-fef']],function() {
    console.log("hello gulp");
});
gulp.task('production',['setProdEnv','bower'], function() {
    console.log("hello gulp");
});

这是由"setLocalEnv"任务创建的configFile.js

angular.module('myApp.config', [])
.constant('EnvironmentConfig', {"api":"http://localhost/"});

这是生成的最小化文件

angular.module("app",[]),angular.module("app").controller("ctrl",["$scope",function(l){console.log("ctrl bind ")}]);

下面是gulp默认命令

的输出
[20:09:56] Using gulpfile ~/WebstormProjects/NodeJs-Seed/public/gulpfile.js
[20:09:56] Starting 'clean'...
[20:09:56] Finished 'clean' after 2.46 ms
[20:09:56] Starting 'setLocalEnv'...
gulp test running 
[20:09:56] Finished 'setLocalEnv' after 20 ms
[20:09:56] Starting 'bower'...
[20:09:56] Using cwd:  /home/abhay/WebstormProjects/NodeJs-Seed/public
[20:09:56] Using bower dir:  lib
[20:09:56] Finished 'bower' after 3.85 ms
[20:09:56] Starting 'js-fef'...
[20:09:56] Finished 'js-fef' after 10 ms
[20:09:56] Starting 'default'...
hello gulp

我使用

来解决这个问题

" gulp.run("js-fef")"

现在我的gulp任务看起来像
gulp.task('setLocalEnv', function () {
    console.log("gulp test running ");
    gulp.src('configFile.json')
        .pipe(gulpNgConfig('myApp.config', {
            environment: 'local'
        }))
        .pipe(gulp.dest('./js'),function(end){
            console.log("set env",end);
        })
        .on('end', function () {
            gulp.run('js-fef')
        });
});

相关内容

  • 没有找到相关文章

最新更新