This repository contains a collection of framework-agnostic web components designed for reuse across multiple projects. This guide outlines the process for developing and adding new components to the library.
Before you begin, please ensure you have the following installed on your system:
- Node.js (v18 or later recommended)
-
pnpm (or your preferred Node.js package manager like
npm
oryarn
)
To install the project dependencies, run the following command from the root directory:
pnpm install
- /src: Contains the source code for each component (e.g., TypeScript/TSX, CSS files). Each component should reside in its own dedicated folder.
-
/wcs: Contains manifest files (
.wc
) that define and register each web component. This is how our build system discovers and configures them.
Follow these steps to create a new, production-ready web component.
First, create a new directory inside /src
for your component. It's best practice to name the folder after the component itself.
For example, to create a new my-button
component:
- Create a new folder:
src/my-button
- Add your source files inside it, for example:
src/my-button/my-button.tsx
andsrc/my-button/my-button/module.css
.
Next, you need to create a manifest file in the /wcs
directory to register your component with our build system.
-
Create a new file in the
/wcs
folder. The filename must follow the conventioncomponent-name.wc
.- Example:
wcs/my-button.wc
- Example:
-
Add the following JSON content to the file, customizing it for your component:
{
"tag": "my-button",
"component": "src/my-button/my-button.tsx",
"attrs": ["label", "variant", "disabled"]
}
Manifest Fields Explained:
-
"tag"
: The custom HTML tag name for your component. By web component standards, this must contain a hyphen. -
"component"
: The path from the project root to your main component source file. -
"attrs"
: An array of attribute names that your component will observe. When these attributes change on the HTML tag, your component will be notified.
To make your component available for development tools like Storybook and for proper module resolution, you must add an entry to the exports
field in the root package.json
file.
-
Open
package.json
. -
Add a new key-value pair to the
exports
object.```json // package.json { // ... other package.json content "exports": { // ... other existing exports "./my-button": "./src/my-button/my-button.tsx" } } ```
This creates a clean, predictable import path for your component's source code.
Storybook is integrated into this project to allow for isolated development and testing of components.
- (Optional but Recommended) Create a story for your component. Add a new file in the
<root>/apps/stories
directory, such asstories/my-button.stories.ts
.
Of course. Here is a rewritten version of that section, designed to be more informative, clear, and provide step-by-step guidance for any developer.
This guide outlines the process for publishing a new version of the @aibots-public/web-components
package to the public NPM registry.
Before you can publish a new version, please ensure you have the following:
- An NPM Account: You must have an active account on npmjs.com.
-
Required Permissions: Your NPM account must have write access to the
@aibots-public
organization. -
NPM Authentication: You need to be logged into your NPM account on your local machine. If you are not logged in, run this command and follow the prompts:
npm login
This step kicks off an interactive command-line process that helps you select which component(s) to include in the release, choose the new version number (following SemVer conventions), and generate changelogs.
- From the root folder of the project, run the prepare script:
pnpm publish:prepare
- Follow the on-screen prompts. You will be asked to select the specific web component(s) you intend to release and choose whether this is a
patch
,minor
, ormajor
version update.
This command will update the package.json
version and stage the necessary files for the next step.
After the preparation step is complete, run the following command. This script will handle the final build process for the selected components and upload the new package version to the NPM registry.
pnpm publish:run
Wait for the script to complete. You should see a success message indicating that the package has been published.
Once the publish script finishes, it's important to verify that the new version is publicly available.
-
Check the NPM Registry: Visit the package's official page on NPM and confirm that the new version number is listed.
-
Check the unpkg CDN: You can also verify that the distributable files are accessible via the
unpkg
CDN. Replace<version>
with the version you just published (e.g.,3.1.0
).https://unpkg.com/@aibots-public/web-components@<version>/dist/live-chat.widget.global.js
For example, for version
3.1.0
, the link would be:If you can access this URL, your package has been successfully published and is available on the CDN.
- Modify the
public/index.html
file to include your latest web component - Run
pnpm start:test:server