I'd like to replicate webpack's ability to be run from any directory with npm scripts.
For example this works with Webpack
webpack --config /absolute/path/to/webpack.config.js
Is there an equivalent for npm scripts, eg
/absolute/path/to/package.json/npm run build
?
I'm trying to avoid having to cd
in, run the script, then cd
out again.
There does not seem to be any option in npm to specify a folder, so I think you will have to cd into the directory, run your npm command, then cd out again (note that $OLDPWD automatically holds the previous working directory - you don't have to assign it):
cd /path/to/package.json; npm run build; cd $OLDPWD
However, if an error occurs during your npm call, you will be stuck in that directory.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.