javascript Gulp 不创建文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30360885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:05:13  来源:igfitidea点击:

Gulp doesn't create folder?

javascriptnode.jsgulp

提问by rublex

When I minified my css, I was left with an incorrect path to the fonts from various libraries. So, I created a task to move the fonts from my bower_components/folder to dist/public/fonts:

当我缩小我的 css 时,我得到了一个不正确的来自各种库的字体路径。所以,我创建了一个任务来将字体从我的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/fontsdoesn't exist. Why not?

但我运行后,dist/public/fonts不存在。为什么不?

回答by JAAulde

I don't fully understand the paths you're src-ing (public/bower_components?), but I believe you'll want to use the baseoption 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. Otherwise you'll need to get into merging streams or the addSrcplugin.

因为这两个 glob 将具有不同的基础,我建议将其分解为两个单独的任务,并构建第三个将它们聚合为一个。否则,您将需要进入合并流或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']);

回答by sqram

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' 文件夹不存在,则会公开创建它。