Compare commits

...

20 Commits

Author SHA1 Message Date
9721c024ff Add scrolling to react native app 2024-06-27 17:15:35 -04:00
b4010cedd8 Update React Native readme 2024-06-26 22:18:44 -04:00
e41ca163a5 Add React Native app 2024-06-26 22:14:36 -04:00
03e5a27b4e Refactor server.go 2024-06-24 21:37:36 -04:00
1b760329ef Build frontends with the expected base url 2024-06-24 20:53:48 -04:00
lks
86eac30d5e Merge pull request 'Use vite.svg the same way as svelte.svg in Svelte frontend' (#1) from main into server
Fix vite.svg not being found with the current technique of combining front ends into one server.
Reviewed-on: #1
2024-06-23 14:03:29 -04:00
dbe49ef82b Use vite.svg the same way as svelte.svg in Svelte frontend 2024-06-23 13:59:28 -04:00
5a70b50a6e Fix Makefile for fresh builds 2024-06-23 13:49:18 -04:00
bfdabf4033 Fix 'make clean' not removing server executable 2024-06-23 12:46:31 -04:00
e19ff49bc4 Switch to single embed fs and add vue and svelte frontends 2024-06-23 12:43:28 -04:00
2bcde24a2c Add alpinejs to server 2024-06-22 18:31:05 -04:00
fa1131c225 Merge branch 'main' into server 2024-06-22 18:24:42 -04:00
778ebf2ba4 Clean up vuejs frontend css 2024-06-20 21:56:33 -04:00
836f720a42 Clean up vuejs frontend css 2024-06-20 21:51:12 -04:00
5feaee7b72 Componentize vue.js frontend 2024-06-20 21:38:18 -04:00
bb2026d182 Add Svelte frontend 2024-06-20 21:18:03 -04:00
f9ba02a160 Add alpinejs frontend 2024-06-20 20:16:27 -04:00
4281b244dd Complete vue.js example 2024-06-20 19:57:44 -04:00
3cb8a7c812 Remove vue router 2024-06-19 22:47:47 -04:00
cf26584449 Create Vue.js frontend 2024-06-19 22:31:25 -04:00
66 changed files with 25459 additions and 51 deletions

3
.gitignore vendored
View File

@@ -1 +1,4 @@
tmp tmp
server
dist
index.html

View File

@@ -5,13 +5,67 @@ nil:
reactNextJS/out/*: reactNextJS/app/* reactNextJS/*.js reactNextJS/*.json reactNextJS/out/*: reactNextJS/app/* reactNextJS/*.js reactNextJS/*.json
cd reactNextJS && npm install && npm run build cd reactNextJS && npm install && npm run build
nextjs: reactNextJS/out/* nextjs: reactNextJS/out/*
serverdeps: nextjs *.go reactNextJS/addToServer.go cleanNext:
rm -rf reactNextJS/out
build: serverdeps 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
reactNative/dist/*: ./reactNative/*
cd reactNative && npm install && npm run export
reactNative: reactNative/dist/*
cleanReactNative:
rm -rf ./reactNative/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/
dist/reactNative: dist reactNative/dist/*
rm -rf ./dist/reactNative && \
cp -r ./reactNative/dist ./dist/reactNative
export: dist/vanillaJS dist/react dist/alpinejs dist/reactNextJS dist/vuejs dist/svelte dist/index.html dist/reactNative
web: ./reactNative/dist/* ./svelte/dist/* ./vuejs/dist/* ./reactNextJS/out/* vanillaJS/index.html react/index.html alpinejs/index.html
build: web server.go
go build server.go go build server.go
run: serverdeps run: web server.go
go run server.go go run server.go
air: nextjs nil air: nil web server.go
air server.go air server.go
clean: cleanNext cleanVue cleanSvelte cleandist
rm -rf tmp
rm -f server
rm -f index.html
.PHONY: all build nextjs serverdeps run air nil .PHONY: all build clean cleanbuild nextjs vuejs svelte run air nil web export

23
alpinejs/index.html Normal file
View File

@@ -0,0 +1,23 @@
<html>
<head>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<body x-data="{
blurb_data: {
title: 'Fart Man Comes To Town!',
blurb: 'Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town believe the imminent winds of change will revitalize the towns central business district.'
}
}">
<div x-data="{blurbs: [blurb_data]}">
<template x-for="blurb in blurbs">
<div>
<h1 x-text="blurb.title"></h1>
<p x-text="blurb.blurb"></p>
<a href="#">Read more...</a>
</div>
</template>
<br />
<button x-on:click="blurbs.push(blurb_data)">Load More</button>
</div>
</body>
</html>

View File

@@ -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
View File

@@ -0,0 +1,10 @@
<html>
<body>
<h1>Frontends</h1>
<ul>
{{range .}}
<li><a href="{{.Mountpoint}}">{{.Name}}</a></li>
{{end}}
</ul>
</body>
</html>

20
reactNative/.gitignore vendored Normal file
View File

@@ -0,0 +1,20 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
# macOS
.DS_Store
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli
expo-env.d.ts
# @end expo-cli

40
reactNative/README.md Normal file
View File

@@ -0,0 +1,40 @@
# Welcome to your Expo app 👋
This is an [Expo](https://expo.dev) project created with [`create-expo-app`](https://www.npmjs.com/package/create-expo-app).
## Get started
1. Install dependencies
```bash
npm install
```
2. Start the app
```bash
npx expo start
```
In the output, you'll find options to open the app in a
- [development build](https://docs.expo.dev/develop/development-builds/introduction/)
- [Android emulator](https://docs.expo.dev/workflow/android-studio-emulator/)
- [iOS simulator](https://docs.expo.dev/workflow/ios-simulator/)
- [Expo Go](https://expo.dev/go), a limited sandbox for trying out app development with Expo
You can start developing by editing the files inside the **app** directory. This project uses [file-based routing](https://docs.expo.dev/router/introduction).
## Learn more
To learn more about developing your project with Expo, look at the following resources:
- [Expo documentation](https://docs.expo.dev/): Learn fundamentals, or go into advanced topics with our [guides](https://docs.expo.dev/guides).
- [Learn Expo tutorial](https://docs.expo.dev/tutorial/introduction/): Follow a step-by-step tutorial where you'll create a project that runs on Android, iOS, and the web.
## Join the community
Join our community of developers creating universal apps.
- [Expo on GitHub](https://github.com/expo/expo): View our open source platform and contribute.
- [Discord community](https://chat.expo.dev): Chat with Expo users and ask questions.

37
reactNative/app.json Normal file
View File

@@ -0,0 +1,37 @@
{
"expo": {
"name": "reactNativeApp",
"slug": "reactNativeApp",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"bundler": "metro",
"output": "static",
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router"
],
"experiments": {
"typedRoutes": true,
"baseUrl": "/reactNative"
}
}
}

View File

@@ -0,0 +1,9 @@
import { Stack } from "expo-router";
export default function RootLayout() {
return (
<Stack>
<Stack.Screen name="index" options={{ title:'Hello World!'}}/>
</Stack>
);
}

33
reactNative/app/index.tsx Normal file
View File

@@ -0,0 +1,33 @@
import { Text, View, Button, ScrollView } from "react-native";
import React, {useState} from 'react';
import { ThemedText } from "@/components/ThemedText"
import Blurb, {BlurbData} from "@/components/Blurb"
const default_blurb: BlurbData = {
title: "Fart Man Comes To Town!",
blurb: "Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town believe the imminent winds of change will revitalize the towns central business district."
};
export default function Index() {
const [blurbs, setBlurbs] = useState([default_blurb])
return (
<ScrollView
contentContainerStyle={{
flex: 1,
justifyContent: "center",
alignItems: "center",
}}
>
{blurbs.map((blurb, i) => (
<Blurb key={i} {...blurb} />
))}
<Button
onPress={() => {
setBlurbs(blurbs.concat([default_blurb]));
}}
title="Load More"
/>
</ScrollView>
);
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,6 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};

View File

@@ -0,0 +1,31 @@
import React, {useState} from 'react';
import {Text, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
baseText: {
fontFamily: 'Cochin',
},
titleText: {
fontSize: 20,
fontWeight: 'bold',
},
});
type BlurbData = {
title: string;
blurb: string;
}
const Blurb = (props: BlurbData) => {
return(
<Text style={styles.baseText}>
<Text style={styles.titleText}>{props.title}</Text>
{'\n'}
{props.blurb}
{'\n'}
{'\n'}
</Text>
);
}
export default Blurb;

View File

@@ -0,0 +1,26 @@
/**
* Below are the colors that are used in the app. The colors are defined in the light and dark mode.
* There are many other ways to style your app. For example, [Nativewind](https://www.nativewind.dev/), [Tamagui](https://tamagui.dev/), [unistyles](https://reactnativeunistyles.vercel.app), etc.
*/
const tintColorLight = '#0a7ea4';
const tintColorDark = '#fff';
export const Colors = {
light: {
text: '#11181C',
background: '#fff',
tint: tintColorLight,
icon: '#687076',
tabIconDefault: '#687076',
tabIconSelected: tintColorLight,
},
dark: {
text: '#ECEDEE',
background: '#151718',
tint: tintColorDark,
icon: '#9BA1A6',
tabIconDefault: '#9BA1A6',
tabIconSelected: tintColorDark,
},
};

View File

@@ -0,0 +1 @@
export { useColorScheme } from 'react-native';

View File

@@ -0,0 +1,8 @@
// NOTE: The default React Native styling doesn't support server rendering.
// Server rendered styles should not change between the first render of the HTML
// and the first render on the client. Typically, web developers will use CSS media queries
// to render different styles on the client and server, these aren't directly supported in React Native
// but can be achieved using a styling library like Nativewind.
export function useColorScheme() {
return 'light';
}

View File

@@ -0,0 +1,22 @@
/**
* Learn more about light and dark modes:
* https://docs.expo.dev/guides/color-schemes/
*/
import { useColorScheme } from 'react-native';
import { Colors } from '@/constants/Colors';
export function useThemeColor(
props: { light?: string; dark?: string },
colorName: keyof typeof Colors.light & keyof typeof Colors.dark
) {
const theme = useColorScheme() ?? 'light';
const colorFromProps = props[theme];
if (colorFromProps) {
return colorFromProps;
} else {
return Colors[theme][colorName];
}
}

19570
reactNative/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

49
reactNative/package.json Normal file
View File

@@ -0,0 +1,49 @@
{
"name": "reactnativeapp",
"main": "expo-router/entry",
"version": "1.0.0",
"scripts": {
"start": "expo start",
"export": "expo export",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo/vector-icons": "^14.0.0",
"@react-navigation/native": "^6.0.2",
"expo": "~51.0.14",
"expo-constants": "~16.0.2",
"expo-font": "~12.0.7",
"expo-linking": "~6.3.1",
"expo-router": "~3.5.16",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.6",
"expo-web-browser": "~13.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.2",
"react-native-gesture-handler": "~2.16.1",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "4.10.1",
"react-native-screens": "3.31.1",
"react-native-web": "~0.19.10"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/jest": "^29.5.12",
"@types/react": "~18.2.45",
"@types/react-test-renderer": "^18.0.7",
"jest": "^29.2.1",
"jest-expo": "~51.0.1",
"react-test-renderer": "18.2.0",
"typescript": "~5.3.3"
},
"private": true
}

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env node
/**
* This script is used to reset the project to a blank state.
* It moves the /app directory to /app-example and creates a new /app directory with an index.tsx and _layout.tsx file.
* You can remove the `reset-project` script from package.json and safely delete this file after running it.
*/
const fs = require('fs');
const path = require('path');
const root = process.cwd();
const oldDirPath = path.join(root, 'app');
const newDirPath = path.join(root, 'app-example');
const newAppDirPath = path.join(root, 'app');
const indexContent = `import { Text, View } from "react-native";
export default function Index() {
return (
<View
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
}}
>
<Text>Edit app/index.tsx to edit this screen.</Text>
</View>
);
}
`;
const layoutContent = `import { Stack } from "expo-router";
export default function RootLayout() {
return (
<Stack>
<Stack.Screen name="index" />
</Stack>
);
}
`;
fs.rename(oldDirPath, newDirPath, (error) => {
if (error) {
return console.error(`Error renaming directory: ${error}`);
}
console.log('/app moved to /app-example.');
fs.mkdir(newAppDirPath, { recursive: true }, (error) => {
if (error) {
return console.error(`Error creating new app directory: ${error}`);
}
console.log('New /app directory created.');
const indexPath = path.join(newAppDirPath, 'index.tsx');
fs.writeFile(indexPath, indexContent, (error) => {
if (error) {
return console.error(`Error creating index.tsx: ${error}`);
}
console.log('app/index.tsx created.');
const layoutPath = path.join(newAppDirPath, '_layout.tsx');
fs.writeFile(layoutPath, layoutContent, (error) => {
if (error) {
return console.error(`Error creating _layout.tsx: ${error}`);
}
console.log('app/_layout.tsx created.');
});
});
});
});

17
reactNative/tsconfig.json Normal file
View File

@@ -0,0 +1,17 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"paths": {
"@/*": [
"./*"
]
}
},
"include": [
"**/*.ts",
"**/*.tsx",
".expo/types/**/*.ts",
"expo-env.d.ts"
]
}

