I have an NPM project, when npm install
is run, I'd like to run a custom script.
I tried using this in package.json:
"scripts": {
"ng": "ng",
"start": "ng serve",
"install": "./scripts/install.sh", // <<<<
},
but that actually just resulted in an infinite loop.
The reason I am looking for this, is because there are tools that simply call npm install
, so I can't control what they run. Otherwise, if I had control, I would just call ./scripts/install.sh
myself instead.
Note that this is probably not the best idea, just curious if it's possible.
Note my install script looks something like this:
#!/usr/bin/env bash
export FOO="bar";
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true";
npm install
NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.
With NPM we also have other options for specifying the version of a package. Using either a caret ( ^ ) or a tilde ( ~ ) we can specify the latest minor or patch version, respectively. This way you can specify a compatible package version, but still get the latest.
You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.
Use preinstall
to run code before npm install
. Don't try to override npm install
in this fashion where you would end up with an infinite loop of calls to npm install
.
You can also set environment variables using the config
property of package.json
. See docs for details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With