Dev environment configuration (env.jsonc)

The env.jsonc file controls the configuration for your component development environments and their peer dependencies.

Peer dependencies

Peer dependencies are dependencies that are expected to be included once in the development environment and the consuming applications.

// @filename: env.jsonc
{
  "policy": {
    "peer": [
      {
        "name": "react",
        /* the version to be installed and used by the env */
        "version": "^18.0.0",
        /* the range of versions this env's components are compatible with */
        "supportedRange": "^17.0.0 || ^18.0.0"
      },
      {
        "name": "react-dom",
        "version": "^18.0.0",
        "supportedRange": "^17.0.0 || ^18.0.0"
      },
      {
        "name": "@types/react",
        "version": "^18.0.0",
        "supportedRange": "^18.0.0"
      }
    ]
  }
}
CopiedCopy

Define your peers using the following properties:

  • name. Package name of the peer dependency.
  • version. The version of the dependency to be installed in the development environment.
  • supportedRange: A semver range specifying compatible versions for your components. This helps prevent version conflicts across your projects.

If your components use the react package, Bit will automatically define it as a peer dependency. You can verify this by running bit show <component-id> to inspect the component's dependencies and ensure your env.jsonc configuration aligns with the desired React version for your project.

Control component dependencies

You can use env.jsonc to control component dependencies in a graunlar level, and set the env to force specific runtime or dev dependencies to its components.

// @filename: env.jsonc
{
  "policy": {
    "runtime": [
      {
        "name": "classnames",
        "version": "^2.0.0",
        "force": true
      }
    ],
    "dev": [
      {
        "name": "@my-org.design/themes/my-theme",
        "version": "-",
        "force": true
      }
    ]
  }
}
CopiedCopy

Use the following proeprties to control dev and runtime dependencies of your dev environment:

  • name. Package name of the peer dependency.
  • version. The version of the dependency to be installed in the development environment.
  • force (optional): Determines whether the dependency is forced to all components.

The example above, sets the classnames dependency to all env components and ensures they do not use the @my-org.design/themes/my-theme component.

Development file types

Component files can be defined as dev files (as opposed to "runtime" or "production"), and can be configured to be loaded by a specific dev service.

For example:

{
  "patterns": {
    /**
     * a glob pattern for files to be loaded and previewed
     * */
    "compositions": ["**/*.composition.*", "**/*.preview.*"],
    /**
     * a glob pattern for files to be loaded and displayed as docs
     * */
    "docs": ["**/*.docs.*"],
    /**
     * a glob pattern for files to be loaded and executed as tests
     * (by whichever test runner is configured for the env)
     * */
    "tests": ["**/*.spec.*", "**/*.test.*"],
    /**
     * a glob pattern for files to be loaded by no specific dev service
     * but to be considered as dev files (replace "my-dev-files" with whatever name you want)
     * */
    "my-dev-files": ["**/*.dev.*"]
  }
}
CopiedCopy

Note that every file handled by a dev service is considered as a dev file.

See the section below to learn about alternative dependency configurations:

workspace.jsonc

The workspace dependency policy, configured in the workspace.jsonc file, is the default policy for all components in a workspace. It is applied on all components that use the relevant dependency, and is overridden by more specific policies.

The workspace policy is mostly automated. Dependency versions are resolved to the ones installed in the node_modules directory.

To install new dependencies see Dependency installation
To change the semver range of an existing dependency, see Dependency policies