简体   繁体   English

用gulp进行监视无法正常工作

[英]Watchify with gulp is not working

I have created this gulp task for watchifying but it gives this error: Cannot read property 'cache' of undefined 我已经创建了这个gulp任务来进行观察,但是它给出了以下错误:无法读取未定义的属性“ cache”

gulp.task('browserify-With-Watch', function () {
"use strict";
var bundler = browserify({
    entries: ['src/js/ede-wrapper.js'], // Only need initial file, browserify finds the deps
    debug: true, // Gives us sourcemapping
    cache: {},
    packageCache: {},
    fullPaths: true
});

var watcher  = watchify(bundler);

return watcher
    .on('update', function () { // When any files update
        watcher.bundle() // Create new bundle that uses the cache for high performance
            .pipe(source('src/js/ede-wrapper.js'))
            // This is where you add uglifying etc.
            .pipe(gulp.dest('dist'));
    })
    .bundle() // Create the initial bundle when starting the task
    .pipe(source('src/js/ede-wrapper.js'))
    .pipe(gulp.dest('dist'));
});

This is the error i get 这是我得到的错误

[17:06:04] Starting 'browserify-With-Watch'...
[17:06:04] 'browserify-With-Watch' errored after 1.6 ms
[17:06:04] TypeError: Cannot read property 'cache' of undefined
    at watchify (d:\KHOBI\Source\ede_js_sdk\node_modules\watchify\index.js:13:27)
    at Gulp.<anonymous> (d:\KHOBI\Source\ede_js_sdk\gulpfile.js:55:20)
    at module.exports (d:\KHOBI\Source\ede_js_sdk\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (d:\KHOBI\Source\ede_js_sdk\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (d:\KHOBI\Source\ede_js_sdk\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (d:\KHOBI\Source\ede_js_sdk\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
    at C:\Users\hasithm\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)

Hope this is not something wrong with the watchify version that I use 希望我使用的watchify版本没有问题

Note: I have used gulp-browserify to browserify 注意:我已经使用gulp-browserify来进行浏览器修饰

Note: I have used gulp-browserify to browserify 注意:我已经使用gulp-browserify来进行浏览器修饰

You should use browserify directly here, not gulp-browserify. 您应该在这里直接使用browserify,而不是gulp-browserify。

watchify expects a browserify instance but you're giving it a stream created by gulp-browserify. watchify需要一个browserify实例,但是您正在为其提供由gulp-browserify创建的流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM