Skip to content

A React template for creating well-tested and multilingual extensions for the Blip platform

Notifications You must be signed in to change notification settings

heloineto/blip-extension-template

Repository files navigation

Blip logo

Blip Extension Template

Scaffold extensions for the Blip platform

Installation

To start your extension using this template, run the command below:

npm create blip-extension@latest

Then follow the prompts!

See create-blip-extension for more details on supported templates.

If for some reason the command above doesn't work, simply cloning this repository should suffice.

Tech Stack

  • React
  • TypeScript or JavaScript
  • Tailwind CSS
  • Blip Design System
  • Iframe Message Proxy
  • ESLint, Prettier & CSpell
  • Husky with lint-staged and commitlint
  • i18next
  • Cypress

Note: Although recommended, you don't have use this template to create Blip extensions. You can use any stack as long as you can render your web app as an iframe in the Blip portal.

How to create your Blip extension

In this section, you will learn how to set up and develop a Blip extension.

This guide assumes that you have basic knowledge of JavaScript and React concepts, and know how to use the Blip platform.

What exactly is a Blip extension?

In technical terms, A blip extension is simply a web application viewed as an iframe inside the Blip platform. It can do everything a web app can, and also communicate with the main platform though the iframe-message-proxy API.

Step 1: Setup

Begin by scaffolding your project following the instructions on the installation section.

After running the development server, you will be able to see the extension running on http://localhost:3000/.

Step 2: Running the extension inside Blip

To be able to communicate with the main platform, your extension must be running inside the Blip platform. Due to company policy, I can't show you how to do it here, so if you are interested in learning how to do this, please reach out.

Step 3: Using the Blip APIs

The Blip platform provide multiple API endpoints that allow you to communicate with the main platform.

See the utility functions inside src/lib/iframe-messages to get an idea of how that looks like.

You can look how to do a specific thing on the Blip Documentation.

As I understand, not everything is fully documented. If you can't find what you want to do in the documentation, I would recommend asking around in the Blip forum.

Step 4: Using other APIs

As a web application, you can use any API you want, or develop your own.

Simply make HTTP requests inside your extension. See how to do this in React.

Step 5: CI/CD

This template comes with a CI/CD pipeline already set up for Azure DevOps. You can see it in azure-pipelines.yml. However, this pipeline is specific to my organization (Blip), and uses internal templates.

If you are not part of Blip, you can use this pipeline as a reference to create your own.

These files are related to the pipeline, and can be removed if you are not using it:

- azure-pipelines.yml
- Dockerfile
- charts/*

Step 5: Testing

The old template used Jest and RTL (React Testing Library), however, there were some issues with it, that would make tests very painful to write:

  • JSDOM doesn't support web components (widely used by Blip Design System)
  • RTL doesn't actually render the component, it only renders a representation of it. This causes a lot ot problems and the need to constantly mock things.

To fix this issue, I decided to switch over to Cypress. Cypress is way more powerful, and alongside of solving the problems mentioned above, it also:

  • Allows for better coverage (It actually renders the component)
  • Visual testing (so you can see if your component is rendering correctly)
  • Easier and more intuitive API

Step 5: Develop!

Now it's up to you. Build what you want to, and don't forget to submit it to the Blip Store once it's done. Happy coding!

How to re-create this template

To have an up-to-date project, verify when this template was last updated. If you believe it was too long ago, consider recreating it following (and changing if necessary) the steps below.

  1. Create a new React project using Vite. When prompted, choose React with TypeScript + SWC or JavaScript + SWC. Instructions here.

  2. Install Blip Design System. Instructions here.

    2.1. Add optimizeDeps: { exclude: ['blip-ds/loader'] } to ./vite.config.ts. This is a workaround to make blip-ds work with Vite. See issue

  3. Install Tailwind. Instructions here.

  4. Install the Nunito Sans font using Fontsource. Instructions here.

    4.1. Choose which font weights & styles to use, to cut down on payload sizes. See configuration.

    4.2. Set it as the default font with Tailwind CSS. Instructions here.

  5. Install Prettier. Instructions here.

    5.1. Configure Prettier. See configuration.

  6. Install ESLint. Instructions here.

    6.1. Integrate Prettier with ESlint. Instructions here.

    6.2. Integrate Tailwind CSS with ESLint. Instructions here.

    6.3. Configure ESLint. See configuration.

  7. Configure Git hooks

    7.1. Install husky. Instructions here.

    7.2. Install lint-staged. Instructions here.

    7.3. Install commitlint. Instructions here.

  8. Configure VScode settings

    8.1. Configure settings. See configuration.

    8.2. Configure extensions. See configuration.

  9. Install CSpell. Instructions here.

    9.1. Add CSpell's Brazilian Portuguese Dictionary. Instructions here.

    9.2. Add CSpell's Spanish Dictionary. Instructions here.

    9.3. Configure CSpell. See configuration.

  10. Install i18next. Instructions here.

    10.1. Add type safety. Instructions here.

  11. Install React Router Dom Instructions here.

  12. Install Testing Libraries. Instructions here.

    12.1. Install Vitest. Instructions here.

    12.2. Install Cypress. Instructions here.

  13. Install the iframe-message-proxy package

    13.1. If using TypeScript, add package's types See definitions.

    13.2. Create iframe-message-proxy helper functions (src/lib/iframe-messages)

  14. Finishing touches

    14.1. Set the website title to "Blip Extension".

    14.2. Set the website favicon. See favicon.

    14.3. Install tailwind-blip-ds. Instructions here.

    14.5. Add blip language detector. See code.

Note: To keep the project's root folder clean, transform the configuration files with few lines into keys on package.json. Example: The file .lint-staged.config.cjs can be a lint-staged key on package.json.