This template provides a complete setup for creating a new web component. Follow these steps to get started:
Search and replace the following placeholders throughout the project:
COMPONENT-NAME - Replace with your component’s tag name (e.g., my-awesome-component)ComponentNameElement - Replace with your component’s class name in PascalCase (e.g., MyAwesomeComponentElement)COMPONENT_DESCRIPTION - Replace with a description of your componentFiles to update:
package.jsonREADME.tpl (this will become README.md after setup)COMPONENT-NAME.js (rename this file to match your component name)index.jsdefine.jscustom-elements.jsontest/setup.jstest/COMPONENT-NAME.test.js (rename this file)demo/index.htmlRename the following files to match your component name:
mv COMPONENT-NAME.js your-component-name.js
mv test/COMPONENT-NAME.test.js test/your-component-name.test.js
npm install
Edit your-component-name.js to implement your web component’s functionality. The template provides:
Add tests to test/your-component-name.test.js. The template includes:
custom-elements.json with accurate metadatademo/index.html# Run tests in watch mode
npm test
# Run tests once
npm run test:run
# Run tests with UI
npm run test:ui
# Run tests with coverage
npm run test:coverage
# Lint code
npm run lint
# Format code
npm run format
Delete these template-specific files:
rm SETUP.md
rm README.tpl
rm -rf scripts/
These files are only for template setup and shouldn’t be in your component repository.
package.jsonnpm run test:runnpm run formatnpm run lintcustom-elements.json if needednpm publish
.
├── COMPONENT-NAME.js # Main component implementation
├── index.js # Main entry point (exports class + defines element)
├── define.js # Auto-define script
├── custom-elements.json # Custom Elements Manifest
├── package.json # Package configuration
├── README.md # Documentation
├── LICENSE # MIT License
├── .gitignore # Git ignore rules
├── .npmignore # npm ignore rules
├── .prettierrc # Prettier configuration
├── eslint.config.js # ESLint configuration
├── vitest.config.js # Vitest configuration
├── test/
│ ├── setup.js # Test setup
│ └── COMPONENT-NAME.test.js # Component tests
└── demo/
└── index.html # Demo page