Wednesday, October 2, 2019

Dependency setting in package.json for angular library project and app project

dependencies:
dependencies node defined in package.json will be installed in application's node_modules folder, and used by the library and application project at runtime. There is no difference between library project and application project.

devDependencies:
modules specified in devDependencies is mostly used for compiling and building the library project, so only developers of the app or library need them. For library project, the devDependencies node should only exist in root application's package.json, and should not exist in library project's package.json, so that those information will not be exposed to the library's output package.json, as users of the library do not need to know or care about those modules.

peerDependencies:
peerDependencies node is mostly used by library projects, the packages specified in peerDependencies will not be installed when running "npm package" on the library project, the information specified in peerDependencies node only indicates which version of dependencies packages are required by the library project at runtime, and the host application's package.json must include the related packages with compatible versions, otherwise an error will be reported for missing the required peerDependent packages.

whitelistedNonPeerDependencies:
To avoid developers to add a package in dependencies section by accident, (instead of adding it into peerDependencies section), angular build will fail by default if it finds a such package.
If developers are certain a dependent package should be added into dependencies section instead of peerDependencies section, then developers need to explicitly add the package into ng-package.json's whitelistNonPeerDependencies section to avoid the build failure. Adding a package in whitelistedNonPeerDependencies indicates the developers are certain that a separate copy of the package should be loaded only for the current library.







No comments:

Post a Comment