Compare commits
9 Commits
dbe49ef82b
...
1b760329ef
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b760329ef | |||
| 86eac30d5e | |||
| 5a70b50a6e | |||
| bfdabf4033 | |||
| e19ff49bc4 | |||
| 2bcde24a2c | |||
| fa1131c225 | |||
| b106fe5617 | |||
| 58e435a7bd |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
tmp
|
||||||
|
server
|
||||||
|
dist
|
||||||
|
index.html
|
||||||
62
Makefile
Normal file
62
Makefile
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
all: build
|
||||||
|
|
||||||
|
nil:
|
||||||
|
|
||||||
|
reactNextJS/out/*: reactNextJS/app/* reactNextJS/*.js reactNextJS/*.json
|
||||||
|
cd reactNextJS && npm install && npm run build
|
||||||
|
nextjs: reactNextJS/out/*
|
||||||
|
cleanNext:
|
||||||
|
rm -rf reactNextJS/out
|
||||||
|
|
||||||
|
vuejs/dist/*: vuejs/src/*
|
||||||
|
cd vuejs && npm install && npm run build
|
||||||
|
vuejs: vuejs/dist/*
|
||||||
|
cleanVue:
|
||||||
|
rm -rf ./vuejs/dist
|
||||||
|
|
||||||
|
svelte/dist/*: svelte/src/*
|
||||||
|
cd svelte && npm install && npm run build
|
||||||
|
svelte: svelte/dist/*
|
||||||
|
cleanSvelte:
|
||||||
|
rm -rf ./svelte/dist
|
||||||
|
|
||||||
|
cleandist:
|
||||||
|
rm -rf dist
|
||||||
|
dist:
|
||||||
|
mkdir -p dist
|
||||||
|
dist/vanillaJS: dist vanillaJS/index.html
|
||||||
|
rm -rf dist/vanillaJS && \
|
||||||
|
cp -r ./vanillaJS ./dist/vanillaJS
|
||||||
|
dist/react: dist react/index.html
|
||||||
|
rm -rf dist/react && \
|
||||||
|
cp -r ./react ./dist/react
|
||||||
|
dist/alpinejs: dist alpinejs/index.html
|
||||||
|
rm -rf dist/alpinejs && \
|
||||||
|
cp -r ./alpinejs ./dist/alpinejs
|
||||||
|
dist/reactNextJS: dist reactNextJS/out/*
|
||||||
|
rm -rf ./dist/reactNextJS && \
|
||||||
|
cp -r ./reactNextJS/out ./dist/reactNextJS
|
||||||
|
dist/vuejs: dist vuejs/dist/*
|
||||||
|
rm -rf ./dist/vuejs && \
|
||||||
|
cp -r ./vuejs/dist ./dist/vuejs
|
||||||
|
dist/svelte: dist svelte/dist/*
|
||||||
|
rm -rf ./dist/svelte && \
|
||||||
|
cp -r ./svelte/dist ./dist/svelte
|
||||||
|
dist/index.html: dist index.tmpl
|
||||||
|
go run server.go generate
|
||||||
|
mv index.html dist/
|
||||||
|
|
||||||
|
export: dist/vanillaJS dist/react dist/alpinejs dist/reactNextJS dist/assets dist/vuejs dist/svelte dist/index.html
|
||||||
|
web: ./svelte/dist/* ./vuejs/dist/* ./reactNextJS/out/* vanillaJS/index.html react/index.html alpinejs/index.html
|
||||||
|
build: web server.go
|
||||||
|
go build server.go
|
||||||
|
run: web server.go
|
||||||
|
go run server.go
|
||||||
|
air: nil web server.go
|
||||||
|
air server.go
|
||||||
|
clean: cleanNext cleanVue cleanSvelte cleandist
|
||||||
|
rm -rf tmp
|
||||||
|
rm -f server
|
||||||
|
rm -f index.html
|
||||||
|
|
||||||
|
.PHONY: all build clean cleanbuild nextjs vuejs svelte run air nil web export
|
||||||
@ -1,9 +0,0 @@
|
|||||||
<html>
|
|
||||||
<body>
|
|
||||||
<h1>Frontends</h1>
|
|
||||||
<ul>
|
|
||||||
<li><a href="react/index.html">React</a></li>
|
|
||||||
<li><a href="vanillaJS/index.html">vanillaJS</a></li>
|
|
||||||
</ul>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
10
index.tmpl
Normal file
10
index.tmpl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>Frontends</h1>
|
||||||
|
<ul>
|
||||||
|
{{range .}}
|
||||||
|
<li><a href="{{.Mountpoint}}">{{.Name}}</a></li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
output: 'export',
|
output: 'export',
|
||||||
|
basePath: '/reactNextJS',
|
||||||
|
|
||||||
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
|
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
|
||||||
// trailingSlash: true,
|
// trailingSlash: true,
|
||||||
|
|||||||
82
server.go
Normal file
82
server.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const PORT = 3003
|
||||||
|
|
||||||
|
type frontendInfo struct {
|
||||||
|
Name, Mountpoint string
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:embed "all:vuejs/dist"
|
||||||
|
var vueFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed "all:reactNextJS/out"
|
||||||
|
var nextFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed "all:svelte/dist"
|
||||||
|
var svelteFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed "vanillaJS"
|
||||||
|
var vanillaFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed "alpinejs"
|
||||||
|
var alpineFiles embed.FS
|
||||||
|
|
||||||
|
//go:embed "react"
|
||||||
|
var reactFiles embed.FS
|
||||||
|
|
||||||
|
func addFrontend(files embed.FS, mountpoint string, subfs string, name string) frontendInfo {
|
||||||
|
subFiles, _ := fs.Sub(files, subfs)
|
||||||
|
fileServer := http.FileServerFS(subFiles)
|
||||||
|
http.Handle(mountpoint, http.StripPrefix(mountpoint, fileServer))
|
||||||
|
return frontendInfo{name, mountpoint}
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputIndexAndExit(indexTemplate template.Template, frontends []frontendInfo) {
|
||||||
|
file, err := os.OpenFile("index.html", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
panic(err) // Handle error
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
indexTemplate.Execute(file, frontends)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
home_template, err := template.ParseFiles("index.tmpl")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Error parsing homepage template\n%s", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
frontends := []frontendInfo{
|
||||||
|
addFrontend(vanillaFiles, "/vanillaJS/", "vanillaJS", "JS Only"),
|
||||||
|
addFrontend(alpineFiles, "/alpinejs/", "alpinejs", "Alpine.js"),
|
||||||
|
addFrontend(reactFiles, "/react/", "react", "React"),
|
||||||
|
addFrontend(nextFiles, "/reactNextJS/", "reactNextJS/out", "React (Next.js)"),
|
||||||
|
addFrontend(vueFiles, "/vuejs/", "vuejs/dist", "Vue.js"),
|
||||||
|
addFrontend(svelteFiles, "/svelte/", "svelte/dist", "Svelte"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 2 && args[1] == "generate" {
|
||||||
|
outputIndexAndExit(*home_template, frontends)
|
||||||
|
}
|
||||||
|
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
err = home_template.Execute(w, frontends)
|
||||||
|
})
|
||||||
|
|
||||||
|
err = http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Error starting server: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,4 +4,5 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [svelte()],
|
plugins: [svelte()],
|
||||||
|
base: '/svelte/'
|
||||||
})
|
})
|
||||||
|
|||||||
@ -14,5 +14,6 @@ export default defineConfig({
|
|||||||
alias: {
|
alias: {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
base: '/vuejs/'
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user