I need to replace a file from dependency, located in "node_modules". It is not a good practice to amend node_modules directly, as it will be overwritten with next "npm install". How can I replace such file without touching "node_modules"? For example we can do it with typings. But what about other files?
In my case I want to replace "foo.component.less" and "foo.component.metadata.json" files. Just creating new files in host doesn't help as it would overwrite access to css, but not metadata.
You can edit the file directly, but this would be overwritten whenever npm updates, the best thing to do is go straight to the source.
You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.
The directory node_modules/.bin is where the binaries of the modules used by your project are stored, normally using symbolic links to the respective binaries in the corresponding module's directory.
Optimal, but long solution: to create copy/fork of the package's source code:
readme.md
file not to miss in future upgrades.If we don't require to update files and structure entirely, it can be enough to place overriding files to the root of the project(as for Angular
). For example such css
file would override the same one in node_modules
:
npm
will look it first.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