为重新启动创建gulp任务

时间:2015-07-20 07:36:28

标签: javascript gulp

试图将其置于监视任务中?

browserify -e test/spec/suite.js -t reactify -t rewireify -o test/spec/bundle.js

我的gulp文件目前是:

var gulp = require('gulp'),
requireDir = require('require-dir');

requireDir('./gulp-tasks');

gulp.task('default', ['browserify','css','karma'], function () {
gulp.watch('../App/src/**/*.js', ['browserify']);
 gulp.watch('../App/src/**/*.css', ['css']);
gulp.watch('../App/src/tests/**/*.js', ['rewireify']);
gulp.watch('../App/src/tests/**/*.js', ['karma']);
});

gulp.task('production', ['react', 'css']);

rewireify.js:

var gulp = require('gulp'),
concat = require('gulp-concat'),
rewireify = require('rewireify');

gulp.task('css', function () {
gulp.src([
    './App/src/tests/**/*.js'
])
    .pipe(concat('bundletest.js'))
    .pipe(rewireify())
    .pipe(gulp.dest('test/spec/bundle.js'));
});

当我执行gulp任务时,我收到错误:

TypeError: Cannot read property 'ignore' of undefined
    at rewireify (d:\Source\Workspaces\\node_modules\rewireify\lib\index.js:12:20)
at Gulp.<anonymous> (d:\Source\Workspaces\Call Parents\DEV\CG.CallParents.Web\Areas\Beta\gulp-tasks\rewireify.js:10:15)
at module.exports (d:\Source\Workspaces\\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (d:\Source\gulp\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (d:\Source\\gulp\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (d:\Source\Workspaces\\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
at C:\Users\matthew.harris\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)

任何人都知道如何让它发挥作用?

1 个答案:

答案 0 :(得分:0)

要记住的关键点是重新启动(喜欢这个名字)是一个转换

  

Browserify中最强大的功能是source transforms。源转换是在已解析的模块和返回的内容之间注入的流。使用源转换的一个简单用例是将CoffeeScript编译为JavaScript。

http://blakeembrey.com/articles/2013/09/introduction-to-browserify/

无论如何,我的建议是将gulp-concat部分分成自己的任务,然后创建一个重新启动的任务,您将在之后调用:

gulp.task("build-functional", function () {
    return browserify('some-gulp-concatenated.js', {})
        .transform(rewireify, rewireifyOptions)
        .bundle()
        .pipe(gulp.dest('test/spec/bundle.js'))
}

查看here以获取其他示例。