Tuesday 26 November 2019

NPM - alternative install directory (node_modules)

I am currently stuck with a problem: I am creating a build task (using Grunt), and got a task that builds the product into a dist/ directory. I therefore want to run npm install --only=production in that directory, in order to strip off "junk" not needed in node_modules.What I have tried:Using an npm-command in Gruntfile, with this config:'npm-command': {npmInstallDist: {cwd: "./dist/",cmd: "install",args: ["--only=production"]}},This does not work, it seems like it ignores the cwd completely, and do the work in the root node_modules folder.I then tried to add a script in package.json:"scripts": {"buildDist": "cd dist && npm install --only=production"}This does not work either, not sure exactly why. It still remains in the root directory when installing.So, I'm stuck. The only solutions I can see from the top of my head, is eitherCreate an install.js, that uses node chdir() and spawn() or similarCreate a function in Gruntfile that does the same

Submitted November 26, 2019 at 11:32AM by oyvindi

No comments:

Post a Comment