View File

@@ -1,28 +0,0 @@
package reactNextJS
import (
"embed"
"fmt"
"io/fs"
"net/http"
)
//go:embed "out/*"
var nextFiles embed.FS
//go:embed "out/_next"
var nextScripts embed.FS
// Call this from main once before starting the server
func AddNextStaticClient() {
scriptsSubFolder, err := fs.Sub(nextScripts, "out")
if err != nil {
panic(fmt.Sprint("Error: Could not find \"reactNextJS/out/\". Did you build the reactNextJS client?"))
}
filesSubFolder, _ := fs.Sub(nextFiles, "out")
var nextScriptsServer = http.FileServerFS(scriptsSubFolder)
var nextFilesServer = http.FileServerFS(filesSubFolder)
http.Handle("/reactNextJS/", http.StripPrefix("/reactNextJS/", nextFilesServer))
http.Handle("/_next/", nextScriptsServer)
}

View File

@@ -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,

View File

@@ -3,28 +3,90 @@ package main
import ( import (
"embed" "embed"
"fmt" "fmt"
"frontends/reactNextJS" "html/template"
"io/fs"
"net/http" "net/http"
"os"
) )
const PORT = 3003 const PORT = 3003
//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" //go:embed "vanillaJS"
var vanillaJS embed.FS var vanillaFiles embed.FS
//go:embed "alpinejs"
var alpineFiles embed.FS
//go:embed "react" //go:embed "react"
var react embed.FS var reactFiles embed.FS
//go:embed "reactNextJS/out" //go:embed "all:reactNative/dist"
var nextStatic embed.FS var reactNativeFiles embed.FS
type frontendInfo struct {
Name, Mountpoint string
Filesystem fs.FS
}
var frontends = []frontendInfo{
{"JS Only", "/vanillaJS/", getSubFS(vanillaFiles, "vanillaJS")},
{"Alpine.js", "/alpinejs/", getSubFS(alpineFiles, "alpinejs")},
{"React", "/react/", getSubFS(reactFiles, "react")},
{"React (Next)", "/reactNextJS/", getSubFS(nextFiles, "reactNextJS/out")},
{"React Native", "/reactNative/", getSubFS(reactNativeFiles, "reactNative/dist")},
{"Vue.js", "/vuejs/", getSubFS(vueFiles, "vuejs/dist")},
{"Svelte", "/svelte/", getSubFS(svelteFiles, "svelte/dist")},
}
func getSubFS(f fs.FS, dir string) fs.FS {
files, err := fs.Sub(f, dir)
if err != nil {
panic(err)
}
return files
}
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
}
indexTemplate.Execute(file, frontends)
file.Close()
os.Exit(0)
}
func main() { func main() {
args := os.Args
http.Handle("/vanillaJS/", http.FileServerFS(vanillaJS)) home_template, err := template.ParseFiles("index.tmpl")
http.Handle("/react/", http.FileServerFS(react)) if err != nil {
reactNextJS.AddNextStaticClient() panic(fmt.Sprintf("Error parsing homepage template\n%s", err))
}
err := http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil) if len(args) == 2 && args[1] == "generate" {
outputIndexAndExit(*home_template, frontends)
}
for _, info := range frontends {
fileServer := http.FileServerFS(info.Filesystem)
http.Handle(info.Mountpoint, http.StripPrefix(info.Mountpoint, fileServer))
}
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 { if err != nil {
panic(fmt.Sprintf("Error starting server: %s", err)) panic(fmt.Sprintf("Error starting server: %s", err))
} }

24
svelte/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

3
svelte/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"recommendations": ["svelte.svelte-vscode"]
}

