Socket
Socket
Sign inDemoInstall

@stencil/core

Package Overview
Dependencies
0
Maintainers
2
Versions
1180
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @stencil/core

A Compiler for Web Components and Progressive Web Apps


Version published
Weekly downloads
636K
decreased by-0.51%
Maintainers
2
Install size
18.8 MB
Created
Weekly downloads
 

Package description

What is @stencil/core?

@stencil/core is a compiler for building fast web apps using Web Components. It combines the best features of popular frameworks into a simple build-time tool. Stencil generates standards-compliant Web Components that work in any major framework or with no framework at all.

What are @stencil/core's main functionalities?

Component Creation

Stencil allows you to create reusable web components. The example demonstrates a simple component that takes a 'name' property and renders a greeting message.

```typescript
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>;
  }
}
```

Reactive Data Binding

Stencil provides reactive data binding using the @State decorator. The example shows a counter component that updates its state and re-renders when the button is clicked.

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

@Component({
  tag: 'counter-component',
  styleUrl: 'counter-component.css',
  shadow: true
})
export class CounterComponent {
  @State() count: number = 0;

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

  render() {
    return (
      <div>
        <p>Count: {this.count}</p>
        <button onClick={() => this.increment()}>Increment</button>
      </div>
    );
  }
}
```

Lazy Loading

Stencil supports lazy loading of components to improve performance. The example shows a component that will be lazy-loaded when needed.

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

@Component({
  tag: 'lazy-component',
  styleUrl: 'lazy-component.css',
  shadow: true,
  assetsDirs: ['assets']
})
export class LazyComponent {
  render() {
    return <div>Lazy Loaded Component</div>;
  }
}
```

Other packages similar to @stencil/core

Changelog

Source

⛲️ 4.18.2 (2024-05-20)

Bug Fixes

  • e2e: allow to fetch CSS variables assigned to host elements (#5682) (e420eb6), closes #5681
  • hydrate: respect HydratedFlag configuration in hydrate script (#5741) (3538d06), closes #3606
  • runtime: always throw if component can not be loaded (#5762) (1d52b95), closes #5759
  • runtime: support watch for components with custom tag names (#5767) (f561e0f), closes #3554
  • runtime: throw proper error if component is loaded with invalid runtime (#5675) (3cfbb8d), closes #5596
  • types: move autofocus attr/prop definition to HTMLAttributes (#5727) (3a33eff), closes #5726

Readme

Source

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.

Keywords

FAQs

Last updated on 20 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc