使用gulp选择并移动目录及其文件 [英] Use gulp to select and move directories and their files

查看:201
本文介绍了使用gulp选择并移动目录及其文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用gulp来调用一个清理我的 dist / 目录的bash脚本,并将相应的文件移动到干净的目录中。我希望这可以通过gulp完成,因为我不确定该脚本可以在非* nix文件系统上工作。

到目前为止,我正在使用gulp-clean模块来清理 dist / 目录,但是当我尝试将所需的目录及其文件移动到dist文件夹时,目录为空。

I'm currently using gulp to call a bash script that cleans my dist/ directory and moves the appropriate files to the clean directory. I would like this to be done with gulp because I am not sure the script would work on a non *nix file system.
So far, I'm using the gulp-clean module to clean the dist/ directory but when I try to move the required directories and their files to the dist folder, the directories are empty.

var gulp = require('gulp'),
    clean = require('gulp-clean');

gulp.task('clean', function(){
  return gulp.src(['dist/*'], {read:false})
  .pipe(clean());
});

gulp.task('move',['clean'], function(){
  gulp.src(['_locales', 'icons', 'src/page_action', 'manifest.json'])
  .pipe(gulp.dest('dist'));
});

gulp.task('dist', ['move']);

调用 gulp dist code> dist / 目录正在填充正确的目录,但它们全部为空

calling gulp dist results in the the dist/ directory being populated with the correct directories but they are all empty

$ ls dist/*
dist/manifest.json

dist/_locales:

dist/icons:

dist/page_action:

如何将目录及其内容复制到 dist / folder?

How do I copy the directories and their contents to the dist/ folder?

推荐答案

您需要包含 base 您想要的方式:

You need to include the base option to src, which will preserve the file structure the way you want:

var filesToMove = [
        './_locales/**/*.*',
        './icons/**/*.*',
        './src/page_action/**/*.*',
        './manifest.json'
    ];

gulp.task('move',['clean'], function(){
  // the base option sets the relative root for the set of files,
  // preserving the folder structure
  gulp.src(filesToMove, { base: './' })
  .pipe(gulp.dest('dist'));
});






另外,您可能会遇到麻烦如果你将所有这些源文件放在项目的根目录中,那就是道路。


Also, you are probably going to have trouble down the road if you have all these source files in the root of your project.

如果可以,我建议你使用单个 src / 文件夹,然后将所有应用程序特定的文件移动到那里。这使得维护更容易前进,并防止特定于构建的文件与特定于应用程序的文件混淆。

If you can, I'd recommend you use a single src/ folder and move all your application-specific files into there. This makes maintenance easier moving forward, and prevents your build-specific files from getting mixed up with your application-specific files.

如果这样做,那么只需更换所有出现的事件在上面的例子中 ./ src /

If you do this, then simply replace all occurrences of ./ with src/ in the example above.

这篇关于使用gulp选择并移动目录及其文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