Gulp doesn't create folder?

别等时光非礼了梦想. 提交于 2021-02-04 17:23:28

问题


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:

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.

But after I run it, dist/public/fonts doesn't exist. Why not?


回答1:


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.

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 addSrc plugin.

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']);



回答2:


According to this article, specify your src like this:

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.



来源:https://stackoverflow.com/questions/30360885/gulp-doesnt-create-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!