GithubHelp home page GithubHelp logo

shinobi5 / skeletor Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 373 KB

:skull: Front-end boilerplate for the web platform with Deno

JavaScript 5.46% CSS 25.50% HTML 3.70% TypeScript 65.34%
web-components boilerplate front-end deno

skeletor's Introduction


Image of Skeletor, the lead villain, from Masters of the Universe

Skeletor

Front-end boilerplate for the web platform with Deno.

License MIT


Includes

Notes

This boilerplate is still a work in progress...

Project requires deno and velociraptor to be installed

Custom element names require a hyphen (see using custom elements). Change this during setup (default: x)

Getting started

Clone the repository and give the project a name

git clone [email protected]:shinobi5/skeletor.git <project-name>

Initialise new git repository

cd <project-name> && rm -rf .git && git init

Setup project

vr setup

Serve the project at localhost:1234

vr start

Create build for production in the root of the project at build/

vr build

Components

Create boilerplate web component in src/js/components/

vr create-component

Usage examples

<head>
  <script
    type="module"
    src="js/components/custom-component/custom-component.js"
    defer
  ></script>
</head>
<body>
  <x-custom-component>Custom component</x-custom-component>
</body>
import { component, html } from 'https://cdn.skypack.dev/haunted';
import '../custom-component/custom-component.js';

const app = () => {
  return html`
    <x-custom-component>Custom component</x-custom-component>
  `;
};

customElements.define('x-app', component(app, { useShadowDOM: false }));

Resources

CSS

ShadowDOM

For web components, styles can be set within the shadowDOM and will be encapsulated within the component.

CSS-in-JS

A framework agnostic CSS-in-JS solution like csz can be used to generate scoped styles for custom elements without a shadowDOM.

Alternatively create component scoped global styles with a convention like BEM and remove the need for JS to scope and load styles at runtime.

import { component, html } from 'https://cdn.skypack.dev/haunted';
import css from 'https://cdn.skypack.dev/csz';

const customElement = () => {
  return html`
    <div class=${
      css`
        color: rebeccapurple;
        background-color: black;
        padding: 20px;
      `
    }>
      Custom element with scoped runtime generated styles!
    </div>
  `;
};

customElements.define('x-custom-element', component(customElement, { useShadowDOM: false }));

Global CSS

Basic global styles are provided by default (but can be disabled through the setup CLI) with tools to watch for changes and concatenate the individual files into a single minified styles.css.

The concatenating happens in order from broad to specific styles based on the folder they're in (in the following order): settings, global, elements, components, utilities.

State

Haunted provides internal component state management (same as react hooks).

Global state can be handled with redux and boilerplate files can be generated through the setup step or by running:

vr create-redux

Routing

Routing examples using router-component.

<head>
  <script src="https://cdn.skypack.dev/router-component"></script>
  <script src="js/components/firstPage/firstPage.js"></script>
  <script src="js/components/secondPage/secondPage.js"></script>
  <script src="js/components/pageNotFound/pageNotFound.js"></script>
</head>
<body>
  <router-component>
    <x-first-page path="^/(index.html)?$"></x-first-page>
    <x-second-page path="second-page"></x-second-page>
    <x-page-not-found path=".*"></x-page-not-found>
  </router-component>
</body>
import { component, html } from 'https://cdn.skypack.dev/haunted';
import 'https://cdn.skypack.dev/router-component';
import '../firstPage/firstPage.js';
import '../secondPage/secondPage.js';
import '../pageNotFound/pageNotFound.js';

const app = () => {
  return html`
    <router-component>
      <x-first-page path="^/(index.html)?$"></x-first-page>
      <x-second-page path="second-page"></x-second-page>
      <x-page-not-found path=".*"></x-page-not-found>
    </router-component>
  `;
};

customElements.define('x-app', component(app, { useShadowDOM: false }));

Modules / Bundle

Bundling is not really a thing in Deno (yet) so the best option seems to be a full-scale native es module approach (which is a good thing in my opinion anyway).

Deno has a bundler that works out of the box but it's not at all suitable for production builds. The resulting frontend SystemJS bundled file produced by the internal bundler is massive (lots of module loader boilerplate and no tree-shaking).

This is a great starting point for exploring how browsers handle es modules:
https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/

Deno bundling v3:
denoland/deno#4549

Possible option for bundling:
https://github.com/denofn/denopack

skeletor's People

Contributors

shinobi5 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

skeletor's Issues

Update npm dependencies

  • pkg.dependencies.js
  • scripts/node/templates/package-json.js
  • scripts/node/project/package.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.