- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
has no method ' watch'"-6ren"> has no method ' watch'"-所以我在 gulpfile.js 中添加了一个监视任务,如下所示: gulp.task('watch', function(){ gulp.watch('src/style/*.less', -6ren">
所以我在 gulpfile.js 中添加了一个监视任务,如下所示:
gulp.task('watch', function(){
gulp.watch('src/style/*.less', ['css']);
});
但是当我运行它时(gulp watch
),我收到以下错误:
PS C:\Projects\web\basic> gulp watch
[21:28:42] Using gulpfile C:\Projects\web\basic\gulpfile.js
[21:28:42] Starting 'watch'...
[21:28:42] 'watch' errored after 226 μs
[21:28:42] TypeError: Object #<Object> has no method 'watch'
at Gulp.watch (C:\Projects\web\basic\node_modules\gulp\index.js:40:14)
at Gulp.<anonymous> (C:\Projects\web\basic\gulpfile.js:37:7)
at module.exports (C:\Projects\web\basic\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\Projects\web\basic\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\Projects\web\basic\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (C:\Projects\web\basic\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
at C:\Users\Magnus\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
据我了解, watch 是 built-in function in gulp 那么我在这里做错了什么?我见过的解决这个困境的唯一其他解决方案是 Linux 特定的(并且可能是问题的原因)。它在 this SO-thread 中有描述。 ,但我使用的是 Windows,我看不出该问题如何在 Windows 环境中出现。
此外,我还查看了用于项目安装的 Gulp index.js 文件,它确实包含一个 watch 原型(prototype),但问题似乎(根据错误消息)来自监视函数中的最后一行:
Gulp.prototype.watch = function(glob, opt, fn) {
if (typeof opt === 'function' || Array.isArray(opt)) {
fn = opt;
opt = null;
}
// Array of tasks given
if (Array.isArray(fn)) {
return vfs.watch(glob, opt, function() {
this.start.apply(this, fn);
}.bind(this));
}
return vfs.watch(glob, opt, fn);
};
正是 return vfs.watch(glob, opt, fn);
行导致了崩溃(第 40 行)。在本例中,vfs 是一个包含 vinyl-fs 的变量,如下所示:
var vfs = require('vinyl-fs');
但即使在我的项目和全局中手动安装它之后,它仍然无法工作。任何人都知道可能导致此崩溃的原因是什么?
编辑:完整的 gulpfile.js:
var gulp = require('gulp'),
less = require('gulp-less'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify');
var cssPath = 'src/style/*.less';
var jsPath = 'src/js/*.js';
var htmlPath = 'src/index.htm';
var assetPath = 'src/assets/*';
gulp.task('css', function() {
return gulp.src(cssPath) //Get all less files from src/style/
.pipe(less()) //Pass them on to less
.pipe(concat('style.css')) //Concat all files to one big style.css-file
.pipe(gulp.dest('dist/style')) //Pass the less result to gulp so it can be moved to dist/css
});
gulp.task('js', function(){
return gulp.src(jsPath) //Get all the javascript files from src/js/
.pipe(uglify()) //Pass them on to uglify
.pipe(concat('all.js')) //Concat all the files into one javascript file
.pipe(gulp.dest('dist/js')) //Pass the result to gulp so it can be moved to dist/js
});
gulp.task('html', function(){
return gulp.src(htmlPath)
.pipe(gulp.dest('dist'))
});
gulp.task('assets', function(){
return gulp.src(assetPath)
.pipe(gulp.dest('dist/assets'))
});
gulp.task('watch', function(){
gulp.watch(cssPath, ['css']);
gulp.watch(jsPath, ['js']);
gulp.watch(htmlPath, ['html']);
gulp.watch(assetPath, ['assets']);
});
gulp.task('default', ['css', 'js', 'html', 'assets']);
最佳答案
感谢@ezrepotein 和@entre 帮助我。
解决方案很简单,重新安装node,然后卸载并重新安装项目中的所有gulp组件。之后一切顺利,所以在安装 Node 或 gulp 组件期间一定出了问题。
关于javascript - 使用 gulp.watch 会抛出 "TypeError: Object #<Object> has no method ' watch'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33587626/
实习测试框架有没有 有任何 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 文件。 我只想
我是一名优秀的程序员,十分优秀!