create-vite-hyperapp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/README.md +1 -0
- package/index.js +154 -0
- package/package.json +19 -0
- package/templates/template/_gitignore +24 -0
- package/templates/template/index.html +13 -0
- package/templates/template/package.json +16 -0
- package/templates/template/public/vite.svg +1 -0
- package/templates/template/src/counter.jsx +7 -0
- package/templates/template/src/hyperapp.svg +4 -0
- package/templates/template/src/main.jsx +35 -0
- package/templates/template/src/run.js +5 -0
- package/templates/template/src/style.css +97 -0
- package/templates/template/vite.config.js +6 -0
- package/templates/template-ssr/_gitignore +24 -0
- package/templates/template-ssr/index.html +13 -0
- package/templates/template-ssr/package.json +23 -0
- package/templates/template-ssr/public/vite.svg +1 -0
- package/templates/template-ssr/server.js +60 -0
- package/templates/template-ssr/src/counter.jsx +7 -0
- package/templates/template-ssr/src/entry-client.js +5 -0
- package/templates/template-ssr/src/entry-server.js +5 -0
- package/templates/template-ssr/src/hyperapp.svg +4 -0
- package/templates/template-ssr/src/main.jsx +35 -0
- package/templates/template-ssr/src/style.css +97 -0
- package/templates/template-ssr/vite.config.js +6 -0
- package/templates/template-ts/_gitignore +24 -0
- package/templates/template-ts/index.html +13 -0
- package/templates/template-ts/package.json +17 -0
- package/templates/template-ts/public/vite.svg +1 -0
- package/templates/template-ts/src/counter.tsx +14 -0
- package/templates/template-ts/src/hyperapp.svg +4 -0
- package/templates/template-ts/src/main.tsx +42 -0
- package/templates/template-ts/src/run.ts +5 -0
- package/templates/template-ts/src/style.css +97 -0
- package/templates/template-ts/src/typescript.svg +1 -0
- package/templates/template-ts/src/vite-env.d.ts +1 -0
- package/templates/template-ts/tsconfig.json +27 -0
- package/templates/template-ts/vite.config.js +6 -0
- package/templates/template-ts-ssr/_gitignore +24 -0
- package/templates/template-ts-ssr/index.html +13 -0
- package/templates/template-ts-ssr/package.json +24 -0
- package/templates/template-ts-ssr/public/vite.svg +1 -0
- package/templates/template-ts-ssr/server.js +60 -0
- package/templates/template-ts-ssr/src/counter.tsx +14 -0
- package/templates/template-ts-ssr/src/entry-client.ts +5 -0
- package/templates/template-ts-ssr/src/entry-server.ts +5 -0
- package/templates/template-ts-ssr/src/hyperapp.svg +4 -0
- package/templates/template-ts-ssr/src/main.tsx +42 -0
- package/templates/template-ts-ssr/src/style.css +97 -0
- package/templates/template-ts-ssr/src/typescript.svg +1 -0
- package/templates/template-ts-ssr/src/vite-env.d.ts +1 -0
- package/templates/template-ts-ssr/tsconfig.json +27 -0
- package/templates/template-ts-ssr/vite.config.js +6 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Zacharias Enochsson
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# create-vite-hyperapp
|
package/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import minimist from "minimist"
|
|
3
|
+
import prompts from "prompts"
|
|
4
|
+
import fs from "node:fs"
|
|
5
|
+
import path from "node:path"
|
|
6
|
+
import { fileURLToPath } from "node:url"
|
|
7
|
+
|
|
8
|
+
const args = minimist(process.argv.slice(2))
|
|
9
|
+
|
|
10
|
+
if (args["h"] || args["help"]) {
|
|
11
|
+
process.stdout.write(`
|
|
12
|
+
Usage: npm create vite-hyperapp -- [TARGET_DIR] [OPTIONS]
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
-t, --typescript Use typescript
|
|
16
|
+
-s, --ssr Use server-side rendering
|
|
17
|
+
-n, --no-prompt Just do it, no questions asked
|
|
18
|
+
-h, --help Show this message
|
|
19
|
+
|
|
20
|
+
If no target dir is specified, the project name will be used.
|
|
21
|
+
If --no-prompt option is used, project name will be target dir
|
|
22
|
+
Default project-name/target-dir is 'hyperapp-project'
|
|
23
|
+
|
|
24
|
+
`)
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function collectOptions() {
|
|
29
|
+
const flaggedTypescript = !!(args["t"] || args["typescript"])
|
|
30
|
+
const flaggedSSR = !!(args["s"] || args["ssr"])
|
|
31
|
+
const givenTargetDir = args._[0]
|
|
32
|
+
const targetDirOrDefault = givenTargetDir || "hyperapp-project"
|
|
33
|
+
if (args["n"] || args["no-prompt"]) {
|
|
34
|
+
return {
|
|
35
|
+
targetDir: targetDirOrDefault,
|
|
36
|
+
projectName: targetDirOrDefault,
|
|
37
|
+
useTypescript: flaggedTypescript,
|
|
38
|
+
useSSR: flaggedSSR,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const promptResponse = await prompts([
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
name: "name",
|
|
45
|
+
initial: targetDirOrDefault,
|
|
46
|
+
message: "Name your project:",
|
|
47
|
+
},
|
|
48
|
+
!flaggedTypescript && {
|
|
49
|
+
type: "confirm",
|
|
50
|
+
name: "typescript",
|
|
51
|
+
message: "Use Typescript?",
|
|
52
|
+
initial: true,
|
|
53
|
+
},
|
|
54
|
+
!flaggedSSR && {
|
|
55
|
+
type: "confirm",
|
|
56
|
+
name: "ssr",
|
|
57
|
+
message: "Use server-side rendering?",
|
|
58
|
+
initial: false,
|
|
59
|
+
},
|
|
60
|
+
])
|
|
61
|
+
return {
|
|
62
|
+
targetDir: givenTargetDir || promptResponse.name,
|
|
63
|
+
projectName: promptResponse.name,
|
|
64
|
+
useTypescript: promptResponse.typescript,
|
|
65
|
+
useSSR: promptResponse.ssr,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function copyDir(source, target) {
|
|
70
|
+
if (fs.existsSync(target)) {
|
|
71
|
+
process.stderr.write(`\n${target} already exists. Aborting!\n`)
|
|
72
|
+
process.exit(1)
|
|
73
|
+
}
|
|
74
|
+
fs.mkdirSync(target, { recursive: true })
|
|
75
|
+
|
|
76
|
+
const items = fs.readdirSync(source)
|
|
77
|
+
items.forEach(item => {
|
|
78
|
+
const sourceItem = path.join(source, item)
|
|
79
|
+
const targetItem = path.join(target, item)
|
|
80
|
+
const stats = fs.statSync(sourceItem)
|
|
81
|
+
|
|
82
|
+
if (stats.isDirectory()) {
|
|
83
|
+
copyDir(sourceItem, targetItem)
|
|
84
|
+
} else {
|
|
85
|
+
fs.copyFileSync(sourceItem, targetItem)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isValidPackageName(projectName) {
|
|
91
|
+
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(
|
|
92
|
+
projectName,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function setPackageName(projectDir, packageName) {
|
|
97
|
+
const packageJsonPath = path.join(projectDir, "package.json")
|
|
98
|
+
const info = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
|
|
99
|
+
info.name = packageName
|
|
100
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(info, null, 2))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function fixGitignoreFilename(projectDir) {
|
|
104
|
+
const currentName = path.join(projectDir, "_gitignore")
|
|
105
|
+
const renameTo = path.join(projectDir, ".gitignore")
|
|
106
|
+
fs.renameSync(currentName, renameTo)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function main() {
|
|
110
|
+
const setup = await collectOptions()
|
|
111
|
+
|
|
112
|
+
if (!isValidPackageName(setup.projectName)) {
|
|
113
|
+
process.stderr.write(
|
|
114
|
+
`\n${setup.projectName} is not a valid package.json name\n`,
|
|
115
|
+
)
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!isValidPackageName(setup.targetDir)) {
|
|
120
|
+
process.stderr.write(`\n${setup.targetDir} is not a valid folder name\n`)
|
|
121
|
+
process.exit(1)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const template = setup.useTypescript
|
|
125
|
+
? setup.useSSR
|
|
126
|
+
? "template-ts-ssr"
|
|
127
|
+
: "template-ts"
|
|
128
|
+
: setup.useSSR
|
|
129
|
+
? "template-ssr"
|
|
130
|
+
: "template"
|
|
131
|
+
|
|
132
|
+
const sourceDir = path.resolve(
|
|
133
|
+
fileURLToPath(import.meta.url),
|
|
134
|
+
"../templates/",
|
|
135
|
+
template,
|
|
136
|
+
)
|
|
137
|
+
const targetDir = path.resolve(process.cwd(), "./" + setup.targetDir)
|
|
138
|
+
|
|
139
|
+
process.stdout.write("Scaffolding project ...")
|
|
140
|
+
copyDir(sourceDir, targetDir)
|
|
141
|
+
setPackageName(targetDir, setup.projectName)
|
|
142
|
+
fixGitignoreFilename(targetDir)
|
|
143
|
+
process.stdout.write(`
|
|
144
|
+
...Done.
|
|
145
|
+
|
|
146
|
+
To get started:
|
|
147
|
+
|
|
148
|
+
> cd ${setup.targetDir}
|
|
149
|
+
> npm install
|
|
150
|
+
> npm run dev
|
|
151
|
+
`)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main()
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-vite-hyperapp",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "\"Scaffold a project quickly with Hyperapp and Vite\"",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"author": "Zacharias Enochsson",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"minimist": "^1.2.8",
|
|
14
|
+
"prompts": "^2.4.2"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"create-vite-hyperapp": "index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
|
|
15
|
+
# Editor directories and files
|
|
16
|
+
.vscode/*
|
|
17
|
+
!.vscode/extensions.json
|
|
18
|
+
.idea
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.suo
|
|
21
|
+
*.ntvs*
|
|
22
|
+
*.njsproj
|
|
23
|
+
*.sln
|
|
24
|
+
*.sw?
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Vite + Hyperapp</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/run.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "demo",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"hyperapp": "^2.0.22",
|
|
13
|
+
"vite": "^4.4.5",
|
|
14
|
+
"vite-plugin-hyperapp": "^1.0.3"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg viewBox="-20 -20 230 160" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
|
|
2
|
+
<rect x="-20" y="-20" width="100%" height="100%" fill="#0080FF" rx="15"/>
|
|
3
|
+
<path d="M69.3175129,49.6122454 L109.331858,49.6122454 L118.942605,69.3176912 L69.3175129,69.3176912 L69.3175129,118.931378 L49.6154815,118.931378 L49.6154815,69.3176912 L0,69.3176912 L0,49.6122454 L49.6154815,49.6122454 L49.6154815,0 L69.3175129,0 L69.3175129,49.6122454 Z M192.738726,118.931378 L169.523967,118.931378 L111.518303,0 L134.733062,0 L192.738726,118.931378 Z" fill="#FFFFFF" fill-rule="nonzero"></path>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "./style.css"
|
|
2
|
+
import hyperappLogo from "./hyperapp.svg"
|
|
3
|
+
import viteLogo from "/vite.svg"
|
|
4
|
+
import Counter from "./counter"
|
|
5
|
+
|
|
6
|
+
export const init = () => ({
|
|
7
|
+
counter: 0,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const HandleClick = state => ({
|
|
11
|
+
...state,
|
|
12
|
+
counter: state.counter + 1,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const Logos = () => (
|
|
16
|
+
<>
|
|
17
|
+
<a href="https://vitejs.dev">
|
|
18
|
+
<img src={viteLogo} class="logo" alt="Vite logo" />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://hyperapp.dev/">
|
|
21
|
+
<img src={hyperappLogo} class="logo vanilla" alt="Hyperapp logo" />
|
|
22
|
+
</a>
|
|
23
|
+
</>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export const view = state => (
|
|
27
|
+
<main id="app">
|
|
28
|
+
<h1>Vite + Hyperapp</h1>
|
|
29
|
+
<Logos />
|
|
30
|
+
<Counter clicks={state.counter} onclick={HandleClick} />
|
|
31
|
+
<p class="read-the-docs">
|
|
32
|
+
Click on the Vite & Hyperapp logos to learn more
|
|
33
|
+
</p>
|
|
34
|
+
</main>
|
|
35
|
+
)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
-webkit-text-size-adjust: 100%;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
a {
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
color: #646cff;
|
|
20
|
+
text-decoration: inherit;
|
|
21
|
+
}
|
|
22
|
+
a:hover {
|
|
23
|
+
color: #535bf2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
body {
|
|
27
|
+
margin: 0;
|
|
28
|
+
display: flex;
|
|
29
|
+
place-items: center;
|
|
30
|
+
min-width: 320px;
|
|
31
|
+
min-height: 100vh;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
h1 {
|
|
35
|
+
font-size: 3.2em;
|
|
36
|
+
line-height: 1.1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#app {
|
|
40
|
+
max-width: 1280px;
|
|
41
|
+
margin: 0 auto;
|
|
42
|
+
padding: 2rem;
|
|
43
|
+
text-align: center;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.logo {
|
|
47
|
+
height: 6em;
|
|
48
|
+
padding: 1.5em;
|
|
49
|
+
will-change: filter;
|
|
50
|
+
transition: filter 300ms;
|
|
51
|
+
}
|
|
52
|
+
.logo:hover {
|
|
53
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
54
|
+
}
|
|
55
|
+
.logo.vanilla:hover {
|
|
56
|
+
filter: drop-shadow(0 0 2em #3178c6aa);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.card {
|
|
60
|
+
padding: 2em;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.read-the-docs {
|
|
64
|
+
color: #888;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
button {
|
|
68
|
+
border-radius: 8px;
|
|
69
|
+
border: 1px solid transparent;
|
|
70
|
+
padding: 0.6em 1.2em;
|
|
71
|
+
font-size: 1em;
|
|
72
|
+
font-weight: 500;
|
|
73
|
+
font-family: inherit;
|
|
74
|
+
background-color: #1a1a1a;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
transition: border-color 0.25s;
|
|
77
|
+
}
|
|
78
|
+
button:hover {
|
|
79
|
+
border-color: #646cff;
|
|
80
|
+
}
|
|
81
|
+
button:focus,
|
|
82
|
+
button:focus-visible {
|
|
83
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@media (prefers-color-scheme: light) {
|
|
87
|
+
:root {
|
|
88
|
+
color: #213547;
|
|
89
|
+
background-color: #ffffff;
|
|
90
|
+
}
|
|
91
|
+
a:hover {
|
|
92
|
+
color: #747bff;
|
|
93
|
+
}
|
|
94
|
+
button {
|
|
95
|
+
background-color: #f9f9f9;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
|
|
10
|
+
node_modules
|
|
11
|
+
dist
|
|
12
|
+
dist-ssr
|
|
13
|
+
*.local
|
|
14
|
+
|
|
15
|
+
# Editor directories and files
|
|
16
|
+
.vscode/*
|
|
17
|
+
!.vscode/extensions.json
|
|
18
|
+
.idea
|
|
19
|
+
.DS_Store
|
|
20
|
+
*.suo
|
|
21
|
+
*.ntvs*
|
|
22
|
+
*.njsproj
|
|
23
|
+
*.sln
|
|
24
|
+
*.sw?
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Vite (SSR) + Hyperapp</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<!--ssr-outlet-->
|
|
11
|
+
<script type="module" src="/src/entry-client.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "demo",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "node server",
|
|
8
|
+
"build:client": "vite build --outDir dist/client",
|
|
9
|
+
"build:server": "vite build --outDir dist/server --ssr src/entry-server.js",
|
|
10
|
+
"build": "npm run build:client && npm run build:server",
|
|
11
|
+
"preview": "NODE_ENV=production node server"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"hyperapp": "^2.0.22",
|
|
15
|
+
"vite": "^4.4.5",
|
|
16
|
+
"vite-plugin-hyperapp": "^1.0.3"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"compression": "^1.7.4",
|
|
20
|
+
"express": "^4.19.2",
|
|
21
|
+
"sirv": "^2.0.4"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------
|
|
3
|
+
Cribbed to large extent from template-ssr-solid/server.js
|
|
4
|
+
---------------------------------
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs/promises"
|
|
7
|
+
import express from "express"
|
|
8
|
+
|
|
9
|
+
const isProduction = process.env.NODE_ENV === "production"
|
|
10
|
+
const port = process.env.PORT || 5173
|
|
11
|
+
const base = process.env.BASE || "/"
|
|
12
|
+
|
|
13
|
+
async function createServer() {
|
|
14
|
+
const app = express()
|
|
15
|
+
|
|
16
|
+
let vite
|
|
17
|
+
if (!isProduction) {
|
|
18
|
+
const { createServer } = await import("vite")
|
|
19
|
+
vite = await createServer({
|
|
20
|
+
server: { middlewareMode: true },
|
|
21
|
+
appType: "custom",
|
|
22
|
+
base,
|
|
23
|
+
})
|
|
24
|
+
app.use(vite.middlewares)
|
|
25
|
+
} else {
|
|
26
|
+
const compression = (await import("compression")).default
|
|
27
|
+
const sirv = (await import("sirv")).default
|
|
28
|
+
app.use(compression())
|
|
29
|
+
app.use(base, sirv("./dist/client", { extensions: [] }))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
app.use("*", async (req, res) => {
|
|
33
|
+
const url = req.originalUrl.replace(base, "")
|
|
34
|
+
try {
|
|
35
|
+
let template
|
|
36
|
+
let render
|
|
37
|
+
if (!isProduction) {
|
|
38
|
+
// Always read fresh template in development
|
|
39
|
+
template = await fs.readFile("./index.html", "utf-8")
|
|
40
|
+
template = await vite.transformIndexHtml(url, template)
|
|
41
|
+
render = (await vite.ssrLoadModule("/src/entry-server.js")).render
|
|
42
|
+
} else {
|
|
43
|
+
template = await fs.readFile("./dist/client/index.html", "utf-8")
|
|
44
|
+
render = (await import("./dist/server/entry-server.js")).render
|
|
45
|
+
}
|
|
46
|
+
const html = template.replace(`<!--ssr-outlet-->`, await render())
|
|
47
|
+
res.status(200).set({ "Content-Type": "text/html" }).end(html)
|
|
48
|
+
} catch (e) {
|
|
49
|
+
vite?.ssrFixStacktrace(e)
|
|
50
|
+
console.log(e.stack)
|
|
51
|
+
res.status(500).end(e.stack)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
app.listen(port, () => {
|
|
56
|
+
console.log(`Server started at http://localhost:${port}`)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
createServer()
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg viewBox="-20 -20 230 160" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
|
|
2
|
+
<rect x="-20" y="-20" width="100%" height="100%" fill="#0080FF" rx="15"/>
|
|
3
|
+
<path d="M69.3175129,49.6122454 L109.331858,49.6122454 L118.942605,69.3176912 L69.3175129,69.3176912 L69.3175129,118.931378 L49.6154815,118.931378 L49.6154815,69.3176912 L0,69.3176912 L0,49.6122454 L49.6154815,49.6122454 L49.6154815,0 L69.3175129,0 L69.3175129,49.6122454 Z M192.738726,118.931378 L169.523967,118.931378 L111.518303,0 L134.733062,0 L192.738726,118.931378 Z" fill="#FFFFFF" fill-rule="nonzero"></path>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "./style.css"
|
|
2
|
+
import hyperappLogo from "./hyperapp.svg"
|
|
3
|
+
import viteLogo from "/vite.svg"
|
|
4
|
+
import Counter from "./counter"
|
|
5
|
+
|
|
6
|
+
export const init = () => ({
|
|
7
|
+
counter: 0,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const HandleClick = state => ({
|
|
11
|
+
...state,
|
|
12
|
+
counter: state.counter + 1,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const Logos = () => (
|
|
16
|
+
<>
|
|
17
|
+
<a href="https://vitejs.dev">
|
|
18
|
+
<img src={viteLogo} class="logo" alt="Vite logo" />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://hyperapp.dev/">
|
|
21
|
+
<img src={hyperappLogo} class="logo vanilla" alt="Hyperapp logo" />
|
|
22
|
+
</a>
|
|
23
|
+
</>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export const view = state => (
|
|
27
|
+
<main id="app">
|
|
28
|
+
<h1>Vite (SSR) + Hyperapp</h1>
|
|
29
|
+
<Logos />
|
|
30
|
+
<Counter clicks={state.counter} onclick={HandleClick} />
|
|
31
|
+
<p class="read-the-docs">
|
|
32
|
+
Click on the Vite & Hyperapp logos to learn more
|
|
33
|
+
</p>
|
|
34
|
+
</main>
|
|
35
|
+
)
|