It seems that the app platform always runs the npm install
command when it’s building a component.
Since we compile our assets on our development platform the npm install command is unnecessary.
When the package.json file is removed it doesn’t run this command, but I want to keep this file in our repo.
Is there any reason this command is automatically executed. And is there any way to prevent this?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
There isn’t a directly configurable option that stops
npm install
from running. The most flexible way to customize the build process is to use a Dockerfile which gives you complete control over the build process and the resulting container image.For
npm install
specifically there is a workaround that you can use. If you do not need it at all, you can hijack thepreinstall
script to remove the file completely, like so:If the
STOP_NPM_INSTALL
env var is set to1
, whennpm install
is run thepackage.json
file will “self-destruct” stopping the install process without any errors. Otherwise the process continues as usual.Deleting the whole file is a little crude but it works. You could expand it a bit to run an external script that more carefully only removes the
dependencies
field from the file if you wish.I hope that helps! Out of curiosity, which programming language/build environment does your app use?