Managing the package.json

Set your workspace with the following configurations to manage the package.json properties of every component, in the workspace:

// @filename: workspace.jsonc
{
  "teambit.workspace/variants": {
    "*": {
      "teambit.pkg/pkg": {
        "packageJson": {
          "private": false
        }
      }
    }
  }
}
CopiedCopy

To select a specific component or a group of components, use the component name, instead of the wildcard (*). To learn how to select components, see Configuration variants.

Modifying the 'main' property is not recommended as it might affect other tools and services.

Use the placeholders listed below to inject specific component information into the package.json configuration.

  • {name} - The component's name.
  • {scope} - The component's scope name.
  • {main} - The name of the main file (leaving out the extension) - for example index.js will be index.

Change the package.json properties via an env

Implement the package service handler in your env implementation file (*.bit-env.ts), to override the default package.json properties, for components using that env.

// @filename: my-env.bit-env.ts
// ...
import { PackageGenerator } from '@teambit/pkg';

export class MyEnv extends NodeEnv {
  name = 'my-env';

  package() {
    /**
     * override the default package-generator service
     */
    return PackageGenerator.from({
      /**
       * override the default package.json properties
       */
      packageJson: {
        /* extend the default package.json props */
        ...this.packageJson,
        /* add this property */
        type: 'module',
      },
    });
  }
}

export default new MyEnv();
CopiedCopy