CircleHq Email Builder component
npm install @circlehq/email-builderThis guide explains how to set up, build, and publish a React package to npm using Babel.
Make sure you have the following installed:
- Node.js
- npm
- Babel
Start by creating a package.json file for your project if you don't have one already:.
1. Prepare Your Package
Before publishing, ensure you have a package.json file in the root of your project. You can create one by running:
``bash`
npm init
This will prompt you for information such as the package name, version, and entry point. Make sure to fill it out correctly.
- For a public package, use a unique name, e.g., your-package-name.@your-org/your-package-name
- For an organization package, use a scoped name, e.g., .
If you are using TypeScript, Babel, or another compiler, add a build script in your package.json:
` json`
"scripts": {
"build": "your-build-command",
"prepublishOnly": "npm run build"
}
This ensures that your package is built before publishing.
Create a .npmignore file to exclude unnecessary files from your published package. Common exclusions include:
`bash`
/node_modules
/tests
/src
/*.log
This prevents unnecessary files from being included in the npm package.
If you are not already logged in, log in to npm using:
`bash`
npm login
You'll be prompted for your npm username, password, and email.
To publish your package to npm, run:
`bash`
npm publish
For scoped packages (e.g., @your-org/your-package-name), you must specify public access:
`bash`
npm publish --access public
To update and publish a new version of your package:
1. Update the version in package.json (e.g., from 1.0.0 to 1.0.1).
2. Run the build script, if necessary:
`bash`
npm run build
3. Publish the updated package:
`bash`
npm publish
For scoped packages (e.g., @your-org/your-package-name), you must specify public access:
`bash`
npm publish --access public
You can verify that your package was published successfully by checking it on the npm website:
`bash`
npm info your-package-name
Or visit npmjs.com and search for your package.
By following these steps, you will successfully publish your package to npm.
Increment the version in package.json.
Rebuild the package:
`bash`
npm run build
Publish the updated package:
`bash``
npm publish