OS independent access to variables in package.json
问题 To access a variable in npm scripts you would do something like this in your package.json : "scripts": { "preinstall": "echo ${npm_package_name}" } The problem is that works only in Unix, not Windows, where you have to use %npm_package_name% . Is there a way to do this OS independent? It will be good if npm could do such a variable expansion, before invoking the command. 回答1: To make it cross-platform, use cross-var: "scripts": { "preinstall": "cross-var echo ${npm_package_name}" } 回答2: There