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
Gulp doesn't create folder?
提问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/fonts
doesn'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 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. Otherwise you'll need to get into merging streams or the addSrc
plugin.
因为这两个 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' 文件夹不存在,则会公开创建它。