Giter Site home page Giter Site logo

braincompiler / wails-lit-shoelace-esbuild-template Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 175 KB

A wails template using lit and Shoelace component library + esbuild.

Go 2.83% JavaScript 58.11% TypeScript 25.72% CSS 3.89% HTML 2.08% Shell 7.36%

wails-lit-shoelace-esbuild-template's Introduction

Wails template using lit + Shoelace component library + esbuild

About

Wails template providing frontend with lit, Shoelace component library + pre-configured prettier and typescript.

Live Development

To run in live development mode, run wails dev in the project directory. This will run an esbuild process that will provide a watcher and hot reload of your frontend changes (including fast hot replacement for css without reloading). If you want to develop in a browser and have access to your Go methods, there is also a dev server that runs on http://localhost:34115. Connect to this in your browser, and you can call your Go code from devtools.

It's possible to start the frontend without wails backend:

npm run serve

This will serve the frontend on http://localhost:3000.

Optional port parameter:

npm run serve --port=3210

This will serve the frontend on http://localhost:3210.

Features

Building

To build a redistributable, production mode package, use wails build.

Auto-import of shoelace components

Actually, to use the shoelace components they have to be imported to make them available:

import '@shoelace-style/shoelace/dist/components/button/button.js';

This template provides an esbuild-plugin which scans the src files for used shoelace components and imports them automatically. This way the import will never be forgotten and don't need to import all components and bloat up the bundle.

WailsContext service

This template provides a simple context (https://lit.dev/docs/data/context/) to access the wails backend. This should help to avoid runtime errors in case the frontend is developed without the wails backend.

Provide the context

import { LitElement } from 'lit';

import { provide } from '@lit/context';
import { customElement, property } from '@lit/reactive-element/decorators.js';

import { IWailsContext, wailsContext, WailsContext } from '@contexts';

@customElement('app-root')
export class AppComponent extends LitElement {
    @provide({ context: wailsContext })
    @property({ attribute: false })
    private readonly wailsContext: IWailsContext = new WailsContext();
    
    // ...
}

Consume the context in a child component of the providing parent/root component

import { html, LitElement } from 'lit';

import { consume } from '@lit/context';
import { customElement, property, query, state } from '@lit/reactive-element/decorators.js';

import { SlInput } from '@shoelace-style/shoelace';

import { IWailsContext, wailsContext } from '@contexts';

@customElement('app-child')
export class ChildComponent extends LitElement {
    @consume({ context: wailsContext })
    @property({ attribute: false })
    private readonly wailsContext!: IWailsContext;

    @query('#name')
    private readonly nameInput?: SlInput;

    @state()
    private result: string = 'Please enter your name below ๐Ÿ‘‡';

    public render() {
        return html`
            <div class="form">
                <sl-input
                    id="name"
                    label="${this.result}"
                    clearable
                ></sl-input>
                <sl-button @click="${this.greet}">Greet</sl-button>
            </div>
        `;
    }

    private async greet() {
        if (this.wailsContext.has('Greet')) {
            this.result = await this.wailsContext.call<string>('Greet', this.nameInput?.value);
        } else {
            this.result = '"Greet" function not found';
        }
    }
}

Planned features

  • A WailsRuntimeContext service with all the runtime features provided by wails.
  • This template with vite instead of esbuild

wails-lit-shoelace-esbuild-template's People

Contributors

braincompiler avatar

Watchers

 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.