[英]Quotations being added to combined npm script
I'm attempting to combine 2 npm scripts in one, but when I do the output is incorrect and causes flags to not be passed.我试图将 2 个 npm 脚本合二为一,但是当我这样做时,output 不正确并导致标志无法传递。 Using the dotenv package is not an option and using ampersands is not helping.
使用 dotenv package 不是一个选项,使用&符号也没有帮助。
So in package.json I have this -所以在 package.json 我有这个 -
"define:local": "cross-env NODE_ENV=local FOO=bar BAZ=foo",
"local:dev": "npm run define:local tsnd --inspect --respawn path/to/mycode.ts",
When I run npm run local
the output in the terminal is cross-env NODE_ENV=local FOO=bar BAZ=foo "tsnd" "path/to/mycode.ts"
which means it is dropping the flags being passed to tsnd and causing local development issues.当我运行
npm run local
时,终端中的 output 是cross-env NODE_ENV=local FOO=bar BAZ=foo "tsnd" "path/to/mycode.ts"
这意味着它正在丢弃传递给 tsnd 的标志并导致本地发展问题。 It's also putting quotes around the tsnd command and file path for some reason.出于某种原因,它还在 tsnd 命令和文件路径周围加上引号。
If, however local:dev
is run without "define:local" (eg tsnd --inspect --respawn path/to/mycode.ts
the output is tsnd --inspect --respawn path/to/mycode.ts
without quotes as expected and flags are included.但是,如果
local:dev
在没有“define:local”的情况下运行(例如tsnd --inspect --respawn path/to/mycode.ts
output 是tsnd --inspect --respawn path/to/mycode.ts
没有引号作为包括预期和标志。
Furthermore, If I try to use ampersands in the command to combine the 2, the cross-env command no longer works and the environment variables are not defined.此外,如果我尝试在命令中使用 & 符号来组合 2,则 cross-env 命令不再有效,并且未定义环境变量。
How can I combine these 2 scripts and keep the flags and environment variables in tact?我怎样才能结合这两个脚本并保持标志和环境变量的完整性?
You need --
to tell npm to pass the args to the command, instead of passing them to npm run
:您需要
--
告诉 npm 将参数传递给命令,而不是将它们传递给npm run
:
"define:local": "cross-env NODE_ENV=local FOO=bar BAZ=foo",
"local:dev": "npm run define:local -- tsnd --inspect --respawn path/to/mycode.ts",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.