This starter kit provides a foundation for building custom Twilight components for Salla's e-commerce platform. It includes a pre-configured build setup and development environment to help you get started quickly.
- Clone this repository
- Remove the example components in
src/components/using:tw-delete-component - Create your own components using the component generator:
tw-create-component <component-name> - Run
pnpm installto install dependencies - Run
pnpm run devto start the development server - Run
pnpm run buildto build your components for production
src/
components/
your-component-name/
index.ts # Main component file
styles.ts # Component styles (optional)
types.ts # Component types (optional)
This starter kit includes three Vite plugins that handle the build process:
- Transforms component files to ensure proper naming and registration
- Matches components in
src/components/*/index.ts - To disable: Remove from
vite.config.tsplugins array
- Handles component bundling and output
- Creates individual files for each component in
dist/ - Configures external dependencies (lit libraries)
- To customize: Remove from plugins array and configure your own build settings:
{ build: { lib: { entry: {/* your entries */}, formats: ['es'], fileName: (format, entryName) => `${entryName}.js` }, rollupOptions: { external: [/^lit/], output: {/* your output config */} } } }
- Provides a development environment for testing components
- Creates a demo page with your components
- Configures hot module reloading
- To disable: Remove from plugins array and set up your own dev server
The sallaDemoPlugin accepts the following configuration options:
{
// Optional: Show only specific components
components?: string[];
// Optional: Customize the demo grid layout
grid?: {
// CSS grid-template-columns value
columns?: string; // default: 'repeat(auto-fill, minmax(300px, 1fr))'
// Gap between components
gap?: string; // default: '1rem'
// Responsive breakpoint
minWidth?: string; // default: '300px'
};
// Optional: Add custom CSS
css?: string;
// Optional: Add custom JavaScript
js?: string;
}// vite.config.ts
export default defineConfig({
plugins: [
// ... other plugins
sallaDemoPlugin({
// Show only specific components
components: ['product-card', 'scroll-top'],
// Customize grid layout
grid: {
columns: 'repeat(3, 1fr)',
gap: '1.5rem',
minWidth: '768px'
},
// Add custom styles
css: `
.component-card {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
.component-card:hover {
transform: translateY(-2px);
}
`,
// Add custom JavaScript
js: `
console.log('Demo page loaded!');
// Add your custom JavaScript here
`
})
]
});This starter kit includes a component generator to help you create new components quickly. To use it, run:
pnpm tw-create-component <component-name>Or run without arguments for interactive mode:
pnpm tw-create-componentThe generator will:
- Prompt you for a component name (in kebab-case format)
- Validate that the name is in kebab-case and doesn't already exist
- Create a new component folder with an
index.tsfile - Add the component definition to
twilight-bundle.json
To remove a component, use:
pnpm tw-delete-component <component-name>Or run without arguments to see a list of available components:
pnpm tw-delete-componentThis will:
- Show a list of available components to select from
- Ask for confirmation before deletion
- Remove the component folder from
src/components/ - Remove the component definition from
twilight-bundle.json
Each component should:
- Be a class that extends
LitElement - Export the class as default
- Be placed in its own directory under
src/components/ - Have an
index.tsas the entry point
Example:
import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
export default class MyComponent extends LitElement {
@property({ type: Object })
config?: {
name: string;
//... other properties
};
static styles = css`/* your styles */`;
render() {
return html`<div>Hello ${this.config?.name || 'World'}!</div>`;
}
}Run pnpm run build to create production-ready bundles in the dist/ directory. Each component will have its own file named after the component (e.g., my-component.js).
Run pnpm run dev to start the development server. This will:
- Create a demo page with all your components
- Enable hot module reloading
- Provide a development environment for testing
MIT