47
svelte/README.md Normal file
View File

@@ -0,0 +1,47 @@
# Svelte + Vite
This template should help get you started developing with Svelte in Vite.
## Recommended IDE Setup
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
## Need an official Svelte framework?
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
## Technical considerations
**Why use this over SvelteKit?**
- It brings its own routing solution which might not be preferable for some users.
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
**Why include `.vscode/extensions.json`?**
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
**Why enable `checkJs` in the JS template?**
It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration.
**Why is HMR not preserving my local component state?**
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state).
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
```js
// store.js
// An extremely simple external store
import { writable } from 'svelte/store'
export default writable(0)
```

13
svelte/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

32
svelte/jsconfig.json Normal file
View File

@@ -0,0 +1,32 @@
{
"compilerOptions": {
"moduleResolution": "bundler",
"target": "ESNext",
"module": "ESNext",
/**
* svelte-preprocess cannot figure out whether you have
* a value or a type, so tell TypeScript to enforce using
* `import type` instead of `import` for Types.
*/
"verbatimModuleSyntax": true,
"isolatedModules": true,
"resolveJsonModule": true,
/**
* To have warnings / errors of the Svelte compiler at the
* correct position, enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types.
*/
"checkJs": true
},
/**
* Use global.d.ts instead of compilerOptions.types
* to avoid limiting type declarations.
*/
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}

