0

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

这是我的 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
4

1 回答 1

0

我通过使用解决了这个问题

“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')
        });
});
于 2015-07-29T15:52:01.333 回答