Git Product home page Git Product logo

wails-skeletonui-template-application's Introduction

Wails with Skeleton frontend Template Application

About

This is a quick template application to use a SkeletonUI frontend on a Wails application.

This template is required as there are some nuances that make for poor compatibility between Wails and SkeletonUI. Notably, SkeletonUI creates an application that (when built with SSR) does not have the correct directory structure that Wails wants in the embedded site. This README walks you through setting up a project with Wails and SkeletonUI that still builds correctly using wails build and can be live developed using wails dev. Alternatively, cloning this repo should offer a template to start developing from.

This template is guided by Plihelix's repo, and aims to work better for my own personal projects.

Setting up a new project

Start by creating a new Wails application:

wails init -n Wails-SkeletonUI-Template-App -t svelte

Moving into the newly created directory, remove the frontend directory as we will replace it soon:

cd WailsSkeletonTemplateApp
rm -r ./frontend

Create a new frontend using SkeletonUI:

npm create skeleton-app@latest frontend

We now have a frontend using SkeletonUI, with a backend that (when built) does not understand the directory structure. We can fix this by altering the backend and changing svelte to build a static site (disabling SSR).

First, we note that the new frontend will build to the directory frontend/build, so we must embed this in main.go.

//go:embed all:frontend/build
var assets embed.FS

Your Go linter may complain that frontend/build does not exist, which can be silenced by either creating the directory now or waiting to build the project for the first time. frontend/build is ignored by the Sveltekit default .gitignore, and probably should remain ignored as it is constantly changing with each build. To ensure your project builds correctly when using CI on a remote repo (e.g. GitHub), add a file to the frontend/build directory, immediately commit it, tell git to assume it remains unchanged forever, then remove it again (or let Sveltekit remove it when building the project next):

mkdir frontend/build
touch frontend/build/.gitkeep
git add frontend/build/.gitkeep
git commit -m "Add .gitkeep to frontend/build to ensure directory is tracked"
git update-index --skip-worktree frontend/build/.gitkeep

Add the following line to wails.json, so Wails places the wailjs directory in the default library alias for Sveltekit:

"wailsjsdir": "./frontend/src/lib",

We now add the static adapter to the frontend, as well as the svelte preprocessor:

cd frontend
npm install -D @sveltejs/adapter-static svelte-preprocess

We replace the frontend/svelte.config.js file to implement the static adapter. Ensure you replace the Wails generated frontend/svelte.config.js with the one from this template repo. We also replace frontend/vite.config.js with the file from this repo, updating the resolver to serve app.html even when Wails asks for index.html.

Edit frontend.tsconfig.json and/or frontend/jsconfig.json adding the following at the bottom of "compilerOptions", to overwrite the default Sveltekit variables and allows for importing from the frontend directory:

"paths": {
  "$lib": ["src/lib"],
  "$lib/*": ["src/lib/*"],
  "@/*": ["*"]
}

That's it! Ensure your project operates correctly under both live development (wails dev) and building (wails build). Happy developing!

wails-skeletonui-template-application's People

Contributors

hmcalister 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.