预安装脚本如何设置npmconfiguration到当前目录?

我试图设置用户正在安装的当前目录到一个npmconfigurationvariables,以便我可以在我的安装脚本中引用此。

有什么办法,我可以通过命令行来做,或者我将不得不写一个脚本来做到这一点?

"scripts": { "preinstall": "npm config set base_path CURRENT_PATH_HERE?" ... 

这取决于你用来运行你的npm install命令的环境。 如果你使用bash shell,那么你可以使用

“preinstall”:“npm config set base_path $(pwd)”

而在DOS shell中,您可以使用:

“preinstall”:“npm config set base_path%cd%”

包脚本只是“传递”到shell然后执行,所以你必须弄清楚如何将path作为一个variables。