resuxjs 0.3.3 → 0.3.4
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/README.md +150 -892
- package/dist/cli.js +4 -3
- package/dist/cli.js.map +1 -1
- package/dist/compiler/implementation.js +12 -4
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/config.d.ts +9 -0
- package/dist/core/config.js +16 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/hooks.js +4 -1
- package/dist/core/hooks.js.map +1 -1
- package/dist/create.js +34 -1
- package/dist/create.js.map +1 -1
- package/dist/deploy/common.js +9 -5
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/vercel.js +35 -9
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.d.ts +3 -0
- package/dist/halal-core/ai/classifyRuntimeContent.js +123 -0
- package/dist/halal-core/ai/classifyRuntimeContent.js.map +1 -0
- package/dist/halal-core/index.d.ts +2 -0
- package/dist/halal-core/index.js +2 -0
- package/dist/halal-core/index.js.map +1 -1
- package/dist/halal-core/runtime/guard.d.ts +19 -0
- package/dist/halal-core/runtime/guard.js +203 -0
- package/dist/halal-core/runtime/guard.js.map +1 -0
- package/dist/halal-core/runtime/index.d.ts +4 -0
- package/dist/halal-core/runtime/index.js +5 -0
- package/dist/halal-core/runtime/index.js.map +1 -0
- package/dist/halal-core/runtime/reviewedMemory.d.ts +5 -0
- package/dist/halal-core/runtime/reviewedMemory.js +131 -0
- package/dist/halal-core/runtime/reviewedMemory.js.map +1 -0
- package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +13 -0
- package/dist/halal-core/runtime/serializeRuntimeContent.js +170 -0
- package/dist/halal-core/runtime/serializeRuntimeContent.js.map +1 -0
- package/dist/halal-core/runtime/types.d.ts +57 -0
- package/dist/halal-core/runtime/types.js +2 -0
- package/dist/halal-core/runtime/types.js.map +1 -0
- package/dist/halal.d.ts +1 -0
- package/dist/halal.js +2 -0
- package/dist/halal.js.map +1 -0
- package/dist/i18n/index.js +3 -3
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.js +15 -11
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +6 -6
- package/dist/kit/index.js +6 -11
- package/dist/kit/index.js.map +1 -1
- package/dist/reactivity/reactive.js +5 -1
- package/dist/reactivity/reactive.js.map +1 -1
- package/dist/reactivity/scheduler.js +13 -1
- package/dist/reactivity/scheduler.js.map +1 -1
- package/dist/runtime/index.js +334 -42
- package/dist/runtime/index.js.map +1 -1
- package/dist/ui/index.d.ts +29 -16
- package/dist/ui/index.js +274 -258
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,272 +1,218 @@
|
|
|
1
1
|
# Resux
|
|
2
2
|
|
|
3
|
-
Resux
|
|
3
|
+
**Resux** stands for **Resumability + User Experience (UX)**.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Resux is an experimental HTML-first web framework with a custom resumable runtime. It uses familiar `.vue` files and file-based routing, but normal Resux components do **not** use Vue hydration or the Vue runtime. The compiler renders HTML on the server, serializes the state needed to continue, and loads browser handler code when interaction actually needs it.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
📖 **Documentation:** https://mahmoudabdalrhmanmohamed.github.io/resux-docs/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Why Resux
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Resux is centered on explicit runtime cost:
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
- server-render useful HTML first;
|
|
14
|
+
- preserve serializable state for resumability;
|
|
15
|
+
- load event-handler/client code on interaction instead of hydrating every normal component;
|
|
16
|
+
- use progressive client enhancements when server HTML can remain useful first;
|
|
17
|
+
- use Vue islands only when a widget genuinely needs a Vue component/runtime subtree;
|
|
18
|
+
- keep server-only, client-only, and progressive package boundaries explicit.
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
npx resuxjs@latest init
|
|
17
|
-
```
|
|
20
|
+
The documentation explains these boundaries in detail rather than describing Resux as a normal Vue SSR framework.
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
## Create an app
|
|
20
23
|
|
|
21
24
|
```sh
|
|
22
|
-
npx create-resuxjs@latest
|
|
25
|
+
npx create-resuxjs@latest my-app
|
|
26
|
+
cd my-app
|
|
27
|
+
npm install
|
|
28
|
+
npm run dev
|
|
23
29
|
```
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
You can also scaffold through the framework CLI:
|
|
26
32
|
|
|
27
33
|
```sh
|
|
28
34
|
npx resuxjs@latest init my-app
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
Current framework source requires Node.js `>=20.19.0`.
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
npx resuxjs@latest init my-app --no-install
|
|
35
|
-
```
|
|
39
|
+
## A normal Resux component
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
npx resuxjs@latest init my-app --features i18n,pwa
|
|
41
|
-
```
|
|
41
|
+
```vue
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
const count = ref(0)
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
function increment() {
|
|
46
|
+
count.value++
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
<template>
|
|
51
|
+
<button @click="increment">
|
|
52
|
+
Count: {{ count }}
|
|
53
|
+
</button>
|
|
54
|
+
</template>
|
|
47
55
|
```
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
The normal Resux path is compiled into server HTML, serialized state, and resumable event-handler modules. It is not automatically turned into a Vue-hydrated component.
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"resuxjs": "^<current-version>"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
```
|
|
59
|
+
## Main framework areas
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
The documentation site is the authoritative deep reference for:
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
- compiler and supported SFC/template syntax;
|
|
64
|
+
- SSR, resumability, state, handlers, and client navigation;
|
|
65
|
+
- pages, layouts, middleware, plugins, server routes, modules, hooks, and route rules;
|
|
66
|
+
- data fetching, runtime config, SEO/head APIs, error handling, and TypeScript;
|
|
67
|
+
- third-party package modes and progressive client enhancements;
|
|
68
|
+
- first-party images/video media primitives;
|
|
69
|
+
- optional UI, icon, font, i18n, and Vue-island features;
|
|
70
|
+
- CLI, inspection/check commands, deployment, security, testing, release flow, and Halal Core;
|
|
71
|
+
- public package exports and API references.
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
Start with the **Framework Tour**, then use the API/reference sections for exact contracts.
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
cd my-app
|
|
72
|
-
npm install
|
|
73
|
-
npm run dev
|
|
74
|
-
```
|
|
75
|
+
## First-party images and video
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
`ResuxImg`, `ResuxPicture`, and `ResuxVideo` are handled by the Resux renderer. They are **not** `resuxjs/ui` Vue components.
|
|
77
78
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
templates/ Starter files copied by `resux init`
|
|
88
|
-
tests/ Compiler, SSR, and client resume tests
|
|
79
|
+
```vue
|
|
80
|
+
<ResuxImg
|
|
81
|
+
src="/images/hero.jpg"
|
|
82
|
+
alt="Product dashboard"
|
|
83
|
+
width="1200"
|
|
84
|
+
height="675"
|
|
85
|
+
sizes="100vw"
|
|
86
|
+
priority
|
|
87
|
+
/>
|
|
89
88
|
```
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
The media runtime supports responsive image candidates, image transformation URLs/providers, placeholders, lazy/priority behavior, preloads, picture sources, video loading strategies, and optional image/video transformation paths. Image transformation uses Sharp; video transformation uses FFmpeg when requested.
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
import { renderApp } from "resuxjs/runtime"
|
|
95
|
-
import { createResuxNodeHandler } from "resuxjs/node"
|
|
96
|
-
```
|
|
92
|
+
Deep reference: https://mahmoudabdalrhmanmohamed.github.io/resux-docs/media/
|
|
97
93
|
|
|
98
|
-
|
|
94
|
+
## UI components (`resuxjs/ui`)
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
The UI package is optional and Vue-owned. Its public `Rx*` components (with matching `Resux*` aliases) belong inside a Vue island or another explicit Vue runtime boundary.
|
|
101
97
|
|
|
102
|
-
|
|
98
|
+
```vue
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
import { ref } from 'vue'
|
|
101
|
+
import { RxButton, RxModal } from 'resuxjs/ui'
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
{ code: "ar", name: "العربية", dir: "rtl" }
|
|
114
|
-
],
|
|
115
|
-
messages: {
|
|
116
|
-
en: () => import("./locales/en.json"),
|
|
117
|
-
ar: () => import("./locales/ar.json")
|
|
118
|
-
},
|
|
119
|
-
seo: {
|
|
120
|
-
hreflang: true
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
})
|
|
103
|
+
const open = ref(false)
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<template>
|
|
107
|
+
<RxButton @click="open = true">Open</RxButton>
|
|
108
|
+
<RxModal v-model:open="open" title="Details">
|
|
109
|
+
Vue-owned modal content
|
|
110
|
+
</RxModal>
|
|
111
|
+
</template>
|
|
124
112
|
```
|
|
125
113
|
|
|
126
|
-
|
|
114
|
+
The package also exports `defineUiTokens()`, `isReducedMotion()`, `useAnimate()`, and the Vue directives `vAnime` / `vAnimate`.
|
|
127
115
|
|
|
128
|
-
|
|
129
|
-
import { useI18n } from "resuxjs/i18n"
|
|
116
|
+
Important current limits are documented per component. For example, component names do not imply unimplemented behavior: `RxReveal` currently animates on mount rather than viewport visibility, and `RxAutoAnimate` currently performs one mount animation rather than mutation-aware layout animation.
|
|
130
117
|
|
|
131
|
-
|
|
132
|
-
const title = i18n.t("demo.title")
|
|
133
|
-
const toArabic = i18n.switchLocalePath("ar")
|
|
134
|
-
```
|
|
118
|
+
Component catalog: https://mahmoudabdalrhmanmohamed.github.io/resux-docs/components/
|
|
135
119
|
|
|
136
120
|
## Icons (`resuxjs/icons`)
|
|
137
121
|
|
|
138
|
-
The
|
|
139
|
-
|
|
140
|
-
```ts
|
|
141
|
-
export default defineResuxConfig({
|
|
142
|
-
modules: [
|
|
143
|
-
["resuxjs/icons", {
|
|
144
|
-
component: "Icon",
|
|
145
|
-
mode: "svg",
|
|
146
|
-
apiProvider: "https://api.iconify.design",
|
|
147
|
-
collections: ["material-symbols", "mdi", "mingcute", "cib", "uil", "line-md", "solar", "ph"],
|
|
148
|
-
lazy: true
|
|
149
|
-
}]
|
|
150
|
-
]
|
|
151
|
-
})
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Use `<Icon>` or `<ResuxIcon>` natively in templates without manual imports:
|
|
122
|
+
The icons package provides a **Vue SVG icon component**, a mutable local SVG-path registry, and optional client-side Iconify-compatible remote fetching.
|
|
155
123
|
|
|
156
124
|
```vue
|
|
157
|
-
<
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
<!-- Dynamic Iconify Icon -->
|
|
162
|
-
<Icon name="ph:check-circle-thin" size="2rem" />
|
|
125
|
+
<script setup lang="ts">
|
|
126
|
+
import { Icon } from 'resuxjs/icons'
|
|
127
|
+
</script>
|
|
163
128
|
|
|
164
|
-
|
|
165
|
-
<Icon name="
|
|
129
|
+
<template>
|
|
130
|
+
<Icon name="check" />
|
|
131
|
+
<Icon name="ph:check-circle" lazy />
|
|
166
132
|
</template>
|
|
167
133
|
```
|
|
168
134
|
|
|
135
|
+
Current module defaults include `collections: []`, `mode: 'svg'`, component name `Icon`, and `lazy: false`. Local registry entries can render without a remote request; unknown remote icons resolve on the client. `collections` does not automatically mean entire icon collections are pre-bundled.
|
|
136
|
+
|
|
137
|
+
Deep reference: https://mahmoudabdalrhmanmohamed.github.io/resux-docs/icons/
|
|
138
|
+
|
|
169
139
|
## Fonts (`resuxjs/fonts`)
|
|
170
140
|
|
|
171
|
-
The
|
|
141
|
+
The first-party fonts module is currently a **Google Fonts stylesheet loader**. It supports configured families/weights, `font-display`, preconnect, and eager/preload/lazy loading strategies.
|
|
172
142
|
|
|
173
143
|
```ts
|
|
174
144
|
export default defineResuxConfig({
|
|
175
145
|
modules: [
|
|
176
|
-
[
|
|
177
|
-
preconnect: true,
|
|
178
|
-
strategy: "lazy",
|
|
179
|
-
deferUntilPageLoad: true,
|
|
146
|
+
['resuxjs/fonts', {
|
|
180
147
|
google: [
|
|
181
|
-
{
|
|
182
|
-
|
|
148
|
+
{
|
|
149
|
+
name: 'Inter',
|
|
150
|
+
weights: ['100..900'],
|
|
151
|
+
display: 'swap'
|
|
152
|
+
}
|
|
183
153
|
]
|
|
184
154
|
}]
|
|
185
155
|
]
|
|
186
156
|
})
|
|
187
157
|
```
|
|
188
158
|
|
|
189
|
-
|
|
159
|
+
It does not currently implement local font discovery, self-host/download management, provider plugins, generated `@font-face`, fallback metric generation, or CSS-variable generation.
|
|
160
|
+
|
|
161
|
+
Deep reference: https://mahmoudabdalrhmanmohamed.github.io/resux-docs/fonts/
|
|
162
|
+
|
|
163
|
+
## i18n (`resuxjs/i18n`)
|
|
190
164
|
|
|
191
|
-
|
|
165
|
+
Internationalization is opt-in:
|
|
192
166
|
|
|
193
167
|
```ts
|
|
194
168
|
export default defineResuxConfig({
|
|
195
|
-
modules: [
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
169
|
+
modules: ['resuxjs/i18n'],
|
|
170
|
+
i18n: {
|
|
171
|
+
defaultLocale: 'en',
|
|
172
|
+
fallbackLocale: 'en',
|
|
173
|
+
strategy: 'prefix_except_default',
|
|
174
|
+
locales: [
|
|
175
|
+
{ code: 'en', name: 'English', dir: 'ltr' },
|
|
176
|
+
{ code: 'ar', name: 'العربية', dir: 'rtl' }
|
|
177
|
+
],
|
|
178
|
+
messages: {
|
|
179
|
+
en: () => import('./locales/en.json'),
|
|
180
|
+
ar: () => import('./locales/ar.json')
|
|
181
|
+
}
|
|
182
|
+
}
|
|
206
183
|
})
|
|
207
184
|
```
|
|
208
185
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
```vue
|
|
212
|
-
<template>
|
|
213
|
-
<div v-anime="'fade-up'">
|
|
214
|
-
<h2>Title</h2>
|
|
215
|
-
</div>
|
|
216
|
-
|
|
217
|
-
<button v-anime="{ type: 'scale-in', duration: 400, delay: 100 }">
|
|
218
|
-
Animate Me
|
|
219
|
-
</button>
|
|
220
|
-
</template>
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Halal Core integrity keys
|
|
224
|
-
|
|
225
|
-
Local reports use a deterministic `sha256:` checksum when no key is configured. Production server and deployment guards require authenticated HMAC reports. Configure private keys with at least 32 characters before building production artifacts:
|
|
226
|
-
|
|
227
|
-
```sh
|
|
228
|
-
export RESUX_HALAL_REPORT_SIGNING_SECRET="replace-with-a-private-random-secret"
|
|
229
|
-
export RESUX_HALAL_REVIEW_SIGNING_SECRET="replace-with-a-different-private-random-secret"
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
Do not commit these values. The report key signs the complete generated report; the review key authenticates human review approval files. Optional remote AI classification also requires an HTTPS endpoint (localhost HTTP is allowed for development) and supports `RESUX_AI_TIMEOUT_MS`.
|
|
186
|
+
See the documentation for routing strategy, translation helpers, locale switching, and SEO/hreflang behavior.
|
|
233
187
|
|
|
234
|
-
##
|
|
188
|
+
## Public package entry points
|
|
235
189
|
|
|
236
|
-
|
|
237
|
-
npm install
|
|
238
|
-
npm run typecheck
|
|
239
|
-
npm run build
|
|
240
|
-
npm test
|
|
241
|
-
npm run test:templates
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
Run the full publish-readiness check:
|
|
245
|
-
|
|
246
|
-
```sh
|
|
247
|
-
npm run pack:check
|
|
248
|
-
```
|
|
190
|
+
Resux separates browser/runtime and build/server concerns through package exports, including:
|
|
249
191
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
192
|
+
```txt
|
|
193
|
+
resuxjs
|
|
194
|
+
resuxjs/runtime
|
|
195
|
+
resuxjs/reactivity
|
|
196
|
+
resuxjs/compiler
|
|
197
|
+
resuxjs/create
|
|
198
|
+
resuxjs/i18n
|
|
199
|
+
resuxjs/ui
|
|
200
|
+
resuxjs/icons
|
|
201
|
+
resuxjs/fonts
|
|
202
|
+
resuxjs/kit
|
|
203
|
+
resuxjs/core
|
|
204
|
+
resuxjs/halal
|
|
205
|
+
resuxjs/node
|
|
206
|
+
resuxjs/globals
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Use the focused package entry point when it keeps server/compiler code out of client-facing code or makes an optional feature boundary explicit.
|
|
210
|
+
|
|
211
|
+
Package/API coverage: https://mahmoudabdalrhmanmohamed.github.io/resux-docs/reference/coverage
|
|
266
212
|
|
|
267
213
|
## CLI
|
|
268
214
|
|
|
269
|
-
|
|
215
|
+
Common commands include:
|
|
270
216
|
|
|
271
217
|
```sh
|
|
272
218
|
resux init <project-dir>
|
|
@@ -280,714 +226,26 @@ resux check <app-root>
|
|
|
280
226
|
resux deploy <app-root>
|
|
281
227
|
```
|
|
282
228
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Starter templates are selectable from `resux init` / `npm create resuxjs@latest`:
|
|
286
|
-
|
|
287
|
-
```sh
|
|
288
|
-
npx create-resuxjs@latest my-app --template default
|
|
289
|
-
# templates: minimal, default, full, i18n, pwa, media, package-compatibility, dashboard
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
Useful server flags:
|
|
293
|
-
|
|
294
|
-
```sh
|
|
295
|
-
resux dev --port 4000
|
|
296
|
-
resux preview --host 0.0.0.0 --port 4000
|
|
297
|
-
resux start --host 0.0.0.0 --port 3000
|
|
298
|
-
resux inspect
|
|
299
|
-
resux inspect --json
|
|
300
|
-
resux inspect routes
|
|
301
|
-
resux inspect packages
|
|
302
|
-
resux inspect bundles --json
|
|
303
|
-
resux inspect seo --json
|
|
304
|
-
resux check
|
|
305
|
-
resux check --json
|
|
306
|
-
resux check --fix
|
|
307
|
-
resux prepare
|
|
308
|
-
resux deploy . --preset docker
|
|
309
|
-
resux deploy . --preset nitro
|
|
310
|
-
resux --help
|
|
311
|
-
resux --version
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
Build output is written to:
|
|
315
|
-
|
|
316
|
-
```txt
|
|
317
|
-
<app-root>/.resux
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
Generated integration directories are bootstrapped automatically by `resux dev`, `resux build`, `resux preview`, `resux prepare`, and `resux check --fix`:
|
|
321
|
-
|
|
322
|
-
```txt
|
|
323
|
-
<app-root>/.resux
|
|
324
|
-
<app-root>/.resux-nitro
|
|
325
|
-
<app-root>/.nitro
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
## App Types
|
|
329
|
-
|
|
330
|
-
Generated apps include `env.d.ts` and `tsconfig.json` wired to `resuxjs/globals`, so app files can use the Resux-style globals without imports:
|
|
331
|
-
|
|
332
|
-
```ts
|
|
333
|
-
const count = useState("count", () => 0)
|
|
334
|
-
const route = useRoute()
|
|
335
|
-
const router = useRouter()
|
|
336
|
-
useSeoMeta({
|
|
337
|
-
title: "My App",
|
|
338
|
-
description: "My app description",
|
|
339
|
-
ogTitle: "My App"
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
function openAbout() {
|
|
343
|
-
router.push("/about")
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export default defineResuxConfig({
|
|
347
|
-
app: {
|
|
348
|
-
head: {
|
|
349
|
-
title: "My App"
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
})
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## Reactivity APIs
|
|
356
|
-
|
|
357
|
-
Resux includes a native reactivity layer for resumable components. You can use it with globals in app files, or import directly:
|
|
358
|
-
|
|
359
|
-
```ts
|
|
360
|
-
import {
|
|
361
|
-
ref,
|
|
362
|
-
reactive,
|
|
363
|
-
computed,
|
|
364
|
-
watch,
|
|
365
|
-
watchEffect,
|
|
366
|
-
readonly,
|
|
367
|
-
toRef,
|
|
368
|
-
toRefs,
|
|
369
|
-
unref,
|
|
370
|
-
isRef,
|
|
371
|
-
isReactive,
|
|
372
|
-
isReadonly,
|
|
373
|
-
nextTick
|
|
374
|
-
} from "resuxjs"
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
Or from the focused subpath:
|
|
378
|
-
|
|
379
|
-
```ts
|
|
380
|
-
import { ref, reactive, computed } from "resuxjs/reactivity"
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
These APIs are Resux-native. Normal Resux components do not depend on Vue hydration runtime.
|
|
384
|
-
|
|
385
|
-
## Vite
|
|
386
|
-
|
|
387
|
-
Resux uses Vite in both main app commands:
|
|
388
|
-
|
|
389
|
-
- `resux dev` emits Resux client modules into `.resux/vite-client` and serves the resume runtime plus handler modules through Vite middleware.
|
|
390
|
-
- `resux dev` also opens a dev-only update channel at `/__resux/dev-events`; when source files change, Resux rebuilds and reloads the browser so route, template, and style changes are visible without restarting the dev server.
|
|
391
|
-
- `resux build` uses Vite production bundling for the resume runtime, handler chunks, and server manifest, then writes optimized output into `.resux/client` and `.resux/server-bundle` before producing a Nitro `.output` server.
|
|
392
|
-
|
|
393
|
-
The generated starter keeps Resux-style scripts:
|
|
394
|
-
|
|
395
|
-
```json
|
|
396
|
-
{
|
|
397
|
-
"scripts": {
|
|
398
|
-
"prepare": "resux prepare",
|
|
399
|
-
"dev": "resux dev",
|
|
400
|
-
"build": "resux build",
|
|
401
|
-
"preview": "resux preview",
|
|
402
|
-
"start": "resux start",
|
|
403
|
-
"inspect": "resux inspect",
|
|
404
|
-
"typecheck": "vue-tsc --noEmit"
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
Tailwind can stay Nuxt-style simple too. If your app has `assets/css/tailwind.css` and `tailwindcss` installed, `resux dev` automatically runs Tailwind in watch mode and `resux build` generates a minified `public/tailwind.css` before bundling. No separate `concurrently` script is required.
|
|
410
|
-
|
|
411
|
-
## Deployment
|
|
412
|
-
|
|
413
|
-
Build and serve with the Node server:
|
|
414
|
-
|
|
415
|
-
```sh
|
|
416
|
-
npm run build
|
|
417
|
-
npm run start
|
|
418
|
-
```
|
|
229
|
+
Run `resux --help` and the CLI reference for the complete current options instead of relying on README snippets for every flag.
|
|
419
230
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
```sh
|
|
423
|
-
resux start . --no-security-headers
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
Generated apps include a `Dockerfile`, `.dockerignore`, and `DEPLOYMENT.md`. Use `resux inspect --json` in CI to capture the built routes, server handlers, route rules, feature flags, and diagnostics.
|
|
427
|
-
|
|
428
|
-
Existing apps can generate or refresh deployment files without changing application code:
|
|
429
|
-
|
|
430
|
-
```sh
|
|
431
|
-
resux deploy . --preset node
|
|
432
|
-
resux deploy . --preset docker --force
|
|
433
|
-
resux deploy . --preset nitro --force
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
The Nitro preset writes `nitro.config.ts` and a small `.resux-nitro/handler.ts` adapter. `resux build` now produces Nuxt-style `.output` by default:
|
|
231
|
+
## Development
|
|
437
232
|
|
|
438
233
|
```sh
|
|
234
|
+
npm install
|
|
235
|
+
npm run typecheck
|
|
439
236
|
npm run build
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
The generated Nitro config is conservative for resumability: SSR pages, API routes, and route payloads use `cache-control: no-store`, while build-stable Resux runtime and handler assets use long immutable caching. Nitro prerender crawling is disabled by default.
|
|
444
|
-
|
|
445
|
-
Deployment target selection is automatic by default (`deploy.target = "auto"`). Resux resolves target/preset from:
|
|
446
|
-
|
|
447
|
-
- explicit `deploy.target` / `deploy.nitroPreset` in `resux.config.ts`
|
|
448
|
-
- `NITRO_PRESET` / `RESUX_NITRO_PRESET`
|
|
449
|
-
- provider environment variables
|
|
450
|
-
- project build config detection (`vercel.json`, `netlify.toml`, `wrangler.*`)
|
|
451
|
-
- package scripts heuristics
|
|
452
|
-
|
|
453
|
-
You can pin target behavior explicitly:
|
|
454
|
-
|
|
455
|
-
```ts
|
|
456
|
-
export default defineResuxConfig({
|
|
457
|
-
deploy: {
|
|
458
|
-
target: "vercel", // "auto" | "node" | "netlify" | "cloudflare" | "static"
|
|
459
|
-
nitroPreset: "vercel"
|
|
460
|
-
}
|
|
461
|
-
})
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
Cloudflare worker presets are opt-in via `deploy.target = "cloudflare"` (or explicit `deploy.nitroPreset`) so Node-style Nitro adapters do not get selected automatically in auto mode.
|
|
465
|
-
|
|
466
|
-
Production and dev servers expose a health endpoint for hosts and uptime checks:
|
|
467
|
-
|
|
468
|
-
```txt
|
|
469
|
-
/__resux/health
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
## Modules And Route Rules
|
|
473
|
-
|
|
474
|
-
Resux supports first-party and third-party build-time modules in `resux.config.ts`. Modules run during the Resux build and can extend config without adding hydration:
|
|
475
|
-
|
|
476
|
-
```ts
|
|
477
|
-
export default defineResuxConfig({
|
|
478
|
-
modules: [
|
|
479
|
-
"resux:security",
|
|
480
|
-
["resux:performance", { assetMaxAge: 31536000 }],
|
|
481
|
-
["./modules/security.ts", { header: "enabled" }]
|
|
482
|
-
],
|
|
483
|
-
routeRules: {
|
|
484
|
-
"/old": { redirect: { to: "/", statusCode: 301 } },
|
|
485
|
-
"/admin/**": { headers: { "x-robots-tag": "noindex" } }
|
|
486
|
-
}
|
|
487
|
-
})
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
Built-in modules:
|
|
491
|
-
|
|
492
|
-
- `resux:security`: adds default production hardening headers and optional custom headers or CSP through route rules.
|
|
493
|
-
- `resux:performance`: adds immutable cache rules for built Resux runtime/handler assets and `no-store` for route payloads.
|
|
494
|
-
|
|
495
|
-
Modules can be built-in `resux:*` specifiers, npm package specifiers, local files, inline functions, or objects returned by `defineResuxModule`.
|
|
496
|
-
|
|
497
|
-
```ts
|
|
498
|
-
// modules/security.ts
|
|
499
|
-
export default defineResuxModule({
|
|
500
|
-
defaults: { header: "enabled" },
|
|
501
|
-
setup(options, resux) {
|
|
502
|
-
resux.addCss("/module.css")
|
|
503
|
-
resux.addHead({ meta: [{ name: "module", content: options.header }] })
|
|
504
|
-
resux.addRouteRule("/secure/**", {
|
|
505
|
-
headers: { "x-module": options.header },
|
|
506
|
-
cache: { maxAge: 60, swr: 30 }
|
|
507
|
-
})
|
|
508
|
-
resux.extendRuntimeConfig({
|
|
509
|
-
public: { securityModule: options.header }
|
|
510
|
-
})
|
|
511
|
-
}
|
|
512
|
-
})
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
The module API includes `addCss`, `addHead`, `addRouteRule`, and `extendRuntimeConfig`. Route rules currently support redirects, response headers, status codes, cache headers, and CORS headers.
|
|
516
|
-
|
|
517
|
-
## Plugins
|
|
518
|
-
|
|
519
|
-
Resux auto-discovers app plugins from `plugins/` (and `app/plugins/`) without manual imports:
|
|
520
|
-
|
|
521
|
-
- `plugins/*.ts`
|
|
522
|
-
- `plugins/**/*.ts`
|
|
523
|
-
- `plugins/*.client.ts`
|
|
524
|
-
- `plugins/*.server.ts`
|
|
525
|
-
|
|
526
|
-
Use `defineResuxPlugin`:
|
|
527
|
-
|
|
528
|
-
```ts
|
|
529
|
-
// plugins/01.api.ts
|
|
530
|
-
export default defineResuxPlugin((resuxApp) => {
|
|
531
|
-
resuxApp.provide("apiBase", "/api")
|
|
532
|
-
})
|
|
533
|
-
```
|
|
534
|
-
|
|
535
|
-
Plugin execution order is deterministic and sorted by discovered filename path. Numeric prefixes are supported, for example `01.auth.ts` runs before `02.analytics.ts`.
|
|
536
|
-
|
|
537
|
-
Mode behavior:
|
|
538
|
-
|
|
539
|
-
- `.client` plugins run only in the browser.
|
|
540
|
-
- `.server` plugins run only on the server.
|
|
541
|
-
- Unsuffixed plugins run on both server and client.
|
|
542
|
-
|
|
543
|
-
Use `useResuxApp()` inside setup code to access provided values:
|
|
544
|
-
|
|
545
|
-
```ts
|
|
546
|
-
const app = useResuxApp()
|
|
547
|
-
const apiBase = String(app.provides.apiBase ?? "/api")
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
TypeScript app helpers are available globally when your app includes:
|
|
551
|
-
|
|
552
|
-
```ts
|
|
553
|
-
/// <reference types="resuxjs/globals" />
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
For typed plugin injections, augment `ResuxAppInjections`:
|
|
557
|
-
|
|
558
|
-
```ts
|
|
559
|
-
declare module "resuxjs/runtime" {
|
|
560
|
-
interface ResuxAppInjections {
|
|
561
|
-
apiBase: string
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
```
|
|
565
|
-
|
|
566
|
-
## Route Middleware
|
|
567
|
-
|
|
568
|
-
Resux auto-discovers route middleware from `middleware/` (and `app/middleware/`) without manual imports:
|
|
569
|
-
|
|
570
|
-
- `middleware/*.ts`
|
|
571
|
-
- `middleware/**/*.ts`
|
|
572
|
-
- `middleware/*.global.ts`
|
|
573
|
-
- `middleware/*.client.ts`
|
|
574
|
-
- `middleware/*.server.ts`
|
|
575
|
-
|
|
576
|
-
Create middleware with `defineResuxRouteMiddleware`:
|
|
577
|
-
|
|
578
|
-
```ts
|
|
579
|
-
// middleware/auth.ts
|
|
580
|
-
export default defineResuxRouteMiddleware((to) => {
|
|
581
|
-
if (to.path.startsWith("/admin")) {
|
|
582
|
-
return navigateTo("/login")
|
|
583
|
-
}
|
|
584
|
-
})
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
Apply named middleware from page meta:
|
|
588
|
-
|
|
589
|
-
```ts
|
|
590
|
-
definePageMeta({ middleware: "auth" })
|
|
591
|
-
definePageMeta({ middleware: ["auth", "admin"] })
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
Global middleware (`*.global.ts`) runs for every route. Middleware return handling:
|
|
595
|
-
|
|
596
|
-
- `undefined` or no return: continue
|
|
597
|
-
- `false`: abort with `403`
|
|
598
|
-
- `"/path"`: redirect
|
|
599
|
-
- `{ redirect: "/path" }` or `{ redirect: { to: "/path", statusCode: 302 } }`: redirect
|
|
600
|
-
- `navigateTo("/path")`: redirect helper
|
|
601
|
-
- `abortNavigation("message")`: abort helper
|
|
602
|
-
|
|
603
|
-
Mode behavior:
|
|
604
|
-
|
|
605
|
-
- `.client` middleware runs in browser navigation.
|
|
606
|
-
- `.server` middleware runs only during server rendering/navigation handling.
|
|
607
|
-
- Unsuffixed middleware runs on server route resolution.
|
|
608
|
-
|
|
609
|
-
## Server Middleware
|
|
610
|
-
|
|
611
|
-
Files in `server/middleware` run for each request before server handlers, public files, and page rendering:
|
|
612
|
-
|
|
613
|
-
```ts
|
|
614
|
-
export default defineServerMiddleware((event) => {
|
|
615
|
-
setHeader(event, "x-app", "resux")
|
|
616
|
-
|
|
617
|
-
if (event.path.startsWith("/private")) {
|
|
618
|
-
return { type: "redirect", to: "/login", statusCode: 302 }
|
|
619
|
-
}
|
|
620
|
-
})
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
Server middleware can continue by returning nothing, use h3-style helpers such as `setHeader(event, name, value)`, end the Node response directly when necessary, return a `Response`, return a JSON-serializable value, return `false` to send `403`, or return a redirect/abort object.
|
|
624
|
-
|
|
625
|
-
`server/middleware` is request middleware for raw HTTP handling and API/page requests. Route middleware in `middleware/` is navigation middleware for page routing decisions (`definePageMeta({ middleware })` + globals).
|
|
626
|
-
|
|
627
|
-
## What Works
|
|
628
|
-
|
|
629
|
-
- `.vue`-style SFC files with `<template>`, `<script setup lang="ts">`, and plain CSS `<style>` blocks.
|
|
630
|
-
- File-based routing from `pages/`.
|
|
631
|
-
- Dynamic route params like `pages/post/[id].vue`.
|
|
632
|
-
- Catch-all route params like `pages/docs/[...slug].vue`.
|
|
633
|
-
- `app.vue` with `<ResuxPage />`.
|
|
634
|
-
- Layouts with `<ResuxLayout>`, `<slot />`, and `definePageMeta({ layout })`.
|
|
635
|
-
- `<ResuxLink to="...">` rendered as an `<a href="...">` and intercepted for client-side navigation.
|
|
636
|
-
- Static and dynamic component props with `defineProps()`.
|
|
637
|
-
- Server-side rendering.
|
|
638
|
-
- Head/meta rendering from `resux.config.ts`, `definePageMeta`, `useHead`, and `useSeoMeta`.
|
|
639
|
-
- Component CSS from `<style>` and `<style scoped>`, included in SSR output and updated during client-side navigation.
|
|
640
|
-
- Auto-discovered route middleware from `middleware/**/*`, including `.global`, `.client`, and `.server` files.
|
|
641
|
-
- Request-time server middleware from `server/middleware`.
|
|
642
|
-
- Auto-discovered plugins from `plugins/**/*` plus client enhancement entries from `enhancements/**/*` and `client-enhancements/**/*` (including `app/*` variants), with `.client` / `.server` mode suffix support and stable filename ordering.
|
|
643
|
-
- Server API/routes from `server/api` and `server/routes`.
|
|
644
|
-
- Server handler helpers: `readBody(event)`, `getQuery(event)`, and `setHeader(event, name, value)`, backed by h3.
|
|
645
|
-
- `error.vue` for custom 404/500 rendering.
|
|
646
|
-
- Public file serving from `public/`.
|
|
647
|
-
- Built-in health checks at `/__resux/health`.
|
|
648
|
-
- Basic `resux.config.ts` support for `runtimeConfig`, `app.head`, and `css`.
|
|
649
|
-
- Built-in and package/local Resux modules for extending CSS, head, route rules, and runtime config during build.
|
|
650
|
-
- Route rules for redirects, response headers, status codes, cache headers, and CORS headers.
|
|
651
|
-
- Default production security headers with an opt-out flag.
|
|
652
|
-
- Vite-powered dev serving, production client/server bundling, and minification for the resume runtime and handler chunks.
|
|
653
|
-
- Dev rebuilds with automatic browser reloads, without adding Vue hydration.
|
|
654
|
-
- `resux inspect` and `resux inspect --json` for route and build diagnostics.
|
|
655
|
-
- `resux inspect routes|plugins|middleware|imports|components|build|images|server|packages|templates|bundles|seo`.
|
|
656
|
-
- `resux check`, `resux check --json`, and `resux check --fix` for project readiness checks and safe file scaffolding.
|
|
657
|
-
- `resux deploy --preset node|docker|nitro` for deployment file generation.
|
|
658
|
-
- Serialized route, state, and async data payloads.
|
|
659
|
-
- Resumable event handlers such as `@click="increment"`.
|
|
660
|
-
- Lazy client handler chunks loaded on first interaction.
|
|
661
|
-
- Client-side navigation, persistent same-layout DOM, built-in route transition progress, and hover/focus route payload prefetch for same-origin links.
|
|
662
|
-
- Stable core composables: `useState`, `useAsyncData`, `useRoute`, `useRouter`, `useHead`, `useSeoMeta`, `useRuntimeConfig`, `useResuxApp`, `apiURL`, `useFetch`, `$fetch`, `useError`, `clearError`, `showError`, `createError`, and `onMounted`.
|
|
663
|
-
- Lazy package helpers: `useLazyPackage`, `useClientPackage`, `usePackageReady`, `defineLazyPackage`, `defineClientOnlyPackage`, `defineClientEnhancement`, and `useClientEnhancement`.
|
|
664
|
-
- Package mode classification via `packages.mode` (`ssr`, `clientOnly`, `serverOnly`, `progressive`) with diagnostics in `resux inspect packages`.
|
|
665
|
-
- Client runtime package registries are generated with static importers (no raw `import(packageName)` in generated runtime), including package API calls that use const string identifiers and package subpaths (for example `swiper/modules` and `swiper/css/*`).
|
|
666
|
-
- `useAsyncData` returns a Nuxt-like resource with reactive `data`, `pending`, and `error` refs, plus `value` as a data alias for compatibility. Use `await useAsyncData(...)` when you want SSR to fetch before rendering the page; omit `await` when you intentionally want an SSR skeleton that resumes in the browser.
|
|
667
|
-
|
|
668
|
-
## SSR-First Package Enhancements
|
|
669
|
-
|
|
670
|
-
Use semantic SSR markup first, then enhance only in the browser:
|
|
671
|
-
|
|
672
|
-
```vue
|
|
673
|
-
<section
|
|
674
|
-
use-client-enhancement="swiper-carousel"
|
|
675
|
-
data-trigger="visible"
|
|
676
|
-
>
|
|
677
|
-
<ul class="swiper-wrapper">
|
|
678
|
-
<li class="swiper-slide">...</li>
|
|
679
|
-
</ul>
|
|
680
|
-
</section>
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
Register the enhancement in a client-only support file (for example `client-enhancements/swiper-carousel.client.ts`):
|
|
684
|
-
|
|
685
|
-
```ts
|
|
686
|
-
defineClientEnhancement("swiper-carousel", async (target) => {
|
|
687
|
-
const [
|
|
688
|
-
{ default: Swiper },
|
|
689
|
-
{ Navigation, Pagination },
|
|
690
|
-
] = await Promise.all([
|
|
691
|
-
useClientPackage("swiper"),
|
|
692
|
-
useClientPackage("swiper/modules", { preferDefault: false }),
|
|
693
|
-
])
|
|
694
|
-
await useClientPackage("swiper", {
|
|
695
|
-
css: ["swiper/css", "swiper/css/navigation", "swiper/css/pagination"],
|
|
696
|
-
})
|
|
697
|
-
const instance = new Swiper(target.querySelector(".swiper") as HTMLElement, {
|
|
698
|
-
modules: [Navigation, Pagination],
|
|
699
|
-
})
|
|
700
|
-
return () => instance.destroy?.(true, true)
|
|
701
|
-
})
|
|
702
|
-
```
|
|
703
|
-
|
|
704
|
-
Resux injects runtime helper imports for support modules automatically, so `defineClientEnhancement` and `useClientPackage` are available without global assumptions. This pattern keeps package instances inside client-only closures and avoids resumability-unsafe captures in template handlers.
|
|
705
|
-
|
|
706
|
-
In dev, enhancement and package lifecycles emit events you can observe in custom status UIs:
|
|
707
|
-
- `resux:enhancement:found|triggered|loading|ready|error|cleanup-ready`
|
|
708
|
-
- `resux:package:loading|loaded|error`
|
|
709
|
-
- `resux:package-css:loaded`
|
|
710
|
-
|
|
711
|
-
## Component Syntax
|
|
712
|
-
|
|
713
|
-
```vue
|
|
714
|
-
<script setup lang="ts">
|
|
715
|
-
const count = useState("count", () => 0)
|
|
716
|
-
|
|
717
|
-
function increment() {
|
|
718
|
-
count.value++
|
|
719
|
-
}
|
|
720
|
-
</script>
|
|
721
|
-
|
|
722
|
-
<template>
|
|
723
|
-
<button @click="increment">
|
|
724
|
-
Count: {{ count }}
|
|
725
|
-
</button>
|
|
726
|
-
</template>
|
|
727
|
-
```
|
|
728
|
-
|
|
729
|
-
On the server, Resux renders the button as HTML and serializes `count`.
|
|
730
|
-
|
|
731
|
-
In the browser, Resux installs a tiny delegated event listener. The component handler module is not imported until the user clicks the button. After that, the scope is resumed from serialized state and only the marked DOM bindings are patched.
|
|
732
|
-
|
|
733
|
-
## Async Data Skeletons
|
|
734
|
-
|
|
735
|
-
To fetch during SSR and render the resolved data in the first HTML response, await the call:
|
|
736
|
-
|
|
737
|
-
```vue
|
|
738
|
-
<script setup lang="ts">
|
|
739
|
-
type Stats = {
|
|
740
|
-
response: string
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
const { data, pending, error } = await useAsyncData("stats", ({ signal }) => {
|
|
744
|
-
return $fetch<Stats>("/api/stats", { signal })
|
|
745
|
-
})
|
|
746
|
-
</script>
|
|
747
|
-
|
|
748
|
-
<template>
|
|
749
|
-
<p v-if="pending">Loading</p>
|
|
750
|
-
<p v-if="error">{{ error.message }}</p>
|
|
751
|
-
<strong v-if="data">{{ data.response }}</strong>
|
|
752
|
-
</template>
|
|
753
|
-
```
|
|
754
|
-
|
|
755
|
-
For a Next-style loading skeleton, call `useAsyncData` without `await` and branch on `pending`:
|
|
756
|
-
|
|
757
|
-
```vue
|
|
758
|
-
<script setup lang="ts">
|
|
759
|
-
type Stats = {
|
|
760
|
-
response: string
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
const { data, pending, error } = useAsyncData("stats", ({ signal }) => {
|
|
764
|
-
return $fetch<Stats>("/api/stats", { signal })
|
|
765
|
-
})
|
|
766
|
-
</script>
|
|
767
|
-
|
|
768
|
-
<template>
|
|
769
|
-
<div v-if="pending" class="skeleton"></div>
|
|
770
|
-
<p v-if="error">{{ error.message }}</p>
|
|
771
|
-
<strong v-if="!pending && !error && data">{{ data.response }}</strong>
|
|
772
|
-
</template>
|
|
773
|
-
```
|
|
774
|
-
|
|
775
|
-
Resux serializes the pending state, renders the skeleton immediately, resumes only scopes with pending async data in the browser, and patches the marked DOM blocks after the data resolves. The handler receives an abort `signal`; pass it to `$fetch` or `fetch` so pending client requests are aborted when the user leaves the route before data resolves.
|
|
776
|
-
|
|
777
|
-
Templates auto-unwrap refs returned from `useState`, `useAsyncData`, `useFetch`, Vue `ref`, and `computed`, so template examples use `count`, `pending`, and `data.response`. In `<script setup>`, keep using `.value` when mutating refs, such as `count.value++`.
|
|
778
|
-
|
|
779
|
-
## Server API Fetches
|
|
780
|
-
|
|
781
|
-
Browser-only fetches can use relative API URLs:
|
|
782
|
-
|
|
783
|
-
```ts
|
|
784
|
-
await fetch("/api/test")
|
|
785
|
-
```
|
|
786
|
-
|
|
787
|
-
Code that can run during SSR should use `$fetch()` for internal APIs. Resux automatically resolves internal `/api/...` URLs to an absolute request-origin URL on the server, while keeping them relative in the browser:
|
|
788
|
-
|
|
789
|
-
```vue
|
|
790
|
-
<script setup lang="ts">
|
|
791
|
-
const { data, pending, error } = useAsyncData("test", ({ signal }) => {
|
|
792
|
-
return $fetch("/api/test", { signal })
|
|
793
|
-
})
|
|
794
|
-
</script>
|
|
795
|
-
|
|
796
|
-
<template>
|
|
797
|
-
<p v-if="pending">Loading</p>
|
|
798
|
-
<p v-if="error">{{ error.message }}</p>
|
|
799
|
-
<pre v-if="data">{{ data }}</pre>
|
|
800
|
-
</template>
|
|
801
|
-
```
|
|
802
|
-
|
|
803
|
-
On the server, `$fetch("/api/test")` uses the current request origin, then configured public origins such as `runtimeConfig.public.appOrigin`, and finally `http://localhost:3000`. In the browser it keeps `/api/test` relative. Use `apiURL("/api/test")` only when you call native `fetch()` yourself in code that can run during SSR.
|
|
804
|
-
|
|
805
|
-
## Media Components
|
|
806
|
-
|
|
807
|
-
### `ResuxVideo`
|
|
808
|
-
|
|
809
|
-
`ResuxVideo` supports resumable click zones without hydration. By default, the surface is divided into horizontal thirds:
|
|
810
|
-
|
|
811
|
-
- left third: skip backward
|
|
812
|
-
- center third: single click play/pause
|
|
813
|
-
- center third double click: fullscreen
|
|
814
|
-
- right third: skip forward
|
|
815
|
-
|
|
816
|
-
Controls remain interactive because zones exclude the controls hit area and control targets are ignored.
|
|
817
|
-
|
|
818
|
-
```vue
|
|
819
|
-
<ResuxVideo
|
|
820
|
-
src="/media-test/videos/sample-720.mp4"
|
|
821
|
-
poster="/media-test/images/sample-poster.jpg"
|
|
822
|
-
controls
|
|
823
|
-
skip-seconds="10"
|
|
824
|
-
side-click-skip
|
|
825
|
-
click-to-play
|
|
826
|
-
double-click-fullscreen
|
|
827
|
-
/>
|
|
828
|
-
```
|
|
829
|
-
|
|
830
|
-
`ResuxVideo` props (media interaction subset):
|
|
831
|
-
|
|
832
|
-
- `controls` default `true`
|
|
833
|
-
- `nativeControls` optional
|
|
834
|
-
- `customControls` optional
|
|
835
|
-
- `speedControl`, `speeds`, `defaultSpeed`, `persistSpeed`
|
|
836
|
-
- `qualityControl`, `qualities`, `defaultQuality`
|
|
837
|
-
- `sources` supports `{ src, type, quality }`
|
|
838
|
-
- `skipSeconds` default `10`
|
|
839
|
-
- `sideClickSkip` default `true`
|
|
840
|
-
- `clickToPlay` default `true`
|
|
841
|
-
- `doubleClickFullscreen` default `true`
|
|
842
|
-
- `lazy`, `priority`, `preload`, `poster`, `placeholder`
|
|
843
|
-
- optional transforms: `format`, `formats`, `quality` (for resolution height)
|
|
844
|
-
|
|
845
|
-
Video state attributes:
|
|
846
|
-
|
|
847
|
-
- `data-resux-video="idle|loading|ready|playing|paused|error"`
|
|
848
|
-
- `data-rx-video-controls-ready="true|false"`
|
|
849
|
-
- `data-resux-video-control` on interactive control elements
|
|
850
|
-
- `data-resux-video-zone="left|center|right"` on surface zones
|
|
851
|
-
|
|
852
|
-
Optional video transforms can generate cacheable assets in `public/_resux/generated/videos/*` when enabled:
|
|
853
|
-
|
|
854
|
-
```ts
|
|
855
|
-
export default defineResuxConfig({
|
|
856
|
-
video: {
|
|
857
|
-
transforms: {
|
|
858
|
-
enabled: true,
|
|
859
|
-
formats: ["mp4", "webm"],
|
|
860
|
-
qualities: [480, 720, 1080],
|
|
861
|
-
cache: "1d"
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
})
|
|
865
|
-
```
|
|
866
|
-
|
|
867
|
-
When transforms are requested (for example `format="webm"` or `:qualities="[480,720]"`), Resux emits deterministic URLs under `/_resux/generated/videos/*` and serves them through the built-in `__resux/video` runtime endpoint. If `ffmpeg` is unavailable, Resux falls back with a clear 501 error instead of breaking standard video rendering.
|
|
868
|
-
|
|
869
|
-
### `ResuxImg` and `ResuxPicture`
|
|
870
|
-
|
|
871
|
-
`ResuxImg` and `ResuxPicture` keep placeholders active until the real image load/decode completes.
|
|
872
|
-
|
|
873
|
-
```vue
|
|
874
|
-
<ResuxImg
|
|
875
|
-
src="/media-test/images/hero-large.jpg"
|
|
876
|
-
width="1600"
|
|
877
|
-
height="900"
|
|
878
|
-
priority
|
|
879
|
-
placeholder="blur"
|
|
880
|
-
sizes="(min-width: 1280px) 960px, 100vw"
|
|
881
|
-
/>
|
|
237
|
+
npm test
|
|
238
|
+
npm run test:templates
|
|
882
239
|
```
|
|
883
240
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
- `placeholder="empty"`
|
|
887
|
-
- `placeholder="blur"`
|
|
888
|
-
- `placeholder="skeleton"`
|
|
889
|
-
- `placeholder="spinner"`
|
|
890
|
-
- `placeholder="/custom-placeholder.svg"`
|
|
891
|
-
|
|
892
|
-
Image state attributes:
|
|
893
|
-
|
|
894
|
-
- `data-resux-img="idle|loading|loaded|error"`
|
|
895
|
-
- `data-rx-placeholder-active="true"` while placeholder is visible
|
|
896
|
-
- `data-rx-lazy-image="true"` for deferred lazy sources
|
|
897
|
-
|
|
898
|
-
Priority images emit preload links near the top of `<head>` with `fetchpriority="high"` and responsive `imagesrcset`/`imagesizes`.
|
|
899
|
-
|
|
900
|
-
## Supported Syntax
|
|
901
|
-
|
|
902
|
-
The v1 compiler supports:
|
|
903
|
-
|
|
904
|
-
- Static elements and text.
|
|
905
|
-
- Interpolation: `{{ value }}`.
|
|
906
|
-
- Static attributes: `class="box"`.
|
|
907
|
-
- Dynamic attributes: `:class="className"`.
|
|
908
|
-
- Dynamic class arrays/objects and style objects for `:class` and `:style`.
|
|
909
|
-
- Plain CSS `<style>` blocks, including `<style scoped>`.
|
|
910
|
-
- Plain named events: `@click="increment"`.
|
|
911
|
-
- Inline event expressions that only capture resumable values, plus named handlers such as `@click="increment"`.
|
|
912
|
-
- Resumability-safe event modifiers: `.prevent`, `.stop`, `.self`, `.once`, system/mouse modifiers, and key filters such as `.enter`.
|
|
913
|
-
- `v-if`, `v-else-if`, and `v-else`.
|
|
914
|
-
- `v-show`.
|
|
915
|
-
- `v-text`.
|
|
916
|
-
- Sanitized `v-html`.
|
|
917
|
-
- Basic `v-model` for form values.
|
|
918
|
-
- Simple `v-for`, such as `item in items` or `(item, index) in items`.
|
|
919
|
-
- Component tags from `components/`.
|
|
920
|
-
- `<ResuxPage />`.
|
|
921
|
-
- `<ResuxLayout />`.
|
|
922
|
-
- `<slot />` inside layouts.
|
|
923
|
-
- `<ResuxLink to="/path">`.
|
|
924
|
-
- `defineProps()` in components.
|
|
925
|
-
- `definePageMeta({ layout, middleware, title, meta })`.
|
|
926
|
-
- `useRoute()` for the current path, params, and query.
|
|
927
|
-
- `useRouter().push("/path")`, `replace`, `back`, `forward`, and `go`.
|
|
928
|
-
- `useHead({ title, meta, link })`.
|
|
929
|
-
- `useSeoMeta({ title, description, ogTitle, ogImage, twitterCard })`.
|
|
930
|
-
- `apiURL("/api/path")` for SSR-safe API fetch URLs.
|
|
931
|
-
- `onMounted()`, run when the component scope is first resumed in the browser.
|
|
932
|
-
- Vue runtime islands via `<VueIsland name="CounterIsland" :props="{ start: 1 }" />` and files in `islands/vue`.
|
|
933
|
-
|
|
934
|
-
Handlers and inline event expressions must only capture resumable values, such as refs returned by `useState`.
|
|
935
|
-
|
|
936
|
-
## Current Limits
|
|
241
|
+
For the repository's complete verification matrix, use the scripts defined in `package.json` and the GitHub Actions workflows. Release/package verification intentionally runs more checks than this introductory README lists.
|
|
937
242
|
|
|
938
|
-
|
|
243
|
+
## Documentation rule
|
|
939
244
|
|
|
940
|
-
|
|
941
|
-
- Nitro support is an adapter/deployment preset, not the primary dev server.
|
|
942
|
-
- SFC styles support plain CSS only; preprocessors like SCSS and CSS modules are not implemented for resumable components yet.
|
|
943
|
-
- Event `.capture` and `.passive` are accepted in templates, but the browser runtime still uses delegated resumable listeners.
|
|
944
|
-
- No fallback hydration for unsupported components.
|
|
245
|
+
The **source code, package exports, and tests are the source of truth**. The README is intentionally an introduction rather than a duplicate of the complete documentation site.
|
|
945
246
|
|
|
946
|
-
|
|
247
|
+
When a public API changes, update the implementation/tests and the relevant documentation together. Do not document a feature merely because a comparable framework has it.
|
|
947
248
|
|
|
948
|
-
##
|
|
949
|
-
|
|
950
|
-
- `Failed to parse URL from /api/...` during SSR: use `apiURL("/api/...")` or `$fetch("/api/...")` from Resux setup code so server-side fetches get an absolute URL.
|
|
951
|
-
- Skeletons that never disappear: render `error` from `useAsyncData` and guard success UI with `!pending && !error && data`.
|
|
952
|
-
- Dev edits do not appear: keep `resux dev .` running and make sure the browser is connected to `/__resux/dev-events`; Resux reloads the page after successful rebuilds.
|
|
953
|
-
- Port already in use: pass another port, for example `resux dev --port 4000`.
|
|
954
|
-
- Handler capture compile errors: move non-serializable values out of resumable handlers or store resumable state with `useState`.
|
|
955
|
-
|
|
956
|
-
## Architecture
|
|
957
|
-
|
|
958
|
-
Resux is one package with five internal parts:
|
|
959
|
-
|
|
960
|
-
- Compiler: parses `.vue` files, creates routes, validates resumable handlers, and emits server/client modules.
|
|
961
|
-
- Runtime: renders HTML on the server, provides Resux-style composables, runs plugins, applies layouts, collects head entries, and serializes payloads.
|
|
962
|
-
- CLI and Node server: builds apps, starts the dev server, previews generated output, and exposes `resuxjs/node`.
|
|
963
|
-
- Create CLI: scaffolds a starter app for `resux init`.
|
|
964
|
-
- Package entrypoints: keep the root runtime-only while `resuxjs/compiler`, `resuxjs/runtime`, `resuxjs/node`, `resuxjs/globals`, and `resuxjs/create` expose focused surfaces.
|
|
965
|
-
|
|
966
|
-
The browser initially receives only server-rendered HTML, the serialized payload, and the small resume loader.
|
|
967
|
-
|
|
968
|
-
For internal navigation, the client runtime prefetches route payloads on hover/focus, intercepts same-origin links, fetches a fresh SSR route payload from `/__resux/route`, updates a server-rendered transition progress shell through start/fetch/swap/complete/error phases, keeps the active layout DOM when the layout name matches, swaps the page slot, updates `<head>`, updates browser history, and clears only non-persistent resumed page scopes.
|
|
969
|
-
|
|
970
|
-
## Testing
|
|
971
|
-
|
|
972
|
-
Run:
|
|
973
|
-
|
|
974
|
-
```sh
|
|
975
|
-
npm test
|
|
976
|
-
```
|
|
249
|
+
## License
|
|
977
250
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
- Route generation.
|
|
981
|
-
- SFC compiler output.
|
|
982
|
-
- Compile errors for unsupported resumability captures.
|
|
983
|
-
- Sanitized `v-html`, `v-model`, inline handlers, and mounted resume hooks.
|
|
984
|
-
- SSR payload serialization.
|
|
985
|
-
- Dynamic route params and catch-all params.
|
|
986
|
-
- Layout rendering.
|
|
987
|
-
- Head/meta rendering.
|
|
988
|
-
- Runtime config and plugin provides.
|
|
989
|
-
- Recursive project discovery for layouts, middleware, server middleware, plugins, API routes, and config.
|
|
990
|
-
- Plugin order and client/server mode filtering.
|
|
991
|
-
- Route middleware execution for SSR and client navigation.
|
|
992
|
-
- Extended route-rule serialization.
|
|
993
|
-
- Client resume behavior after interaction.
|
|
251
|
+
See [LICENSE](LICENSE).
|