【问题标题】:run NPM script from a current path从当前路径运行 NPM 脚本
【发布时间】:2021-05-17 10:44:37
【问题描述】:

我的 node 项目的 package.json 文件中有以下 test 脚本(使用 ts-node 包)

"scripts": {
"build": "tsc",
"test": "ts-node"},

如果我在我的根文件夹中执行它就可以工作

npm run test helloWord.ts

当我在任何其他子文件夹中执行它时它也可以工作(但我需要将整个路径作为参数发送)

npm run test src/samples/helloWord.ts

我的问题是:还有另一种方法可以避免放置整个路径并能够执行 npm run test helloWord.ts?

【问题讨论】:

  • 创建一个批处理脚本怎么样 - 假设您在 Windows 上?在 .bat 文件中设置一次路径,将其保存在桌面上,然后在需要执行时双击它。

标签: javascript node.js typescript npm


【解决方案1】:

在您的脚本中,您必须指定类似

"scripts": {
"build": "tsc",
"test": "ts-node",
"test-hw": "ts-node src/samples/helloWord.ts"},

然后您就可以从文件夹/子文件夹中的任何位置运行脚本npm run test-hw

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 2010-11-14
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    相关资源
    最近更新 更多