[gulp] gulp.src ()에서 현재 파일 이름을 가져옵니다.

gulp.js 파일에서 examples폴더의 모든 HTML 파일을 폴더로 스트리밍하고 있습니다 build.

꿀꺽 꿀꺽 만드는 작업은 어렵지 않습니다.

var gulp = require('gulp');

gulp.task('examples', function() {
    return gulp.src('./examples/*.html')
        .pipe(gulp.dest('./build'));
});

그러나 작업에서 발견되고 처리 된 파일 이름을 검색하는 방법을 알 수 없거나 올바른 플러그인을 찾을 수 없습니다.



답변

파일 이름을 어떻게 사용하고 싶은지 잘 모르겠지만 다음 중 하나가 도움이 될 것입니다.

  • 이름 만보고 싶다면 gulp-debug비닐 파일의 세부 정보를 나열하는 것과 같은 것을 사용할 수 있습니다 . 목록을 원하는 위치에 다음과 같이 삽입하십시오.

    var gulp = require('gulp'),
        debug = require('gulp-debug');
    
    gulp.task('examples', function() {
        return gulp.src('./examples/*.html')
            .pipe(debug())
            .pipe(gulp.dest('./build'));
    });
  • 다른 옵션은 gulp-filelog내가 사용하지 않았지만 비슷하게 들립니다 (약간 깨끗할 수 있습니다).

  • 또 다른 옵션은 gulp-filesize파일이며 파일 크기를 모두 출력합니다.

  • 더 많은 제어를 원한다면, 같은 gulp-tap기능을 사용하여 자신 만의 기능을 제공하고 파이프의 파일을 볼 수 있습니다.


답변

나는이 플러그인이 내가 기대했던 것을하고 있음을 발견했다 : gulp-using

간단한 사용 예 : 확장자가 .jsx 인 프로젝트의 모든 파일 검색

gulp.task('reactify', function(){
        gulp.src(['../**/*.jsx'])
            .pipe(using({}));
        ....
    });

산출:

[gulp] Using gulpfile /app/build/gulpfile.js
[gulp] Starting 'reactify'...
[gulp] Finished 'reactify' after 2.92 ms
[gulp] Using file /app/staging/web/content/view/logon.jsx
[gulp] Using file /app/staging/web/content/view/components/rauth.jsx


답변

여기 또 다른 간단한 방법이 있습니다.

var es, log, logFile;

es = require('event-stream');

log = require('gulp-util').log;

logFile = function(es) {
  return es.map(function(file, cb) {
    log(file.path);
    return cb();
  });
};

gulp.task("do", function() {
 return gulp.src('./examples/*.html')
   .pipe(logFile(es))
   .pipe(gulp.dest('./build'));
});


답변

gulp-filenames 모듈을 사용하여 경로 배열을 얻을 수 있습니다 . 네임 스페이스별로 그룹화 할 수도 있습니다.

var filenames = require("gulp-filenames");

gulp.src("./src/*.coffee")
    .pipe(filenames("coffeescript"))
    .pipe(gulp.dest("./dist"));

gulp.src("./src/*.js")
  .pipe(filenames("javascript"))
  .pipe(gulp.dest("./dist"));

filenames.get("coffeescript") // ["a.coffee","b.coffee"]  
                              // Do Something With it 


답변

내 경우에는 gulp-ignore 가 완벽했습니다. 옵션으로 함수를 전달할 수 있습니다.

function condition(file) {
 // do whatever with file.path
 // return boolean true if needed to exclude file 
}

그리고 작업은 다음과 같습니다.

var gulpIgnore = require('gulp-ignore');

gulp.task('task', function() {
  gulp.src('./**/*.js')
    .pipe(gulpIgnore.exclude(condition))
    .pipe(gulp.dest('./dist/'));
});


답변

Typescript에서 @OverZealous ‘answer ( https://stackoverflow.com/a/21806974/1019307 )를 import사용 하려면 대신 다음을 수행해야합니다 require.

import * as debug from 'gulp-debug';

...

    return gulp.src('./examples/*.html')
        .pipe(debug({title: 'example src:'}))
        .pipe(gulp.dest('./build'));

(또한 추가했습니다 title).


답변