【问题标题】:npm: how to run test & lint on each change?npm:如何在每次更改时运行测试和 lint?
【发布时间】:2015-12-30 11:49:04
【问题描述】:

我正在使用裸 npm(没有 grunt/gulp)方法来开发我的新 MEAN 项目。
我的配置如下:

文件package.json:

...
"start": "nodemon ./bin/www",
"lint": "jshint **/*.js",
"test": "mocha --recursive",
"dependencies": {
  ...
},
"devDependencies": {
  ...
},

在开始之前,我运行npm startnodemon 开始监视我的项目树的更改,在每次源文件更改后触发重新启动。
到目前为止一切顺利。

但是,如果我想在每次重新启动时包括 - 比如说 - lint 和/或 test 阶段怎么办?
我没有找到任何线索,也没有在nodemon 页面和npm 一个...

【问题讨论】:

    标签: node.js npm nodemon


    【解决方案1】:

    因此,您应该在 package.json 中定义 start 以首先运行 lint,然后进行测试,然后才是实际运行的服务器。 您可以在以下帖子中找到示例: http://substack.net/task_automation_with_npm_run

    您应该运行“npm run monitor”命令来启动监控,并且重新启动应该调用 npm run start 脚本。

    但基本上你想拥有(基于你的 package.json)

    "scripts": {
        "start": "npm run lint & npm run test & node ./myfile.js",
        "lint": "jshint **/*.js",
        "test": "mocha --recursive",
        "monitor": "nodemon ./bin/www"
        .....
    

    【讨论】:

    • ./myfile.js 是什么?
    • 启动应用程序的 app.js 文件。
    • 我不明白你的意思,对不起:如果我打电话给npm run monitor,那npm start会怎么调用?
    • 如果这就是你启动应用程序的方式,那就是。
    • 查看github.com/remy/nodemon#running-non-node-scripts,这样你就可以拥有 nodemon --exec "npm run start"
    猜你喜欢
    • 2019-04-27
    • 2020-08-01
    • 2020-06-10
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    相关资源
    最近更新 更多