Gulp:输出到dest文件夹时排除src根文件夹

时间:2015-05-11 04:34:14

标签: javascript configuration config gulp

鉴于以下gulpfile,我希望dist文件夹的内容是src/js/的内容。相反,dist的内容为src/js/*

var del = require('del');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var livereload = require('gulp-livereload');
var notify = require('gulp-notify');
var sourcemaps = require('gulp-sourcemaps');
var transpile  = require('gulp-es6-module-transpiler');

gulp.task('build', function() {
    return gulp.src('src/js/**/*.js')
        .pipe(sourcemaps.init())
        .pipe(transpile({
            formatter: 'bundle'
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('dist'))
        .pipe(notify({ message: 'Build task complete.' })); });

如何从src输出目录中排除dist根目录,结果为dist/js/**/*.js

1 个答案:

答案 0 :(得分:1)

我的猜测是它与相对路径有关(与你从哪里开始吞咽)。尝试将dest更改为相对路径:

gulp.task('build', function() {
return gulp.src('./src/js/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(transpile({
        formatter: 'bundle'
    }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dist/js/'))
    .pipe(notify({ message: 'Build task complete.' })); });