Is there a way to chain Envs in Bit?

62 Views Asked by At

I currently have a React environment built: https://bit.cloud/enlear/dev/envs/react It uses the following dependencies:

{
  /**
   * standardize your component dependencies.
   * @see https://bit.dev/docs/react-env/dependencies
   **/
  "policy": {
    /**
     * peer dependencies for components using that env.
     */
    "peers": [
      {
        "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": "jest",
        "version": "29.3.1",
        "supportedRange": "29.3.1"
      },
      {
        "name": "react-router-dom",
        "version": "6.8.1",
        "supportedRange": "^6.8.1"
      },
      {
        "name": "@mdx-js/react",
        "version": "1.6.22",
        "supportedRange": "^1.6.22"
      },
      {
        "name": "@teambit/mdx.ui.mdx-scope-context",
        "version": "1.0.0",
        "supportedRange": "^1.0.0"
      },
      {
        "name": "@emotion/styled",
        "version": "^11.11.0",
        "supportedRange": "^11.11.0"
      },
      {
        "name": "@emotion/styled",
        "version": "^11.11.0",
        "supportedRange": "^11.11.0"
      },
      {
        "name": "@emotion/react",
        "version": "^11.11.0",
        "supportedRange": "^11.11.0"
      },
      {
        "name": "@mui/material",
        "version": "^5.14.13",
        "supportedRange": "^5.14.13"
      }
    ],
    /**
     * dev dependencies for components using that env
     */
    "dev": [
      {
        "name": "@types/react",
        "version": "18.2.12",
        /**
         * hide the dependency from bit's inspection tools.
         * in most cases, a component should only list its env as a dev dependency
         */
        "hidden": true,
        /* add this dependency to components, even if they don't explicitly import it */
        "force": true
      },
      {
        "name": "@types/react-dom",
        "version": "^18.2.5",
        "hidden": true,
        "force": true
      },
      {
        "name": "@types/jest",
        "version": "^29.2.2",
        "hidden": true,
        "force": true
      },
      {
        "name": "@testing-library/react",
        "version": "^13.4.0"
      },
      {
        "name": "@types/testing-library__jest-dom",
        "version": "^5.9.5",
        "force": true
      },
      {
        "name": "@testing-library/react-hooks",
        "version": "^8.0.1"
      }
    ]
  },
  /**
   * associate files with a specific dev service.
   * associated files are considered as dev files.
   * @see https://bit.dev/docs/react-env/dependencies#configure-files-as-dev-files
   **/
  "patterns": {
    /**
     * files to be loaded and displayed in the 'preview' tab.
     * @see https://bit.dev/docs/react-env/component-previews
     */
    "compositions": [
      "**/*.composition.*",
      "**/*.preview.*"
    ],
    /**
     * files to be loaded and displayed in the 'overview' tab.
     * @see https://bit.dev/docs/react-env/component-docs
     */
    "docs": [
      "**/*.docs.*"
    ],
    /* files to be included in the component testing */
    "tests": [
      "**/*.spec.*",
      "**/*.test.*"
    ]
  }
}

My use case is as follows:

I want to create components that use the React env that I created. This is pretty straight forward with the bit envs set command. But there is this one component that I am using that uses a package that I don't necessarily want to include in my env component as it is only being used in one component.

Is there a way I can create a second React env that only uses this external library and chain it with the already existing React env of mine? Or is there any recommended best practise for this approach?

Currently, I included the single library in my custom React env. But this does not feel necessary as I don't want the library in every component I use my Env with.

1

There are 1 best solutions below

0
On

Please see my answer for this question, which is essentially the same scenario:

Installing dependencies for a Bit component that uses an env