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.
To get started, follow these steps:
npm install
or pnpm install
depending on your preferred package manager.npm run dev
or pnpm dev
.http://localhost:3000
to 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
src/widget
directory.src
directory. Useful for development and testing your widget in a Vite app.dist
directory.public
directory.To clone the repository, you can use the following command:
git clone https://github.com/makerkit/react-widget-starter.git
To install the dependencies, you can use the following commands:
npm install
or
pnpm install
To run the development server, you can use the following command:
npm run dev
or
pnpm dev
Once 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:widget
or
pnpm build:widget
This 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:production
or
pnpm build:widget:production
Production mode will use the environment variables from the .env.production
file.
To test the bundled widget, you can use the following command:
npm run serve
or
pnpm serve
This will start a local server and serve the widget at http://localhost:33333/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.