- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 gulp watch 的问题,错误后会中断。然后我找到了一个不错的reference使用水管工及其扩展,gulp-prettyerror .
然后我创建这个gulpfile.js
const gulp = require('gulp'),
babel = require('gulp-babel')
changed = require('gulp-changed'),
prettyError = require('gulp-prettyerror');
////////////////////////// START SQUAREBOOK ////////////////////////////////
const reactSquarebookSource = './common/modules/squarebook/web/jsx/*.{js,jsx}';
const reactSquarebookDest = './common/modules/squarebook/web/js';
// run babel on squarebook
gulp.task('babel:squarebook', function () {
return gulp.src(reactSquarebookSource)
.pipe(prettyError())
.pipe(changed(reactSquarebookDest)) // make sure only changed source
.pipe(babel()) // do the babel
.pipe(gulp.dest(reactSquarebookDest));
});
gulp.task('watch:squarebook', function () {
gulp.watch(reactSquarebookSource, ['babel:squarebook']);
});
////////////////////////// FINISH SQUAREBOOK ///////////////////////////////
///////////////////////// START FRONTEND ///////////////////////////////////
const reactFrontendSource = './frontend/web/jsx/*.{js,jsx}';
const reactFrontendDest = './frontend/web/js';
// run babel on frontend
gulp.task('babel:frontend', function () {
return gulp.src(reactFrontendSource)
.pipe(prettyError())
.pipe(changed(reactFrontendDest)) // make sure only changed source
.pipe(babel()) // do the babel
.pipe(gulp.dest(reactFrontendDest));
});
gulp.task('watch:frontend', function () {
gulp.watch(reactFrontendSource, ['babel:frontend']);
});
///////////////////////// FINISH FRONTEND //////////////////////////////////
// all babel react
gulp.task('babel', [
'babel:squarebook',
'babel:frontend'
])
// all watchers
gulp.task('watch', [
'watch:squarebook',
'watch:frontend'
]);
gulp.task('default', [
'babel',
'watch'
]);
prettyError 工作得很好。我喜欢。但这段代码相当多余。我仍然需要创建更多模块,这将使我每次创建模块时都复制粘贴任务。所以我决定将其重构为:
// require all the libraries
const gulp = require('gulp'),
babel = require('gulp-babel')
changed = require('gulp-changed'),
prettyError = require('gulp-prettyerror');
// react source map
const moduleSources = {
squarebook: {
src : './common/modules/squarebook/web/jsx/*.{js,jsx}',
dest : './common/modules/squarebook/web/js'
},
frontend: {
src : './frontend/web/jsx/*.{js,jsx}',
dest : './frontend/web/js'
}
}
gulp.task('babel', function () {
for(var moduleName in moduleSources) {
var sourceMap = moduleSources[moduleName];
var taskName = 'babel:' + moduleName;
// create the task
gulp.task(taskName, function () {
return gulp.src(sourceMap.src)
.pipe(changed(sourceMap.dest)) // make sure only changed source
.pipe(prettyError())
.pipe(babel()) // do the babel
.pipe(gulp.dest(sourceMap.dest));
});
// do the watcher
gulp.watch(sourceMap.src, [taskName]);
}
});
gulp.task('default', [
'babel'
]);
现在我尝试在 './common/modules/squarebook/web/jsx/*.{js,jsx}'
上创建错误,但错误未显示。看起来 PrettyError 只显示最后一个循环中的错误。观察者没有中断,但没有显示错误。知道为什么会发生这种情况吗?
我想知道循环是否出错。
最佳答案
问题是我在匿名函数内使用sourceMap
,它将更新直到循环结束。所以,我的解决方案是:
// require all the libraries
const gulp = require('gulp'),
babel = require('gulp-babel')
changed = require('gulp-changed'),
prettyError = require('gulp-prettyerror');
// react source map
const moduleSources = {
squarebook: {
src : './common/modules/squarebook/web/jsx/*.{js,jsx}',
dest : './common/modules/squarebook/web/js'
},
frontend: {
src : './frontend/web/jsx/*.{js,jsx}',
dest : './frontend/web/js'
}
}
// http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
// create function to ensure the right closure
function processBabel(src, dest) {
console.log(src);
return gulp.src(src)
.pipe(changed(dest)) // make sure only changed source
.pipe(prettyError())
.pipe(babel()) // do the babel
.pipe(gulp.dest(dest));
}
var babelTasks = [];
gulp.task('babel', function () {
for(var moduleName in moduleSources) {
var sourceMap = moduleSources[moduleName];
var taskName = 'babel:' + moduleName;
// create the task
gulp.task(taskName, processBabel.bind(this, sourceMap.src, sourceMap.dest));
// do the watcher
gulp.watch(sourceMap.src, [taskName]);
}
});
gulp.task('default', [
'babel'
]);
因此,我创建了其他函数来处理src
和dest
,这样它就不会通过引用进行更新。
关于javascript - Gulp Plumber 或 PrettyError 无法在循环中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38073287/
实习测试框架有没有 有任何 gulp 插件或文档可以与 gulp 集成吗? 最佳答案 它看起来不像,但我已经做到了 使用 gulp-shell : gulp.task('intern', shell.
我正在寻找答案,不必深入或详细。只是想确切地知道任务序列发生了什么。 gulp.task('name',['*this right here*'], function() { // conte
假设有四个任务 'a'、'b'、'c'、'd'(b 依赖于 c 和 d;c 和 d 都依赖于 a),因此任务按以下顺序运行: a-> (c, d) -> b 这是相应地工作的 gulpfile.js:
我安装了本地gulp插件,并意识到我不需要它。如何删除它,是否有例如npm remove gulp-sass这样的命令? 最佳答案 只需运行npm uninstall --save即可。转到此链接h
我使用del包删除文件夹: gulp.task('clean', function(){ return del('dist/**/*', {force:true}); }); 但是,如果dis
有一个 super 简单的 gulp 文件,我想在其中依次运行一些基本的 gulp 任务。 我似乎无法在 Gulp v4 中运行它。使用 run-sequence 在 Gulp v3 中有类似的东西而
我目前有这样的文件结构 SASS gulpfile.js node_modules sites example-site scss
我创建了一个简单的 Gulp 任务来检查我的 ES6 文件中的更改。我想转换它们并在出现问题时显示错误消息。 正在显示错误屏幕。但是,当一切都成功时,我想显示不同的信息。 我试过 .on('end')
我已经安装了gulp在全局范围内 sudo npm install --global gulp-cli 和本地 npm install --save-dev gulp /usr/local/bin/g
我正在尝试使用 gulp-rev、gulp-rev-replace 和 gulp-rev-css-url 重写对我的版本图像文件的引用。 我已设法修改文件并将 list 与以下 gulp 代码合并:
尝试创建一个 gulp 任务,通过 LESS 通过管道传输来自不同文件夹的一堆文件,然后将它们输出到基于原始源的文件夹。考虑这个文件夹结构: Project +-- /Module_A | +-
我在终端上的项目文件夹中,并且: 如果我执行: gulp -v 我得到: [15:47:15] CLI version 3.9.0 [15:47:15] Local version 3.9.
设置很简单: gulp.task('rev-js', function() { return gulp.src('/js/main.js, {base: '.'}) .pipe(ne
我有两个任务,B 依赖于 A。 任务A需要循环一个数组,然后执行gulp.dest,但似乎B会在A完成之前执行。 A 所做的就是加载所有 html,并将每个 html 注入(inject)到 temp
我尝试在工作流程中将 gulp-data 与 gulp-jade 结合使用,但收到与 gulp-data 插件相关的错误。 这是我的 gulpfile.js var gulp = require('g
编辑:有没有办法清理这段代码? 任务.咖啡 # Watch pages gulp.task 'jade', -> # Watch index gulp.src('src/jade/index.
这可能听起来很愚蠢,但请耐心等待。我遇到了麻烦。 我正在开发一个使用 Grunt 来编译和构建其发行版的项目。但是,它使用另一个名为 prism 的库,您可以在 http://prismjs.com
我有一个简单的 less 任务的 gulp 工作流程,如下所示: gulp.task('less', function() { gulp.src(source_less) .p
我有一个 gulp 工作流程,一切都运行良好,但似乎它只适用于最上面的文件,例如:public/index.html,但如果我想使用 public/products/item.html,gulp-da
我想使用 gulp-useref 将我所有的 JavaScript 文件连接成一个。 在我的 JavaScript 文件中,我混合了pre-minified 和non-minified 文件。 我只想
我是一名优秀的程序员,十分优秀!