web-component-starter

Web Component Starter - Setup Instructions

This template provides a complete setup for creating a new web component. Follow these steps to get started:

1. Replace Placeholders

Search and replace the following placeholders throughout the project:

Files to update:

2. Rename Files

Rename 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

3. Install Dependencies

npm install

4. Implement Your Component

Edit your-component-name.js to implement your web component’s functionality. The template provides:

5. Write Tests

Add tests to test/your-component-name.test.js. The template includes:

6. Update Documentation

7. Development Commands

# 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

8. Clean Up Template Files

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.

9. Before Publishing

  1. Update the version in package.json
  2. Ensure all tests pass: npm run test:run
  3. Ensure code is formatted: npm run format
  4. Ensure code passes linting: npm run lint
  5. Test the demo locally
  6. Update custom-elements.json if needed

10. Publishing to npm

npm publish

Project Structure (After Cleanup)

.
├── 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

Tips