有没有办法将$PWD与package.json中的字符串连接起来?
我正在努力:
"config": {
"mypath" : "$(pwd)/assets/dist/js"
}但似乎不起作用。是访问当前工作路径的一种方式吗?
如果我在脚本中使用它就行了。例如:
"scripts": {
"echo" : "echo $(pwd)/assets/dist/js"
}发布于 2017-10-24 19:29:01
不知道确切的用例,但可以在脚本中使用$npm_package_config_path作为参数传递:
"config" : {
"path": "/assets/dist/js"
},
"scripts" : {
"something":"CONFIG_PATH=${PWD}$npm_package_config_path node -e \"console.warn(process.env.CONFIG_PATH)\"",
}
}然后:
$> npm run something
/path/to/your/dir/assets/dist/js发布于 2022-02-21 23:56:52
我不知道您想在哪里使用config.mypath值,但是如果您想在脚本中使用这个值,可以使用以下方法:
在开始之前,我们必须知道: npm使用几个程序来运行脚本。默认情况下,它在gnu/linux中使用bash,在windows中使用cmd (我们可以像在这个question中一样设置shell )。因此,应该创建每个脚本来运行bash或cmd,并且它们通常不是兼容的。
现在让我们开始工作吧
在示例中,config.mypath用于创建两个脚本:
配置:打印config.mypath值
git-克隆:克隆config.mypath文件夹中的存储库
https://stackoverflow.com/questions/46604827
复制相似问题