Convert Figma logo to code with AI

stenciljs logocore

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.

12,735
800
12,735
277

Top Related Projects

12,666

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.

81,903

web development for the rest of us

233,534

The library for web and native user interfaces.

208,514

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

97,258

Deliver web apps with confidence 🚀

37,267

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Quick Overview

StencilJS is a compiler for building fast, reusable web components and progressive web apps (PWAs). It combines the best concepts of popular frameworks into a simple build-time tool, generating standards-compliant web components that run in any modern browser.

Pros

  • Generates framework-agnostic, standards-compliant web components
  • Offers excellent performance due to its compile-time optimizations
  • Provides a familiar developer experience with TypeScript, JSX, and decorators
  • Includes built-in lazy-loading and code-splitting capabilities

Cons

  • Learning curve for developers not familiar with web components
  • Limited ecosystem compared to more established frameworks
  • May require additional tooling for complex state management in large applications
  • Some features might not be fully supported in older browsers

Code Examples

  1. Creating a simple component:
import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',
  shadow: true,
})
export class MyComponent {
  @Prop() name: string;

  render() {
    return <div>Hello, {this.name}!</div>;
  }
}
  1. Using lifecycle methods:
import { Component, State, Method, h } from '@stencil/core';

@Component({
  tag: 'my-counter',
})
export class MyCounter {
  @State() count: number = 0;

  @Method()
  async increment() {
    this.count++;
  }

  componentWillLoad() {
    console.log('Component is about to load');
  }

  render() {
    return (
      <div>
        <p>Count: {this.count}</p>
        <button onClick={() => this.increment()}>Increment</button>
      </div>
    );
  }
}
  1. Handling events:
import { Component, Event, EventEmitter, h } from '@stencil/core';

@Component({
  tag: 'my-button',
})
export class MyButton {
  @Event() buttonClicked: EventEmitter<string>;

  handleClick() {
    this.buttonClicked.emit('Button was clicked!');
  }

  render() {
    return <button onClick={() => this.handleClick()}>Click me</button>;
  }
}

Getting Started

To start using StencilJS, follow these steps:

  1. Install StencilJS globally:

    npm init stencil
    
  2. Choose a starter project (e.g., component, app)

  3. Navigate to your project directory and install dependencies:

    cd my-stencil-project
    npm install
    
  4. Start the development server:

    npm start
    
  5. Build your components in the src/components directory

  6. To build for production:

    npm run build
    

Competitor Comparisons

12,666

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.

Pros of Stencil

  • More comprehensive documentation and examples
  • Stronger integration with Ionic framework ecosystem
  • Better support for building design systems and component libraries

Cons of Stencil

  • Slightly larger bundle size
  • Steeper learning curve for developers new to Web Components
  • More opinionated approach to component development

Code Comparison

Stencil component:

import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',
  shadow: true,
})
export class MyComponent {
  @Prop() name: string;

  render() {
    return <div>Hello, {this.name}</div>;
  }
}

Stenciljs/core component:

import { Component, Prop } from '@stencil/core';

@Component('my-component')
export class MyComponent {
  @Prop() name: string;

  render() {
    return `<div>Hello, ${this.name}</div>`;
  }
}

Both repositories aim to simplify Web Component development, but Stencil offers a more feature-rich environment with additional tooling and integration options. Stenciljs/core provides a more lightweight approach, focusing on core functionality. The code comparison shows similar syntax, with Stencil using JSX-like rendering and Stenciljs/core using template literals. Developers should consider their project requirements and ecosystem preferences when choosing between the two.

81,903

web development for the rest of us

Pros of Svelte

  • Smaller bundle sizes due to compile-time optimizations
  • More intuitive syntax with less boilerplate code
  • Faster runtime performance, especially for small to medium-sized applications

Cons of Svelte

  • Smaller ecosystem and community compared to more established frameworks
  • Limited tooling and IDE support
  • Potential challenges with scaling for very large applications

Code Comparison

Svelte component:

<script>
  let count = 0;
  function increment() {
    count += 1;
  }
</script>

<button on:click={increment}>
  Clicks: {count}
</button>

Stencil component:

import { Component, State, h } from '@stencil/core';

@Component({
  tag: 'my-component',
})
export class MyComponent {
  @State() count: number = 0;

  increment() {
    this.count += 1;
  }

  render() {
    return (
      <button onClick={() => this.increment()}>
        Clicks: {this.count}
      </button>
    );
  }
}

The Svelte example demonstrates its more concise syntax, while the Stencil example showcases its use of decorators and TypeScript integration. Both frameworks aim to simplify component creation, but Svelte's approach results in less code and a more straightforward structure.

233,534

The library for web and native user interfaces.

Pros of React

  • Larger ecosystem and community support
  • More mature and battle-tested in production environments
  • Extensive third-party libraries and tools available

Cons of React

  • Steeper learning curve for beginners
  • Requires additional libraries for state management and routing
  • Larger bundle size compared to Stencil's output

Code Comparison

React component:

import React from 'react';

const MyComponent = ({ name }) => {
  return <h1>Hello, {name}!</h1>;
};

export default MyComponent;

Stencil component:

