DanielContreras18881 / workshop-stenciljs

Workshop about StencilJS for beginners

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Built With Stencil

Stencil Workshop Starter with Storybook

This is a starter project for building a library of web components using Stencil and Storybook.

The slides are here: https://beta.deckdeckgo.io/raguilera/workshop-stenciljs/

Stencil

Stencil is a compiler for building fast web apps using Web Components.

Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.

Stencil components are just Web Components, so they work in any major framework or with no framework at all.

Pre-Requisites

Note: A client of Git is mandatory!

Before of nothing, you need to install the latest version of NodeJS in your workstation.

For that, the best way is thru NVM.

Once installed you have to run:

  • (Linux & MacOS)
$> nvm install stable
  • (Windows)
$> nvm install latest

And that's all!

Also, you need a text editor and a browser. For that, Visual Studio Code and Chrome are the best!

Getting Started

To start building a new web component using Stencil and Storybook, clone this repo to a new directory:

$> git clone https://github.com/raguilera82/workshop-stenciljs
$> cd workshop-stenciljs
$> npm install

Once finished this process, you have to run:

$> npm run start

After few seconds the browser must open the Storybook's homepage with the default index page component.

You must see that any changes in code reflects on the browser.

Some useful commands

Create new component

For that, you have to run:

$> npm run generate

The console asks for a name of the component and you can select the files that you want to create.

Build Stencil & Storybook for production

$> npm run build

This command creates two folders:

  • dist: for StencilJS
  • storybook-static: for Storybook

If you want to build only Stencil, you have to run:

$> npm run build:stencil

Or only Storybook:

$> npm run build:storybook

Run test

To run test E2E and unit, you have to run:

$> npm run test

Need help? Check out our docs here.

Using this component

Script tag

  • Publish to NPM
  • Put a script tag similar to this <script src='https://unpkg.com/my-component@0.0.1/dist/mycomponent.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

Node Modules

  • Run npm install my-component --save
  • Put a script tag similar to this <script src='node_modules/my-component/dist/mycomponent.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

In a stencil-starter app

  • Run npm install my-component --save
  • Add an import to the npm packages import my-component;
  • Then you can use the element anywhere in your template, JSX, html etc

Any doubts or troubles?

Please open an issue in this repository

About

Workshop about StencilJS for beginners

License:MIT License


Languages

Language:JavaScript 36.4%Language:TypeScript 31.1%Language:CSS 29.5%Language:HTML 3.0%