Change working directory for npm scripts

前端 未结 2 378
迷失自我
迷失自我 2021-02-02 05:14

Q: Is it possible to change the the context in which npm runs scripts?

What I want to is the following:



        
2条回答
  •  春和景丽
    2021-02-02 05:16

    As noted above:

    npm is probably using

    var spawn = require('child_process').spawn
    

    which would allow you to set options like:

        {cwd: pwd + 'somepath'}
    

    but isn't exposing it.

    I've solved it with a fairly large install.js, which does roughly that and it gets called from package.json like above. The API of child_process isn't that easy to handle, though, since it throws loads of hard to debug errors. Took me some time, but I am happy now.

提交回复
热议问题