gulp js concat issue


/*global -$ */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var csso = require('gulp-csso');
var argv = require('yargs').argv;
var gulpif = require('gulp-if');
var inquirer = require('inquirer');
var minifyHTML = require('gulp-minify-html');
var browserSync = require('browser-sync');
var del = require('del');
var reload = browserSync.reload;
// variables
var production = !!(argv.production);  
var dev = !!(argv.dev);  
var move = !!(argv.move); 
var app = 'app';
var dist = 'dist';
var src = {
  scss : app+'/style.scss',  
  scripts:{
  modernizr:'bower_components/modernizr/modernizr.js',
  vendor:['bower_components/jquery/dist/jquery.js',
  'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js',
  ],
  main:app+'/scripts/main.js'
  }
};
// Vendor js
gulp.task('vendorScripts', function(){
  return gulp.src(src.scripts.vendor)
    .pipe(concat('vendor.js'))    
    .pipe(gulpif(dev,gulp.dest(app+'/js/vendor/')))
    .pipe(gulpif(production,gulp.dest(app+'/js/vendor/')))
    .pipe(rename('vendor.min.js'))
    .pipe(uglify())
    .pipe(gulpif(dev,gulp.dest(app+'/js/vendor/')))
    .pipe(gulpif(production,gulp.dest(dist+'/js/vendor/')));
});

当我运行gulp vendorScripts—production时只编译vendor.min.js但是当我运行gulp vendorScripts -dev编译vendor.js和vendor.min.js

我想在dist文件夹中编译两个文件。发生了什么问题?

看起来你想写dist用于生产,但是你写了app。将第二行改为使用dist而不是app。

.pipe(gulpif(dev,gulp.dest(app+'/js/vendor/')))
.pipe(gulpif(production,gulp.dest(app+'/js/vendor/')))

下面是正确的

.pipe(gulpif(dev,gulp.dest(app+'/js/vendor/')))
.pipe(gulpif(production,gulp.dest(dist+'/js/vendor/')));

只是一个建议:而不是使用gulp-if,应用js的if-else逻辑来获得输出的目录名,并在任务中使用它…

相关内容

  • 没有找到相关文章

最新更新