website/versioned_docs/version-v2.11.0/guides/templates.mdx
Wails generates projects from pre-created templates. In v1, this was a difficult to maintain set of projects that were subject to going out of date. In v2, to empower the community, a couple of new features have been added for templates:
To create a template, you can use the wails generate template command. To generate a default template, run:
wails generate template -name mytemplate
This creates the directory "mytemplate" with default files:
.
|-- NEXTSTEPS.md
|-- README.md
|-- app.tmpl.go
|-- frontend
| `-- dist
| |-- assets
| | |-- fonts
| | | |-- OFL.txt
| | | `-- nunito-v16-latin-regular.woff2
| | `-- images
| | `-- logo-dark.svg
| |-- index.html
| |-- main.css
| `-- main.js
|-- go.mod.tmpl
|-- main.tmpl.go
|-- template.json
`-- wails.tmpl.json
The default template consists of the following files and directories:
| Filename / Dir | Description |
|---|---|
| NEXTSTEPS.md | Instructions on how to complete the template |
| README.md | The README published with the template |
| app.tmpl.go | app.go template file |
| frontend/ | The directory containing frontend assets |
| go.mod.tmpl | go.mod template file |
| main.tmpl.go | main.go template file |
| template.json | The template metadata |
| wails.tmpl.json | wails.json template file |
At this point it is advisable to follow the steps in NEXTSTEPS.md.
It's possible to create a template from an existing frontend project by passing the path to the project when generating the template. We will now walk through how to create a Vue 3 template:
npm install -g @vue/clivue create vue3-base
Default (Vue 3) ([Vue 3] babel, eslint)> wails generate template -name wails-vue3-template -frontend .\vue3-base\
Extracting base template files...
Migrating existing project files to frontend directory...
Updating package.json data...
Renaming package.json -> package.tmpl.json...
Updating package-lock.json data...
Renaming package-lock.json -> package-lock.tmpl.json...
NEXTSTEPS.md filewails init -n my-vue3-project -t .\wails-vue3-template\cd my-vue3-project then wails build.\build\bin\my-vue3-project.exe<div className="text--center">
</div>
Publishing a template is simply pushing the files to GitHub. The following best practice is encouraged:
.git) from your frontend directorytemplate.json is complete, especially helpurl