DEV Community

Rickard Natt och Dag
Rickard Natt och Dag

Posted on • Originally published at willcodefor.beer on

ReScript: Adding a third-party library

Sometimes we want to include a library that extends our code. To add a third-party library to our ReScript code we use npm as we would in a JavaScript project, but after installing we need to adjust our ReScript configuration to include the new code.

We start by installing the library using npm or yarn. For this example, I'll be using @opendevtools/rescript-telefonnummer.

npm install --save @opendevtools/rescript-telefonnummer
Enter fullscreen mode Exit fullscreen mode

After the installation is complete we need to add the library name in our bsconfig.json in the bs-dependencies array.

// bsconfig.json
{
  ...
  "bs-dependencies": [
    ...,
    "@opendevtools/rescript-telefonnummer"
  ]
}
Enter fullscreen mode Exit fullscreen mode

After saving, the compiler will pick up that a change has been made in the configuration and build the library. We're now ready to start using the library in our code.

Top comments (0)