1184
svelte/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

16
svelte/package.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "svelte",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"svelte": "^4.2.12",
"vite": "^5.2.0"
}
}

54
svelte/src/App.svelte Normal file
View File

@@ -0,0 +1,54 @@
<script>
import svelteLogo from './assets/svelte.svg'
import viteLogo from './assets/vite.svg'
import Counter from './lib/Counter.svelte'
import Blurb from './lib/Blurb.svelte';
const blurb_data = {
title: "Fart Man Comes To Town!",
blurb: "Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town believe the imminent winds of change will revitalize the towns central business district."
};
let blurbs = [blurb_data];
function addBlurb() {
blurbs = [...blurbs, blurb_data];
}
$: num_blurbs = blurbs.length;
</script>
<main>
<div class="center">
<a href="https://vitejs.dev" target="_blank" rel="noreferrer">
<img src={viteLogo} class="logo" alt="Vite Logo" />
</a>
<a href="https://svelte.dev" target="_blank" rel="noreferrer">
<img src={svelteLogo} class="logo svelte" alt="Svelte Logo" />
</a>
</div>
{#each blurbs as blurb}
<Blurb title={blurb.title} blurb={blurb.blurb} />
{/each}
<br />
<button on:click={addBlurb}>Load More</button>
</main>
<style>
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.svelte:hover {
filter: drop-shadow(0 0 2em #ff3e00aa);
}
.center {
text-align: center;
}
</style>

78
svelte/src/app.css Normal file
View File

@@ -0,0 +1,78 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
.card {
padding: 2em;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,10 @@
<script>
export let title;
export let blurb;
</script>
<div>
<h1>{title}</h1>
<p>{blurb}</p>
<a href="#top">Read more...</a>
</div>

View File

@@ -0,0 +1,10 @@
<script>
let count = 0
const increment = () => {
count += 1
}
</script>
<button on:click={increment}>
count is {count}
</button>

8
svelte/src/main.js Normal file
View File

@@ -0,0 +1,8 @@
import './app.css'
import App from './App.svelte'
const app = new App({
target: document.getElementById('app'),
})
export default app

2
svelte/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />

7
svelte/svelte.config.js Normal file
View File

@@ -0,0 +1,7 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
export default {
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
}

8
svelte/vite.config.js Normal file
View File

@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
base: '/svelte/'
})

14
vuejs/.eslintrc.cjs Normal file
View File

@@ -0,0 +1,14 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}

