【问题标题】:Watchify with gulp is not working用 gulp 监视不起作用
【发布时间】:2015-08-25 15:31:58
【问题描述】:

我创建了这个用于监视的 gulp 任务,但它给出了这个错误:无法读取未定义的属性“缓存”

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'));
});

这是我得到的错误

[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)

希望我使用的 watchify 版本没有问题

注意:我使用 gulp-browserify 来浏览器化

【问题讨论】:

    标签: javascript gulp browserify watchify


    【解决方案1】:

    注意:我使用 gulp-browserify 来浏览器化

    你应该在这里直接使用 browserify,而不是 gulp-browserify。

    watchify 需要一个 browserify 实例,但你给它的是一个由 gulp-browserify 创建的流。

    【讨论】:

    猜你喜欢
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多