Code Monkey home page Code Monkey logo

pwa-lit-template's Introduction

๐Ÿ›  Status: Experimental

pwa-lit-template is currently in development.

CI

pwa-lit-template

This project helps you to build Progressive Web Applications following the modern web standards, best practices and providing you with tools for that purpose. Out of the box, provides you with the following features:

  • Simple way to create Web Components with LitElement.
  • Small and powerful client-side router for Web Components with Vaadin Router.
  • All the benefits from a PWA (manifest, service worker, offline UI) thanks to Workbox and pwa-helpers.
  • SEO friendly thanks to the PageElement custom element and the html-meta-manager.
  • A development server with auto-reload to serve the application without bundling the code with es-dev-server.
  • Simple build flow thanks to Rollup and @open-wc/building-rollup initial configuration.
  • Easy deployment over to prpl-server or any static hosting.

Getting started

Prerequisites

Furthermore, this project is built on TypeScript with the intention of improving the developer experience.

Install the dependencies

npm install

Start the development server

This command serves the app at http://localhost:8000:

npm start

The folder that es-dev-server will serve running this command will be src-js/, a compiled version from TypeScript that will output plain JavaScript, without any transformation from the build process.

Project structure

โ”œโ”€ images/
โ”œโ”€ patches/
โ”œโ”€ server/
โ”œโ”€ src/
โ”‚  โ”œโ”€ components/
โ”‚  โ”‚  โ”œโ”€ app-index.ts
โ”‚  โ”‚  โ””โ”€ ยทยทยท
โ”‚  โ”œโ”€ config/
โ”‚  โ”œโ”€ helpers/
โ”‚  โ”‚  โ”œโ”€ page-element.ts
โ”‚  โ”‚  โ””โ”€ ยทยทยท
โ”‚  โ”œโ”€ pages/
โ”‚  โ”‚  โ”œโ”€ page-home.ts
โ”‚  โ”‚  โ””โ”€ ยทยทยท
โ”‚  โ””โ”€ router/
โ”‚     โ””โ”€ routes.ts
โ”œโ”€ index.html
โ”œโ”€ manifest.webmanifest
โ”œโ”€ package.json
โ”œโ”€ robots.txt
โ”œโ”€ rollup.config.js
โ””โ”€ tsconfig.json
  • images: is use to store the static resourced used by your application.
  • patches: contains the patches to apply in the different packages mentioned here. It will be removed at some point.
  • server: contains the logic to serve the application. And is where you are going to create your dist/ folder containing the bundle of your application.
  • src
    • components: contains your custom Web Components. Inside this folder you will find the app-index.ts file, main root of your application following the PRPL patern.
    • config: stores the configuration (handles the environment at the build time).
    • helpers: contains two interesting features: PageElement and html-meta-manager. Go more in-depth with them here.
    • pages: where you create the pages for your application.
    • router: where you create the routes for your application.
  • index.html: the application entry point.

Guides

Build for production

This command use Rollup to build an optimized version of the application for production:

npm run build

It has two outputs: in addition to outputting a regular build, it outputs a legacy build which is compatible with older browsers down to IE11.

At runtime it is determined which version should be loaded, so that legacy browsers don't force to ship more and slower code to most users on modern browsers.

Note: If you need to add static files to the build, like the images folder or the manifest.webmanifest, you should register them in the copy() plugin of the rollup.config.js.

Create a new page

  1. Create the new page component (extending from PageElement helper) in the pages folder. For example a page-explore.ts.

    import { html, customElement } from 'lit-element';
    
    import { PageElement } from '../helpers/page-element';
    
    @customElement('page-explore')
    export class PageExplore extends PageElement {
      render() {
        return html`
          <h1>Explore</h1>
          <p>My new explore page!</p>
        `;
      }
    }
  2. Register the new route in the routes.ts:

    {
      path: '/explore',
      name: 'explore',
      component: 'page-explore',
      metadata: {
        title: 'Explore',
        description: 'Explore page description'
      },
      action: async () => {
        await import('../pages/page-explore');
      }
    },

With SEO in mind, this project offers you the PageElement base class to help you to deal with it; it has a metadata() method that edits the HTML meta tags of the specific page with the metadata property defined in the route. And if you need dynamic information, you also can override the metadata() method.

Browser support

  • Chrome
  • Edge
  • Firefox
  • Safari

To run on other browsers, you need to use a combination of polyfills and transpilation. This step is automated by the build for production command.


Things to be aware

  • There is a patch that modifies the @vaadin/router's scroll standard behavior to have a more consistent scroll; now when you perform a click event, the scroll will be reset to the top position.

    Related issue: #1: Remove the Vaadin Router patch

pwa-lit-template's People

Contributors

abdonrd avatar dependabot[bot] avatar tansito avatar ruanxianzhi avatar

Watchers

James Cloos avatar  avatar

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.