如何指定‘ package.json’到 npm 的路径?

我使用 npm脚本来构建我的项目。我希望能够从不同的目录运行脚本。也就是说,不要做以下事情:

cd project;
npm run build;
cd ..

我想简单地做一些事情,比如:

npm run build -config project/package.json;

或者

npm run build -wd project;

这可能吗?

108618 次浏览

Using --prefix worked for me:

npm --prefix /path/to/project run build

Where path/to/project is the directory where your package.json with build command defined.

to change the path of package.json that npm gets this didnt work for me

npm --prefix /path/to/project run build

but this did

npm --prefix /path/to/project run

but this does not permanently change it for example you can say

npm --prefix /path/to/project run test