30
vuejs/.gitignore vendored Normal file
View File

@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo

8
vuejs/.prettierrc.json Normal file
View File

@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}

7
vuejs/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}

35
vuejs/README.md Normal file
View File

@@ -0,0 +1,35 @@
# vuejs
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Compile and Minify for Production
```sh
npm run build
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```

13
vuejs/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

8
vuejs/jsconfig.json Normal file
View File

@@ -0,0 +1,8 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}

3510
vuejs/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
vuejs/package.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "vuejs",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"vue": "^3.4.29"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.8.0",
"@vitejs/plugin-vue": "^5.0.5",
"@vitejs/plugin-vue-jsx": "^4.0.0",
"@vue/eslint-config-prettier": "^9.0.0",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.23.0",
"prettier": "^3.2.5",
"vite": "^5.3.1"
}
}

BIN
vuejs/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

41
vuejs/src/App.vue Normal file
View File

@@ -0,0 +1,41 @@
<script setup>
import { ref } from 'vue'
import Blurb from './components/Blurb.vue'
const blurb_data = {
title: "Fart Man Comes To Town!",
blurb: "Will this controversial figure finally cause the downfall of the town? Sally Smith from town center says that she can already smell trouble brewing but other members of the town believe the imminent winds of change will revitalize the towns central business district."
};
const blurbs = ref([blurb_data])
function addBlurb() {
blurbs.value.push(blurb_data)
}
</script>
<template>
<header>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
</header>
<main>
<div v-for="blurb in blurbs">
<Blurb :title="blurb.title" :blurb="blurb.blurb" link="#" />
<br />
</div>
<br />
<button @click="addBlurb">Load more</button>
</main>
</template>
<style scoped>
header {
line-height: 1.5;
}
.logo {
display: block;
margin: 0 auto 2rem;
}
</style>