import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-component',
})
export class MyComponent {
  @Prop() name: string;

  render() {
    return <h1>Hello, {this.name}!</h1>;
  }
}

The main differences in the code examples are:

  • React uses functional components with hooks, while Stencil uses class-based components with decorators
  • Stencil requires the @Component decorator and defines a custom element tag
  • Props in Stencil are declared using the @Prop() decorator
  • Stencil's render method is part of the class, while React's return statement is the entire functional component

Both frameworks use JSX for templating, making the actual rendering syntax quite similar.

208,514

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

Pros of Vue

  • More mature ecosystem with extensive community support and plugins
  • Easier learning curve for developers familiar with traditional web development
  • Flexible and incrementally adoptable, allowing gradual integration into existing projects

Cons of Vue

  • Larger bundle size compared to Stencil's output
  • Less focus on web components and cross-framework compatibility
  • May require additional tooling for optimal performance in large-scale applications

Code Comparison

Vue component:

<template>
  <div>{{ message }}</div>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, Vue!'
    }
  }
}
</script>

Stencil component:

import { Component, h, State } from '@stencil/core';

@Component({
  tag: 'my-component'
})
export class MyComponent {
  @State() message: string = 'Hello, Stencil!';

  render() {
    return <div>{this.message}</div>;
  }
}

Vue focuses on a template-based approach with a more familiar structure for traditional web developers. Stencil uses TypeScript decorators and JSX, emphasizing type safety and web component creation. While Vue offers a gentler learning curve and broader ecosystem, Stencil excels in generating lightweight, framework-agnostic web components with better performance characteristics.

97,258

Deliver web apps with confidence 🚀

Pros of Angular

  • Comprehensive framework with built-in features like routing, forms, and HTTP client
  • Large ecosystem with extensive third-party libraries and community support
  • Powerful CLI for project scaffolding, development, and build processes

Cons of Angular

  • Steeper learning curve due to its complexity and TypeScript requirement
  • Larger bundle size, which can impact initial load times
  • More opinionated structure, potentially limiting flexibility for some projects

Code Comparison

Angular component:

@Component({
  selector: 'app-hello',
  template: '<h1>Hello, {{name}}!</h1>'
})
export class HelloComponent {
  @Input() name: string;
}

Stencil component:

@Component({
  tag: 'my-hello',
  template: '<h1>Hello, {{name}}!</h1>'
})
export class HelloComponent {
  @Prop() name: string;
}

Both frameworks use decorators and similar syntax for component creation. However, Angular uses @Input() for properties, while Stencil uses @Prop(). Angular's selector uses a prefix, while Stencil defines a custom element tag.

Stencil focuses on generating web components that can be used in any framework, offering better interoperability. It has a smaller footprint and faster compilation times compared to Angular. However, Angular provides a more complete solution for large-scale applications with its extensive feature set and established patterns.

37,267

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Pros of Preact

  • Smaller bundle size (3KB gzipped) for lightweight applications
  • Faster rendering and better performance in benchmarks
  • Easier learning curve for developers familiar with React

Cons of Preact

  • Less extensive ecosystem and fewer third-party libraries
  • Limited built-in features compared to Stencil's full-featured approach
  • May require additional polyfills for older browser support

Code Comparison

Preact component:

import { h, Component } from 'preact';

class MyComponent extends Component {
  render() {
    return <div>Hello, {this.props.name}!</div>;
  }
}

Stencil component:

import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-component',
})
export class MyComponent {
  @Prop() name: string;

  render() {
    return <div>Hello, {this.name}!</div>;
  }
}

The code comparison shows that Preact follows a more React-like syntax, while Stencil uses decorators and a slightly different component structure. Stencil's approach provides additional features like automatic component registration and built-in property declarations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

stencil-logo

Stencil

A compiler for generating Web Components using technologies like TypeScript and JSX, built by the Ionic team.

StencilJS is released under the MIT license. StencilJS is released under the MIT license. PRs welcome! Follow @stenciljs Official Ionic Discord

Quick Start · Documentation · Contribute · Blog
Community: Discord · Forums · Twitter

Getting Started

Start a new project by following our quick Getting Started guide. We would love to hear from you! If you have any feedback or run into issues using Stencil, please file an issue on this repository.

Examples

A Stencil component looks a lot like a class-based React component, with the addition of TypeScript decorators:

import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-component',            // the name of the component's custom HTML tag
  styleUrl: 'my-component.css',   // css styles to apply to the component
  shadow: true,                   // this component uses the ShadowDOM
})
export class MyComponent {
  // The component accepts two arguments:
  @Prop() first: string;
  @Prop() last: string;

   //The following HTML is rendered when our component is used
  render() {
    return (
      <div>
        Hello, my name is {this.first} {this.last}
      </div>
    );
  }
}

The component above can be used like any other HTML element:

<my-component first="Stencil" last="JS"></my-component>

Since Stencil generates web components, they work in any major framework or with no framework at all. In many cases, Stencil can be used as a drop in replacement for traditional frontend framework, though using it as such is certainly not required.

Contributing

Thanks for your interest in contributing! Please take a moment to read up on our guidelines for contributing. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

NPM DownloadsLast 30 Days