Installation
Get started with @rhtml by setting up your development environment and creating your first project.
Prerequisitesโ
Before you begin, make sure you have the following installed:
- Node.js (v18.0.0 or higher)
- npm (v8.0.0 or higher) or yarn
- Git (for cloning starter templates)
๐ Quick Start Optionsโ
Option 1: Frontend Developmentโ
For frontend applications, use the official starter template:
# Clone the frontend starter
git clone https://github.com/rxdi/starter-client-side-lit-html my-app
cd my-app
# Install dependencies
npm install
# Start development server
npm start
Option 2: Backend Developmentโ
For backend applications, use the Fastify starter template:
# Clone the backend starter
git clone https://github.com/r-html/fastify-starter my-backend
cd my-backend
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Start development server
npm start
Option 3: Manual Setupโ
If you prefer to start from scratch:
# Create a new directory
mkdir my-rhtml-project
cd my-rhtml-project
# Initialize package.json
npm init -y
# Install core dependencies
npm install @rhtml/component @rxdi/lit-html @rhtml/di rxjs
npm install --save-dev typescript @types/node
๐ฆ Package Installationโ
Core Frontend Packagesโ
# Component system
npm install @rhtml/component @rxdi/lit-html
# Reactive programming
npm install rxjs
# Dependency injection
npm install @rhtml/di
# Additional frontend packages
npm install @rhtml/operators @rhtml/decorators @rhtml/hooks
Backend Packagesโ
# Fastify integration
npm install @rhtml/fastify fastify
# Database integration
npm install @rhtml/mongoose mongoose
# Message queue
npm install @rhtml/amqp amqplib
# GraphQL support
npm install @rhtml/graphql graphql
Development Toolsโ
# TypeScript
npm install --save-dev typescript @types/node
# Build tools
npm install --save-dev webpack webpack-cli webpack-dev-server
# Testing
npm install --save-dev jest @types/jest
# Code quality
npm install --save-dev eslint prettier
โ๏ธ Configurationโ
TypeScript Configurationโ
Create a tsconfig.json
file:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Environment Variablesโ
For backend projects, create a .env
file:
# Server Configuration
PORT=3000
NODE_ENV=development
# Database Configuration
MONGODB_URI=mongodb://localhost:27017/myapp
# AMQP Configuration
AMQP_URL=amqp://localhost
# GraphQL Configuration
GRAPHQL_ENDPOINT=/graphql
๐๏ธ Project Structureโ
Frontend Project Structureโ
my-app/
โโโ src/
โ โโโ components/
โ โ โโโ app.component.ts
โ โ โโโ user.component.ts
โ โโโ services/
โ โ โโโ user.service.ts
โ โโโ styles/
โ โ โโโ global.css
โ โโโ main.ts
โโโ public/
โ โโโ index.html
โโโ package.json
โโโ tsconfig.json
โโโ webpack.config.js
Backend Project Structureโ
my-backend/
โโโ src/
โ โโโ controllers/
โ โ โโโ user.controller.ts
โ โโโ services/
โ โ โโโ user.service.ts
โ โโโ modules/
โ โ โโโ app.module.ts
โ โโโ models/
โ โ โโโ user.model.ts
โ โโโ main.ts
โโโ tests/
โโโ .env
โโโ package.json
โโโ tsconfig.json
๐ Development Scriptsโ
Add these scripts to your package.json
:
{
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production",
"test": "jest",
"lint": "eslint src/**/*.ts",
"format": "prettier --write src/**/*.ts"
}
}
๐ง IDE Setupโ
VS Code Extensionsโ
Install these recommended extensions:
- TypeScript and JavaScript Language Features
- ESLint
- Prettier
- LitElement Language Support
- Web Components
VS Code Settingsโ
Add to your .vscode/settings.json
:
{
"typescript.preferences.importModuleSpecifier": "relative",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
๐งช Testing Setupโ
Jest Configurationโ
Create jest.config.js
:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
moduleNameMapping: {
'^@/(.*)$': '<rootDir>/src/$1'
}
};
Test Setup Fileโ
Create src/test-setup.ts
:
import '@testing-library/jest-dom';
// Mock Web Components
customElements.define('test-element', class extends HTMLElement {
connectedCallback() {
this.innerHTML = '<div>Test Element</div>';
}
});
๐ Browser Supportโ
@rhtml supports all modern browsers:
- Chrome (v88+)
- Firefox (v85+)
- Safari (v14+)
- Edge (v88+)
For older browsers, you may need polyfills:
npm install @webcomponents/webcomponentsjs
๐ Next Stepsโ
Now that you have @rhtml installed, you can:
- Learn about Components
- Explore State Management
- Check out Controllers
- Understand Modules