86
vuejs/src/assets/base.css Normal file
View File

@@ -0,0 +1,86 @@
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white: #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;
--vt-c-black: #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;
--vt-c-indigo: #2c3e50;
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1: var(--vt-c-white);
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
}
/* semantic color variables for this project */
:root {
--color-background: var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);
--color-border: var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);
--color-heading: var(--vt-c-text-light-1);
--color-text: var(--vt-c-text-light-1);
--section-gap: 160px;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);
--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);
--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
font-weight: normal;
}
body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition:
color 0.5s,
background-color 0.5s;
line-height: 1.6;
font-family:
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
'Helvetica Neue',
sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>

After

Width:  |  Height:  |  Size: 276 B

23
vuejs/src/assets/main.css Normal file
View File

@@ -0,0 +1,23 @@
@import './base.css';
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
font-weight: normal;
}
a,
.green {
text-decoration: none;
color: hsla(160, 100%, 37%, 1);
transition: 0.4s;
padding: 3px;
}
@media (hover: hover) {
a:hover {
background-color: hsla(160, 100%, 37%, 0.2);
}
}

View File

@@ -0,0 +1,25 @@
<script setup>
const props = defineProps(['title', 'blurb', 'link'])
</script>
<template>
<div class="blurb">
<h1 class="green">{{ props.title }}</h1>
<h3>
{{ props.blurb }}
</h3>
<a href="{{ props.link }}">Read more...</a>
</div>
</template>
<style scoped>
h1 {
font-weight: 500;
position: relative;
}
h3 {
font-size: 1.2rem;
}
</style>

6
vuejs/src/main.js Normal file
View File

@@ -0,0 +1,6 @@
import './assets/main.css'
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')

19
vuejs/vite.config.js Normal file
View File

@@ -0,0 +1,19 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
base: '/vuejs/'
})