gulp --watch直接退出,并没有监听

1.在学习es6(彩票项目)搭建环境时遇到gulp --watch 只运行一次就退出了不能监听:

D:\nodejs\es6-base>gulp --watch
[09:18:49] Failed to load external module @babel/register
[09:18:49] Requiring external module babel-register
[09:18:52] Using gulpfile D:\nodejs\es6-base\gulpfile.babel.js
[09:18:52] Starting 'build'...
[09:18:52] Starting 'clean'...
[09:18:52] Finished 'clean' after 62 ms
[09:18:52] Starting 'css'...
[09:18:52] Finished 'css' after 44 ms
[09:18:52] Starting 'pages'...
[09:18:52] Finished 'pages' after 78 ms
[09:18:52] Starting 'scripts'...
[09:18:52] Version: webpack 1.15.0
   Asset     Size  Chunks             Chunk Names
index.js  1.51 kB       0  [emitted]  index
[09:18:53] Finished 'scripts' after 580 ms
[09:18:53] Starting 'browser'...
[09:18:53] Finished 'browser' after 202 μs
[09:18:53] Starting 'serve'...
[09:18:53] Finished 'serve' after 315 μs
[09:18:53] Finished 'build' after 792 ms
[09:18:53] Starting 'default'...

D:\nodejs\es6-base>

2.解决问题:

多次尝试后发现tasks -> util -> args.js中没有将 args暴露出去:

// yargs包是用来处理命令行参数的,自动识别命令行命令
import yargs from 'yargs';

const args = yargs
// 是否用于生产,压缩所有scripts
    .option('production', {
        boolean: true,
        default: false,
        describe: 'min all scripts'
    })

    // 监听所有文件
    .option('watch', {
        boolean: true,
        default: false,
        describe: 'watch all files'
    })

    // 详细输出命令行执行日志
    .option('verbose', {
        boolean: true,
        default: false,
        describe: 'log'
    })

    // 强制生成sourcemaps(js压缩后会有一个sourcemaps)
    .option('sourcemaps', {
        describe: 'force the creation of sourcemaps'
    })

    // 服务器端口
    .option('port', {
        string: true,
        default: '8880',
        describe: 'server port'
    })

    // argv表示对输入的命令行以字符串解析
    .argv;

// args一定要暴露出去否则gulp --watch 不会完成监听
export default args;

 3.备注

参考:http://www.imooc.com/wenda/detail/354015

上一篇:怎么解决syntaxerror:non-utf-8 code starting with \xc4'in file


下一篇:Dsicuz x2.5、X3、X3.2如何去掉域名后面的/forum.php