This is a starter template for creating embeddable widgets with React by MakerKit.
To learn more about how we created this template, check out our blog post.
- 🛡️ Fully Isolated - Shadow DOM encapsulation prevents style conflicts
- 🚀 Modern Stack - Built with React 19, TypeScript, and Vite
- 🔌 Simple Integration - Single line of code to embed
- 🛠️ Developer Experience - Hot reload, TypeScript, and modern tooling
To get started, follow these steps:
- Clone this repository to your local machine.
- Install the dependencies by running
npm installorpnpm installdepending on your preferred package manager. - Run the development server by running
npm run devorpnpm dev. - Open your browser and navigate to
http://localhost:3000to see the widget in action.
The project is structured as follows:
.
├── dist/ # Output directory for the widget
├── public/ # Public assets for the widget
├── src/ # Source code for the widget
│ ├── App.css # CSS file for the development Vite app
│ ├── App.tsx # Entry point for the development Vite app
│ ├── widget/ # Source code for the widget
│ │ ├── components/ # Components for the widget
│ │ ├── lib/ # Utility functions for the widget
│ │ ├── index.tsx # Entry point for the widget
│ │ └── styles/ # CSS styles for the widget
- Widget code: The source code for the widget is located in the
src/widgetdirectory. - Development app code: The source code for the development app is located in the
srcdirectory. Useful for development and testing your widget in a Vite app. - Widget distribution: The widget is bundled into the
distdirectory. - Public assets: Public assets like images, fonts, and CSS files are located in the
publicdirectory.
To clone the repository, you can use the following command:
git clone https://github.com/makerkit/react-embeddable-widget.gitTo install the dependencies, you can use the following commands:
npm installor
pnpm installTo run the development server, you can use the following command:
npm run devor
pnpm devOnce the development server is running, you can open your browser and navigate to http://localhost:3000 to see the widget in action.
To bundle the widget, you can use the following command:
npm run build:widgetor
pnpm build:widgetThis will create a dist directory with the bundled widget files.
For running the widget in production mode, you can use the following command:
npm run build:widget:productionor
pnpm build:widget:productionProduction mode will use the environment variables from the .env.production file.
To test the bundled widget, you can use the following command:
npm run serveor
pnpm serveThis will start a local server and serve the widget at http://localhost:3333/index.html.
Depending on which provider you want to use, you can deploy the widget to a CDN, or simply host it on your own server.
Copy the bundled files from the dist directory to your server and have the consumers of the widget use the script tags to load the widget.
If your widget is hosted on a CDN, you can use the following script tag:
<script async src="https://example.com/widget.js"></script>We welcome contributions to this project. If you find a bug or have a suggestion for improvement, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more information.
Makerkit is a SaaS Starter Kit for building a production-ready SaaS application. Check it out for more information.