node.js - 命令未在 npm 脚本中的 && 之后运行

标签 node.js gulp

这是我正在运行的 npm 脚本(当然是在我的 package.json 中定义的):

  "scripts": {
    "test": "gulp && mocha-casperjs test/features/specs/*-spec.js"
  }

出于某种原因,我所有的 gulp 任务都运行良好,但我的 mocha 测试从未运行过。所以当 gulp 完成时我看到的是这样的:

$ npm test

> someApp@0.0.0 test /Users/me/code/projects/we-do-tdd
> gulp && mocha-casperjs test/features/specs/*-spec.js

[17:34:50] Using gulpfile ~/code/projects/someApp/gulpfile.js
[17:34:50] Starting 'default'...
[17:34:50] Starting 'bundleApp'...
[17:34:50] Finished 'bundleApp' after 17 ms
[17:34:50] Starting 'watch'...
[17:34:50] Finished 'watch' after 7.33 ms
[17:34:50] Starting 'startApp'...
[17:34:50] Finished 'startApp' after 6.63 ms
[17:34:50] Finished 'default' after 34 ms

gulp 文件

"use strict";

var app = require('./server'),
    gulp = require('gulp'),
    runSequence = require('run-sequence'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    gutil = require('gulp-util'),
    babelify = require('babelify');

var scriptsCount = 0;

gulp.task('default', function (cb){
    runSequence(['bundleApp','watch'], ['startApp'], cb)
});

gulp.task('watch', function () {
    gulp.watch(['./src/*.js'], ['scripts']);
});

gulp.task('startApp', function (cb) {
    app.listen(3000, cb).on('error', function(err) {
        console.log(err);
    });;
});

gulp.task('bundleApp', function () {
    bundleApp(false);
});

function bundleApp() {
    scriptsCount++;
    var appBundler = browserify({
        entries: './src/components/app.js',
        debug: true
    })

    appBundler
        .transform("babelify", {presets: ["es2015", "react"]})
        .bundle()
        .on('error', gutil.log)
        .pipe(source('bundle.js'))
        .pipe(gulp.dest('./build/app/js'));
}

最佳答案

&& 之后的命令在第一个命令完成后执行,因为您的默认 gulp 任务不会终止,所以第二个命令永远不会被调用。

使用:

 "test": "gulp & mocha-casperjs test/features/specs/*-spec.js"

一个 & 同时运行命令。

关于node.js - 命令未在 npm 脚本中的 && 之后运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36510471/

相关文章:

node.js - 在 CPanel 上部署 Node.js React 应用程序 - 'Failed to load resource: the server responded with a status of 404 ()'

gulp - babel ES7 Async - 未定义 regeneratorRuntime

jquery - 加载 JqueryUI 的 Browserify 无法正常工作

python - 是否可以为 Django 配置 Gulp Livereload?

angular - 如何为多个应用程序捆绑可重用的 angular 2 组件?

Node.js 文件上传功能 : Large Video Files Uploading with support for interruption

javascript - 类型错误 : Cannot read property 'firstChild' of undefined While rendering the react page server side

node.js - 云函数崩溃并显示 `Error: Can' 无法确定 Firebase 数据库 URL。

angularjs - browserSync 的 modRewrite 不适用于带有 gulp 的路径 'app/index.html' 的 angularjs html5mode

node.js - 生产中的 KeystoneJS