简体   繁体   English

Gulp不创建文件夹?

[英]Gulp doesn't create folder?

When I minified my css, I was left with an incorrect path to the fonts from various libraries. 当我缩小我的CSS时,我从各种库中找到了不正确的字体路径。 So, I created a task to move the fonts from my bower_components/ folder to dist/public/fonts : 所以,我创建了一个任务,将字体从我的bower_components/文件夹移动到dist/public/fonts

gulp.task('doit', function() {
    gulp.src(["public/bower_components/bootstrap/dist/fonts/*", "public/bower_components/font-awesome/fonts/*"])
        .pipe(gulp.dest("dist/public/fonts"));
});

Basically that should throw any fonts I need into a generic fonts folder, which my minified css should now be able to access. 基本上应该把我需要的任何字体扔进一个通用的字体文件夹,我的缩小的CSS现在应该可以访问。

But after I run it, dist/public/fonts doesn't exist. 但是在我运行之后, dist/public/fonts不存在。 Why not? 为什么不?

I don't fully understand the paths you're src -ing ( public/bower_components ?), but I believe you'll want to use the base option for gulp.src . 我不完全理解你的路径src -ing( public/bower_components ?),但我相信你会希望使用base的选项gulp.src

Because these two globs will have different bases, I'd suggest breaking it into two separate tasks, and building a third to aggregate them into a single. 因为这两个globs将有不同的基础,我建议将它分成两个单独的任务,并建立第三个将它们聚合成一个单独的任务。 Otherwise you'll need to get into merging streams or the addSrc plugin. 否则你需要进入合并流或addSrc插件。

gulp.task('copy:fonts:bootstrap', function () {
    return gulp.src(
        [
            'public/bower_components/bootstrap/dist/fonts/**/*'
        ],
        {
            base: 'public/bower_components/bootstrap/dist/fonts'
        }
    )
        .pipe(gulp.dest('dist/public/fonts'));
});

gulp.task('copy:fonts:fontawesome', function () {
    return gulp.src(
        [
            'public/bower_components/font-awesome/fonts/**/*'
        ],
        {
            base: 'public/bower_components/font-awesome/fonts'
        }
    )
        .pipe(gulp.dest('dist/public/fonts'));
});

gulp.task('copy:fonts', ['copy:fonts:bootstrap', 'copy:fonts:fontawesome']);

According to this article , specify your src like this: 根据这篇文章 ,指定你的src如下:

gulp.src(['src/js/**/*.js'], { base: 'src' })
  .pipe(foo())
  .pipe(gulp.dest("./public/"));

and it will auto create the destination directories for you. 它会自动为您创建目标目录。 In this case, the 'js' folder will be created in public if it doesnt exist already. 在这种情况下,如果'js'文件夹不存在,它将在公共场所创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM