PKG
Check out the Pkg Aspect on Bit.dev
Bit components can be thought of as a super-set of standard packaged node modules. Each component contains a consumable package in addition to its documentation, history and other information that enables it to be independently developed and maintained.
The PKG aspect handles the configuration, publishing and packing of component packages. It adds its own build task to the build pipeline, to create component packages and include them in as part of the component artifacts. This automation includes generating the package name and other properties according to the component's details.
Features#
- Efficient
package.jsonconfiguration: Use the PKG's workspace config API to add or overridepackage.jsonproperties to a group of components, all at once. Use PKG's 'placeholders' to integrate component-specific data into the component's package configurations. - An API for programmable
package.jsonconfiguration: Use PKG's API to provide your extensions with "packaging capabilities". Modify thepackage.jsonto suit your extension's needs, whether it is an environment or any other type of extension. - Automated packing and publishing: - PKG is registered to your build pipeline. That means every 'build' will also test 'packing' and every tagging of a new release version will also include 'publishing'. Your components and packages versions are alway in-sync.
- "On-demand" packing and publishing: - PKG offers the
packandpreviewCLI commands for a manual and on-demand usage.
Quickstart & configuration#
This aspect is only configurable using the 'variants' workspace API.
Package properties#
Use the packageJson property to add or override the default package.json for your component packages.
Warning! Packages with a modified
nameproperty will not be published to Bit.dev's registry.
{ "ui/*": { "teambit.pkg/pkg": { "packageJson": { "name": "@{scope}/{name}", "private": false, "main": "dist/{main}.js", "custom-prop": "value" } } }}Publish#
If
publishConfigornameare not set, packages will be published to Bit.dev's registry.
npm arguments#
You can specify additional arguments to the npm publish command by adding an array of args to packageManagerPublishArgs.
For example:
"ui/*": { "teambit.pkg/pkg": { "packageManagerPublishArgs": ["--access public"] }}npmjs Registry#
- Use the
nameproperty to set the publishing process to your npm scope. - Use the
private(boolean) property to set packages to be published with either private or public access.
{ "ui/*": { "teambit.pkg/pkg": { "packageJson": { "name": "@{scope}/{name}", "private": false, } } }}Private registry#
Use the scope and registry properties to configure the publishing process to your own private registry (and scope).
"ui/*": { "teambit.pkg/pkg": { "packageJson": { "publishConfig": { "scope": "@custom", "registry": "http://localhost:4873" } } }}Packages with a modified
publishConfigproperty will not be published to Bit.dev's registry.
Placeholders#
Placeholders are an easy way to inject component-specific information into the 'pkg' configurations.
{name}- The name of the component.{scope}- The name of the component scope.{main}- the name of the main file (leaving out the extension) - for exampleindex.jswill beindex.
For example:
"packageJson": { "main": "dist/{main}.js" }CLI Reference#
Pack#
Creates a TAR file (to be published to a node package registry):
bit pack <component-id>Overrides the existing TAR file (in the same location):
bit pack <component-id> --override
bit pack <component-id> -oReturns the output in a JSON format:
bit pack <component-id> --json
bit pack <component-id> -jPublish#
Publishes an exported component:
bit publish <componentId>Publishes a staged component that has not yet been exported:
bit publish <component-id> --allow-stagedChecks if the publishing process will be done successfully (without publishing):
bit publish <component-id> --dry-run
bit publish <component-id> -dReturns the output as JSON:
bit publish <component-id> --json
bit publish <component-id> --j