Javascript 断断续续地创建目标目录 为什么gulp有时只创建子目录,即使源文件/目录没有更改,我只是重新运行gulp?
有时候我的gulpfile很好用。。与创建生成目录后第一次运行它类似:Javascript 断断续续地创建目标目录 为什么gulp有时只创建子目录,即使源文件/目录没有更改,我只是重新运行gulp?,javascript,gulp,Javascript,Gulp,有时候我的gulpfile很好用。。与创建生成目录后第一次运行它类似: PS C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch> gulp [09:56:11] Requiring external module babel-register [09:56:13] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js [09:56:13]
PS C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch> gulp
[09:56:11] Requiring external module babel-register
[09:56:13] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js
[09:56:13] Starting 'default'...
[09:56:13] Starting 'clean'...
[09:56:13] Starting 'root'...
[09:56:13] Finished 'root' after 6.23 ms
[09:56:13] Starting 'templates'...
[09:56:13] Finished 'templates' after 1.68 ms
[09:56:13] Starting 'css'...
[09:56:13] Finished 'css' after 7.43 ms
[09:56:13] Starting 'sass'...
[09:56:13] Finished 'sass' after 6.96 ms
[09:56:13] Starting 'scripts'...
[09:56:13] Finished 'scripts' after 3.88 ms
[09:56:13] Finished 'default' after 39 ms
[09:56:13] Finished 'clean' after 91 ms
[09:56:14] File dev\styles\bootstrap-theme.css found.
[09:56:14] Processed media queries:
[09:56:14] @media (max-width: 767px)
[09:56:14] File dev\styles\bootstrap-theme.css created.
[09:56:14] File dev\styles\bootstrap-theme.min.css found.
[09:56:14] Processed media queries:
[09:56:14] @media (max-width:767px)
[09:56:14] File dev\styles\bootstrap-theme.min.css created.
[09:56:15] File dev\styles\bootstrap.css found.
[09:56:15] Processed media queries:
[09:56:15] @media screen and (-webkit-min-device-pixel-ratio: 0)
[09:56:15] @media (max-device-width: 480px) and (orientation: landscape)
[09:56:15] @media all and (transform-3d), (-webkit-transform-3d)
[09:56:15] @media (min-width: 768px)
[09:56:15] @media screen and (min-width: 768px)
[09:56:15] @media (min-width: 768px) and (max-width: 991px)
[09:56:15] @media (min-width: 992px)
[09:56:15] @media (min-width: 992px) and (max-width: 1199px)
[09:56:15] @media (min-width: 1200px)
[09:56:15] @media screen and (max-width: 767px)
[09:56:15] @media (max-width: 767px)
[09:56:15] @media print
[09:56:15] File dev\styles\bootstrap.css created.
[09:56:15] File dev\styles\bootstrap.min.css found.
[09:56:15] Processed media queries:
[09:56:15] @media screen and (-webkit-min-device-pixel-ratio:0)
[09:56:15] @media (max-device-width:480px) and (orientation:landscape)
[09:56:15] @media all and (transform-3d),(-webkit-transform-3d)
[09:56:15] @media (min-width:768px)
[09:56:15] @media screen and (min-width:768px)
[09:56:15] @media (min-width:768px) and (max-width:991px)
[09:56:15] @media (min-width:992px)
[09:56:15] @media (min-width:992px) and (max-width:1199px)
[09:56:15] @media (min-width:1200px)
[09:56:15] @media screen and (max-width:767px)
[09:56:15] @media (max-width:767px)
[09:56:15] @media print
[09:56:15] File dev\styles\bootstrap.min.css created.
[09:56:16] File dev\styles\main.css found.
[09:56:16] File dev\styles\main.css created.
[BS] Access URLs:
------------------------------------
Local: http://localhost:3000
External: http://192.168.1.9:3000
------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.9:3001
------------------------------------
[BS] Serving files from: ./build/
[BS] 5 files changed (bootstrap-theme.min.css, bootstrap-theme.min.min.css, bootstrap.min.css, bootstrap.min.min.css, ma
in.min.css)
[BS] 7 files changed (404.html, index.html, browserconfig.xml, apple-touch-icon.png, tile-wide.png, tile.png, favicon.ic
o)
[BS] 5 files changed (bootstrap.min.js, bootstrap.min.min.js, jquery-3.1.0.min.js, main.min.js, modernizr-2.8.3-respond-
1.4.2.min.min.js)
PS C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch> gulp
[09:57:31] Requiring external module babel-register
[09:57:33] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js
[09:57:33] Starting 'default'...
[09:57:33] Starting 'clean'...
[09:57:33] Starting 'root'...
[09:57:33] Finished 'root' after 6.26 ms
[09:57:33] Starting 'templates'...
[09:57:33] Finished 'templates' after 1.77 ms
[09:57:33] Starting 'css'...
[09:57:33] Finished 'css' after 7.78 ms
[09:57:33] Starting 'sass'...
[09:57:33] Finished 'sass' after 6.5 ms
[09:57:33] Starting 'scripts'...
[09:57:33] Finished 'scripts' after 3.82 ms
[09:57:33] Finished 'default' after 39 ms
[09:57:34] File dev\styles\bootstrap-theme.css found.
[09:57:34] Processed media queries:
[09:57:34] @media (max-width: 767px)
[09:57:34] File dev\styles\bootstrap-theme.css created.
[09:57:34] File dev\styles\bootstrap-theme.min.css found.
[09:57:34] Processed media queries:
[09:57:34] @media (max-width:767px)
[09:57:34] File dev\styles\bootstrap-theme.min.css created.
[09:57:35] File dev\styles\bootstrap.css found.
[09:57:35] Processed media queries:
[09:57:35] @media screen and (-webkit-min-device-pixel-ratio: 0)
[09:57:35] @media (max-device-width: 480px) and (orientation: landscape)
[09:57:35] @media all and (transform-3d), (-webkit-transform-3d)
[09:57:35] @media (min-width: 768px)
[09:57:35] @media screen and (min-width: 768px)
[09:57:35] @media (min-width: 768px) and (max-width: 991px)
[09:57:35] @media (min-width: 992px)
[09:57:35] @media (min-width: 992px) and (max-width: 1199px)
[09:57:35] @media (min-width: 1200px)
[09:57:35] @media screen and (max-width: 767px)
[09:57:35] @media (max-width: 767px)
[09:57:35] @media print
[09:57:35] File dev\styles\bootstrap.css created.
[09:57:36] File dev\styles\bootstrap.min.css found.
[09:57:36] Processed media queries:
[09:57:36] @media screen and (-webkit-min-device-pixel-ratio:0)
[09:57:36] @media (max-device-width:480px) and (orientation:landscape)
[09:57:36] @media all and (transform-3d),(-webkit-transform-3d)
[09:57:36] @media (min-width:768px)
[09:57:36] @media screen and (min-width:768px)
[09:57:36] @media (min-width:768px) and (max-width:991px)
[09:57:36] @media (min-width:992px)
[09:57:36] @media (min-width:992px) and (max-width:1199px)
[09:57:36] @media (min-width:1200px)
[09:57:36] @media screen and (max-width:767px)
[09:57:36] @media (max-width:767px)
[09:57:36] @media print
[09:57:36] File dev\styles\bootstrap.min.css created.
[09:57:36] File dev\styles\main.css found.
[09:57:36] File dev\styles\main.css created.
[09:57:36] Plumber found unhandled error:
Error: ENOENT: no such file or directory, chmod 'C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch\build\styles
\bootstrap-theme.min.css'
[09:57:36] Plumber found unhandled error:
Error: ENOENT: no such file or directory, chmod 'C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch\build\styles
\bootstrap-theme.min.css'
[09:57:36] Finished 'clean' after 2.94 s
[BS] Access URLs:
------------------------------------
Local: http://localhost:3000
External: http://192.168.1.9:3000
------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.9:3001
------------------------------------
[BS] Serving files from: ./build/
[BS] 7 files changed (404.html, index.html, browserconfig.xml, apple-touch-icon.png, tile-wide.png, tile.png, favicon.ic
o)
[BS] 5 files changed (bootstrap.min.js, bootstrap.min.min.js, jquery-3.1.0.min.js, main.min.js, modernizr-2.8.3-respond-
1.4.2.min.min.js)
但大多数时候(但并非总是),我在style
子目录中遇到了一个错误:
PS C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch> gulp
[09:56:11] Requiring external module babel-register
[09:56:13] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js
[09:56:13] Starting 'default'...
[09:56:13] Starting 'clean'...
[09:56:13] Starting 'root'...
[09:56:13] Finished 'root' after 6.23 ms
[09:56:13] Starting 'templates'...
[09:56:13] Finished 'templates' after 1.68 ms
[09:56:13] Starting 'css'...
[09:56:13] Finished 'css' after 7.43 ms
[09:56:13] Starting 'sass'...
[09:56:13] Finished 'sass' after 6.96 ms
[09:56:13] Starting 'scripts'...
[09:56:13] Finished 'scripts' after 3.88 ms
[09:56:13] Finished 'default' after 39 ms
[09:56:13] Finished 'clean' after 91 ms
[09:56:14] File dev\styles\bootstrap-theme.css found.
[09:56:14] Processed media queries:
[09:56:14] @media (max-width: 767px)
[09:56:14] File dev\styles\bootstrap-theme.css created.
[09:56:14] File dev\styles\bootstrap-theme.min.css found.
[09:56:14] Processed media queries:
[09:56:14] @media (max-width:767px)
[09:56:14] File dev\styles\bootstrap-theme.min.css created.
[09:56:15] File dev\styles\bootstrap.css found.
[09:56:15] Processed media queries:
[09:56:15] @media screen and (-webkit-min-device-pixel-ratio: 0)
[09:56:15] @media (max-device-width: 480px) and (orientation: landscape)
[09:56:15] @media all and (transform-3d), (-webkit-transform-3d)
[09:56:15] @media (min-width: 768px)
[09:56:15] @media screen and (min-width: 768px)
[09:56:15] @media (min-width: 768px) and (max-width: 991px)
[09:56:15] @media (min-width: 992px)
[09:56:15] @media (min-width: 992px) and (max-width: 1199px)
[09:56:15] @media (min-width: 1200px)
[09:56:15] @media screen and (max-width: 767px)
[09:56:15] @media (max-width: 767px)
[09:56:15] @media print
[09:56:15] File dev\styles\bootstrap.css created.
[09:56:15] File dev\styles\bootstrap.min.css found.
[09:56:15] Processed media queries:
[09:56:15] @media screen and (-webkit-min-device-pixel-ratio:0)
[09:56:15] @media (max-device-width:480px) and (orientation:landscape)
[09:56:15] @media all and (transform-3d),(-webkit-transform-3d)
[09:56:15] @media (min-width:768px)
[09:56:15] @media screen and (min-width:768px)
[09:56:15] @media (min-width:768px) and (max-width:991px)
[09:56:15] @media (min-width:992px)
[09:56:15] @media (min-width:992px) and (max-width:1199px)
[09:56:15] @media (min-width:1200px)
[09:56:15] @media screen and (max-width:767px)
[09:56:15] @media (max-width:767px)
[09:56:15] @media print
[09:56:15] File dev\styles\bootstrap.min.css created.
[09:56:16] File dev\styles\main.css found.
[09:56:16] File dev\styles\main.css created.
[BS] Access URLs:
------------------------------------
Local: http://localhost:3000
External: http://192.168.1.9:3000
------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.9:3001
------------------------------------
[BS] Serving files from: ./build/
[BS] 5 files changed (bootstrap-theme.min.css, bootstrap-theme.min.min.css, bootstrap.min.css, bootstrap.min.min.css, ma
in.min.css)
[BS] 7 files changed (404.html, index.html, browserconfig.xml, apple-touch-icon.png, tile-wide.png, tile.png, favicon.ic
o)
[BS] 5 files changed (bootstrap.min.js, bootstrap.min.min.js, jquery-3.1.0.min.js, main.min.js, modernizr-2.8.3-respond-
1.4.2.min.min.js)
PS C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch> gulp
[09:57:31] Requiring external module babel-register
[09:57:33] Using gulpfile ~\OneDrive\Público\projects\Overwatch\gulpfile.babel.js
[09:57:33] Starting 'default'...
[09:57:33] Starting 'clean'...
[09:57:33] Starting 'root'...
[09:57:33] Finished 'root' after 6.26 ms
[09:57:33] Starting 'templates'...
[09:57:33] Finished 'templates' after 1.77 ms
[09:57:33] Starting 'css'...
[09:57:33] Finished 'css' after 7.78 ms
[09:57:33] Starting 'sass'...
[09:57:33] Finished 'sass' after 6.5 ms
[09:57:33] Starting 'scripts'...
[09:57:33] Finished 'scripts' after 3.82 ms
[09:57:33] Finished 'default' after 39 ms
[09:57:34] File dev\styles\bootstrap-theme.css found.
[09:57:34] Processed media queries:
[09:57:34] @media (max-width: 767px)
[09:57:34] File dev\styles\bootstrap-theme.css created.
[09:57:34] File dev\styles\bootstrap-theme.min.css found.
[09:57:34] Processed media queries:
[09:57:34] @media (max-width:767px)
[09:57:34] File dev\styles\bootstrap-theme.min.css created.
[09:57:35] File dev\styles\bootstrap.css found.
[09:57:35] Processed media queries:
[09:57:35] @media screen and (-webkit-min-device-pixel-ratio: 0)
[09:57:35] @media (max-device-width: 480px) and (orientation: landscape)
[09:57:35] @media all and (transform-3d), (-webkit-transform-3d)
[09:57:35] @media (min-width: 768px)
[09:57:35] @media screen and (min-width: 768px)
[09:57:35] @media (min-width: 768px) and (max-width: 991px)
[09:57:35] @media (min-width: 992px)
[09:57:35] @media (min-width: 992px) and (max-width: 1199px)
[09:57:35] @media (min-width: 1200px)
[09:57:35] @media screen and (max-width: 767px)
[09:57:35] @media (max-width: 767px)
[09:57:35] @media print
[09:57:35] File dev\styles\bootstrap.css created.
[09:57:36] File dev\styles\bootstrap.min.css found.
[09:57:36] Processed media queries:
[09:57:36] @media screen and (-webkit-min-device-pixel-ratio:0)
[09:57:36] @media (max-device-width:480px) and (orientation:landscape)
[09:57:36] @media all and (transform-3d),(-webkit-transform-3d)
[09:57:36] @media (min-width:768px)
[09:57:36] @media screen and (min-width:768px)
[09:57:36] @media (min-width:768px) and (max-width:991px)
[09:57:36] @media (min-width:992px)
[09:57:36] @media (min-width:992px) and (max-width:1199px)
[09:57:36] @media (min-width:1200px)
[09:57:36] @media screen and (max-width:767px)
[09:57:36] @media (max-width:767px)
[09:57:36] @media print
[09:57:36] File dev\styles\bootstrap.min.css created.
[09:57:36] File dev\styles\main.css found.
[09:57:36] File dev\styles\main.css created.
[09:57:36] Plumber found unhandled error:
Error: ENOENT: no such file or directory, chmod 'C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch\build\styles
\bootstrap-theme.min.css'
[09:57:36] Plumber found unhandled error:
Error: ENOENT: no such file or directory, chmod 'C:\Users\RobertoTomás\OneDrive\Público\projects\Overwatch\build\styles
\bootstrap-theme.min.css'
[09:57:36] Finished 'clean' after 2.94 s
[BS] Access URLs:
------------------------------------
Local: http://localhost:3000
External: http://192.168.1.9:3000
------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.9:3001
------------------------------------
[BS] Serving files from: ./build/
[BS] 7 files changed (404.html, index.html, browserconfig.xml, apple-touch-icon.png, tile-wide.png, tile.png, favicon.ic
o)
[BS] 5 files changed (bootstrap.min.js, bootstrap.min.min.js, jquery-3.1.0.min.js, main.min.js, modernizr-2.8.3-respond-
1.4.2.min.min.js)
整个style
子目录不会在build
中创建
这是我的gulpfile:
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var autoPrefixer = require('gulp-autoprefixer');
//if node version is lower than v.0.1.2
//require('es6-promise').polyfill();
var cssComb = require('gulp-csscomb');
var cmq = require('gulp-merge-media-queries');
var cleanCss = require('gulp-clean-css');
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload
var clean = require('gulp-clean');
gulp.task('clean', function (done) {
gulp.src('build/*', { read: false })
.pipe(clean())
done()
})
gulp.task('sass', function (done) {
gulp.src(['dev/styles/**/*.scss', 'dev/styles/**/*.sass'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoPrefixer())
.pipe(cssComb())
.pipe(cmq({ log: true }))
.pipe(gulp.dest('build/styles'))
.pipe(rename({
suffix: '.min'
}))
.pipe(cleanCss())
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/styles'))
.pipe(reload({ stream: true }))
done()
});
gulp.task('css', function (done) {
gulp.src(['dev/styles/**/*.css'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(autoPrefixer())
.pipe(cssComb())
.pipe(cmq({ log: true }))
.pipe(gulp.dest('build/styles'))
.pipe(rename({
suffix: '.min'
}))
.pipe(cleanCss())
.pipe(gulp.dest('build/styles'))
.pipe(reload({ stream: true }))
done()
});
gulp.task('scripts', function (done) {
gulp.src(['dev/scripts/**/*.js'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(browserify())
.pipe(gulp.dest('build/scripts'))
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('build/scripts'))
.pipe(reload({ stream: true }))
done()
});
gulp.task('templates', function (done) {
gulp.src(['dev/hypermedia/**/*.html'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(gulp.dest('build/hypermedia/'))
.pipe(reload({ stream: true }))
done()
});
gulp.task('root', function (done) {
gulp.src(['dev/**/*.html', 'dev/**/*.xml', 'dev/**/*.png', 'dev/**/*.ico'])
.pipe(plumber({
handleError: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(gulp.dest('build/'))
.pipe(reload({ stream: true }))
done()
});
gulp.task('all', function (done) {
gulp.start('root', 'templates', 'css', 'sass', 'scripts')
done()
})
gulp.task('default', ['clean', 'root', 'templates', 'css', 'sass', 'scripts'], function (done) {
gulp.watch('dev/scripts/**/*.js', ['scripts']);
gulp.watch('dev/styles/**/*.css', ['css']);
gulp.watch(['dev/styles/**/*.scss', 'dev/styles/**/*.sass'], ['sass']);
gulp.watch('hypermedia/**/*.html', ['templates']);
gulp.watch(['dev/**/*.html', 'dev/**/*.xml', 'dev/**/*.png', 'dev/**/*.ico'], ['root']);
browserSync.init({ server: './build/' });
done()
});
这特别奇怪,因为我只删除了default
任务开头的样式目录(实际上是依赖项),然后我立即重新创建了它(仍然是依赖项,它应该仍然存在)
我还尝试通过一个承诺来实现这一点,或者作为一系列的.on('end'
调用,使用和不使用done()
回调,但我也没有找到解决方案
奖金问题:
如何将
.min.js
与.js
分开匹配,这样我就不会处理第三方js文件了?我很乐意使用供应商
子目录,但我不确定如何包括除供应商之外的所有处理子目录。1.您不会返回流
在每项任务中都需要这样做:
gulp.task('sass',function(){
return gulp.src(['dev/styles/**/*.scss','dev/styles/**/*.sass'])
您还需要删除代码中散布的所有毫无意义的done()
回调
进一步阅读:
2.您正在并行运行所有任务。
gulp.task('default', ['clean', 'root', 'templates', 'css', 'sass', 'scripts'], function (done) {
上述操作没有按顺序运行clean
,root
,模板
,css
,sass
和脚本
。它们同时运行。这就是为什么会出现enoint
错误的原因。当其他任务创建文件时,您正在删除clean
任务中的文件
在您的情况下,最好的方法可能是使用:
以上内容确保了以下任务顺序:
clean
根目录
,模板
,css
,sass
,脚本
并行watch
发球
进一步阅读:1.您没有返回您的流 在每项任务中都需要这样做:
gulp.task('sass',function(){
return gulp.src(['dev/styles/**/*.scss','dev/styles/**/*.sass'])
您还需要删除代码中散布的所有毫无意义的done()
回调
进一步阅读:
2.您正在并行运行所有任务。
gulp.task('default', ['clean', 'root', 'templates', 'css', 'sass', 'scripts'], function (done) {
上述操作没有按顺序运行clean
,root
,模板
,css
,sass
和脚本
。它们同时运行。这就是为什么会出现enoint
错误的原因。当其他任务创建文件时,您正在删除clean
任务中的文件
在您的情况下,最好的方法可能是使用:
以上内容确保了以下任务顺序:
clean
根目录
,模板
,css
,sass
,脚本
并行watch
发球
进一步阅读:关于奖金问题:您可以通过给文件或模式加上
!
前缀来排除它。如果您的js文件(包括缩小的和未缩小的)位于src
的顶层,您应该使用['src/*.js','!src/*.min.js']
另请参见。了解附加问题:您可以通过给文件或模式添加
!
前缀来排除该文件或模式。如果您的js文件(包括缩小的和未缩小的)位于src
的顶层,您将使用['src/*.js','!src/*.min.js']
另请参见。谢谢!我对何时需要回调与何时不需要回调仍有点不确定。您自己在defult任务中使用它是出于某种原因-无论如何,实施您的建议正好解决了我的问题。谢谢。谢谢!我对何时需要回调与何时不需要回调仍有点不确定。您自己使用它如果因为某种原因参加了最终任务,不管怎样,实施你的建议正好解决了我的问题。谢谢你。哇,谢谢你,亨利,我没想到会有人回来做这个:)哇,谢谢你,亨利,我没想到会有人回来做这个:)