【问题标题】:How to pass dynamic file name in npm run command如何在 npm run 命令中传递动态文件名
【发布时间】:2021-05-18 04:46:37
【问题描述】:

我想 npm 运行一个命令,根据我在命令行中传递的文件名生成一个动态输出文件。但我无法从以下命令生成它

在脚本的 package.json 中,我添加了命令:

scripts:{
"gen-out":"some_cmd src/app/parser/$npm_config_filene.st -o src/app/parser/$npm_config_filene.j"
}

运行后

npm run gen-out --filene=myfile 

它会生成一个名为 $npm_config_filene.js 而不是 myfile.js 的文件

有人可以帮忙吗?

【问题讨论】:

  • 您可能在 Windows 上运行此命令,在这种情况下,npm 使用 cmd 作为运行 npm 脚本的默认 shell。 cmd 中的变量使用 %...% 表示法引用(与 *nix 上的 sh 不同,它使用美元 ($) 前缀)。如果您使用的是 Windows,请尝试使用 %...% 在您的 npm 脚本中封装 npm_config_filene 变量。例如:"gen-out":"some_cmd src/app/parser/%npm_config_filene%.st -o src/app/parser/%npm_config_filene%.js"
  • 感谢它的工作

标签: npm command-line


【解决方案1】:

windows 平台使用这种格式:

scripts:{
"gen-out":"some_cmd src/app/parser/%npm_config_filene%.st -o src/app/parser/%npm_config_filene%.j"
}

npm run gen-out --filene=myfile 

【讨论】:

    猜你喜欢
    • 2017-01-12
    • 2015-11-14
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 2021-02-12
    • 2017-05-07
    相关资源
    最近更新 更多