@mednours/fronton 0.1.0 → 0.2.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/README.md +23 -3
- package/dist/client.d.ts +52 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -0
- package/dist/dom-animation-RYVDSRON.js +5 -0
- package/dist/dom-max-SN3JCHFZ.js +5 -0
- package/dist/motion/dom-animation.d.ts +2 -0
- package/dist/motion/dom-animation.d.ts.map +1 -0
- package/dist/motion/dom-max.d.ts +2 -0
- package/dist/motion/dom-max.d.ts.map +1 -0
- package/package.json +18 -6
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ bun add @mednours/fronton
|
|
|
9
9
|
Two separate entry points, deliberately not one:
|
|
10
10
|
|
|
11
11
|
- **`@mednours/fronton`** (the root import) — Node-side, meant for `vite.config.ts` only: `obfuscateTailwind()`, `frontonCompression()`, `backonProxy()`.
|
|
12
|
-
- **`@mednours/fronton/client`** — browser-safe, meant for application code: `resolveApiBaseUrl()`.
|
|
12
|
+
- **`@mednours/fronton/client`** — browser-safe, meant for application code: `resolveApiBaseUrl()`, `lazyDomAnimation()`/`lazyDomMax()`.
|
|
13
13
|
|
|
14
14
|
Mixing these into one entry point was the first version's actual design, and it broke in a specific, findable way: importing `resolveApiBaseUrl` from a component pulled the *entire* bundle — including `postcss`, `magic-string`, and `vite-plugin-compression2` — into the client dependency graph, since esbuild had already flattened everything into a single file before Vite's bundler ever got a chance to tree-shake it. Vite's dependency scanner then warned about externalizing `node:crypto`, `node:fs`, and `zlib` for the browser, and the shipped JS bundle was measurably bigger for it (in one test project, 338 KB vs. 191 KB after the split — that's not a rounding error). Splitting the entry point at the source fixes it structurally instead of relying on a bundler to clean it up.
|
|
15
15
|
|
|
@@ -83,6 +83,25 @@ fetch(`${resolveApiBaseUrl()}/api/users`);
|
|
|
83
83
|
|
|
84
84
|
Reads `import.meta.env.VITE_API_BASE_URL`, returning `""` (relative requests) when it's unset — correct for same-origin deployment or the dev-server proxy above. This exists because the obvious alternative, a `process.env` check (the pattern backon's own generated `generate-client` script uses, correctly, since that script runs under Node/Bun), does nothing useful in a browser bundle: `process` isn't defined there, so the check just silently falls through. Only `VITE_`-prefixed variables are ever exposed to client code — Vite drops everything else on purpose, so a backend secret sitting in the same `.env` file never leaks into the browser bundle.
|
|
85
85
|
|
|
86
|
+
## `lazyDomAnimation()` / `lazyDomMax()` (from `@mednours/fronton/client`)
|
|
87
|
+
|
|
88
|
+
Pre-built `<LazyMotion features={...}>` loaders for [`motion`](https://motion.dev) (née Framer Motion):
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { LazyMotion, m } from "motion/react";
|
|
92
|
+
import { lazyDomAnimation } from "@mednours/fronton/client";
|
|
93
|
+
|
|
94
|
+
<LazyMotion features={lazyDomAnimation}>
|
|
95
|
+
<m.div animate={{ opacity: 1 }} initial={{ opacity: 0 }} />
|
|
96
|
+
</LazyMotion>;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This exists because `motion`'s own `<LazyMotion features={domAnimation}>` example is a trap if `domAnimation` gets there via a plain, static `import { domAnimation } from "motion/react"` — that still pulls the whole animation engine into the main bundle, exactly as expensive as using `motion.div` directly. `features` only saves anything when it's a function that *dynamically* imports the bundle. Verified against a real Vite build: the static form produced one 265.81 KB chunk (85.91 KB gzip); switching to a real dynamic loader dropped the main chunk to 231.51 KB (74.58 KB gzip) and moved the rest into its own 37.42 KB chunk (14.18 KB gzip) that only loads once something on the page actually animates.
|
|
100
|
+
|
|
101
|
+
The less obvious trap, also verified against a real build: dynamically importing `"motion/react"` itself doesn't work either. Every component using `<LazyMotion>`/`<m.div>` has to statically import `LazyMotion`/`m` from `"motion/react"` — there's no lazy way to get those — and Rollup refuses to split a module into its own chunk if *anything* in the build graph already imports that exact same specifier statically, even from an unrelated file (an "ineffective dynamic import" — collapses back into one chunk). `lazyDomAnimation`/`lazyDomMax` work around this by each dynamically importing a tiny dedicated internal module that statically re-exports just one feature bundle, giving Rollup a boundary that isn't already claimed elsewhere. Confirmed end-to-end, not just in theory: this package's own build (esbuild with `--splitting`) preserves that boundary as a real separate chunk file, and feeding its actual `dist/client.js` output into a real downstream Vite build reproduced the same 231.51/37.42 KB split.
|
|
102
|
+
|
|
103
|
+
`lazyDomAnimation` covers drag-free interactions (hover/tap/enter-exit/animate); `lazyDomMax` is a strict superset that adds layout and drag animations — same as `motion`'s own `domAnimation`/`domMax`. `motion` is an optional peer dependency (`bun add motion`) — install it only if you actually call one of these.
|
|
104
|
+
|
|
86
105
|
## `compressImages(options?)` and `compressVideos(options?)`
|
|
87
106
|
|
|
88
107
|
Opt-in — not wired into `create-fronton`'s generated `vite.config.ts` by default, and not installed by default either (see "Peer dependencies" below). Both re-encode media files in the finished output directory in place, keeping the result only if it's smaller than the original — same "never make it worse" contract `frontonCompression`'s `skipIfLargerOrEqual` uses:
|
|
@@ -107,15 +126,16 @@ Neither plugin fails a build if its dependencies are missing — each logs a war
|
|
|
107
126
|
|
|
108
127
|
## Peer dependencies
|
|
109
128
|
|
|
110
|
-
`vite` is required. `sharp`, `fluent-ffmpeg`,
|
|
129
|
+
`vite` is required. `sharp`, `fluent-ffmpeg`, `ffmpeg-static`, and `motion` are optional peer dependencies — only needed if you actually use the functions that need them:
|
|
111
130
|
|
|
112
131
|
```
|
|
113
132
|
bun add sharp # for compressImages
|
|
114
133
|
bun add fluent-ffmpeg ffmpeg-static # for compressVideos
|
|
115
134
|
bun add -D @types/fluent-ffmpeg # optional, for types
|
|
135
|
+
bun add motion # for lazyDomAnimation / lazyDomMax
|
|
116
136
|
```
|
|
117
137
|
|
|
118
|
-
They're kept out of `dependencies` on purpose: `sharp` and `ffmpeg-static` are large native binaries, and most projects using `obfuscateTailwind`/`frontonCompression`/`backonProxy` have no media to compress at all — there's no reason for `bun install` to pay for
|
|
138
|
+
They're kept out of `dependencies` on purpose: `sharp` and `ffmpeg-static` are large native binaries, `motion` is a real animation library most projects don't need, and most projects using `obfuscateTailwind`/`frontonCompression`/`backonProxy` have no media to compress or animations to run at all — there's no reason for `bun install` to pay for any of them unless you're actually calling the function that needs it.
|
|
119
139
|
|
|
120
140
|
## Requirements
|
|
121
141
|
|
package/dist/client.d.ts
CHANGED
|
@@ -18,4 +18,56 @@
|
|
|
18
18
|
* are on different origins.
|
|
19
19
|
*/
|
|
20
20
|
export declare function resolveApiBaseUrl(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Pre-built `<LazyMotion features={...}>` loaders for `motion` (the
|
|
23
|
+
* animation library, née Framer Motion) — `lazyDomAnimation` for
|
|
24
|
+
* `domAnimation` (drag/hover/tap/enter-exit), `lazyDomMax` for `domMax`
|
|
25
|
+
* (adds layout animations, on top of everything `domAnimation` covers).
|
|
26
|
+
*
|
|
27
|
+
* Why this exists: `motion`'s own `<LazyMotion features={domAnimation}>`
|
|
28
|
+
* pattern only saves anything if `features` is a function that *dynamically*
|
|
29
|
+
* imports the feature bundle — passing the bundle directly (a plain, static
|
|
30
|
+
* `import { domAnimation } from "motion/react"`) still pulls the whole
|
|
31
|
+
* animation engine into the main bundle, identical in cost to using
|
|
32
|
+
* `motion.div` outright. Verified against a real Vite build: the static
|
|
33
|
+
* form produced one 265.81 KB chunk (85.91 KB gzip); switching to a real
|
|
34
|
+
* dynamic loader dropped the main chunk to 231.51 KB (74.58 KB gzip) and
|
|
35
|
+
* moved the rest into its own 37.42 KB chunk (14.18 KB gzip) that only
|
|
36
|
+
* loads once something on the page actually animates.
|
|
37
|
+
*
|
|
38
|
+
* The less obvious trap, also verified against a real build: it's not
|
|
39
|
+
* enough for *this* function to dynamically import `"motion/react"` —
|
|
40
|
+
* every component using `<LazyMotion>`/`<m.div>` also has to statically
|
|
41
|
+
* import `LazyMotion`/`m` from `"motion/react"` (there's no lazy way to get
|
|
42
|
+
* those), and Rollup refuses to split a module into its own chunk if
|
|
43
|
+
* *anything* in the build graph already imports that exact same module
|
|
44
|
+
* specifier statically (an "ineffective dynamic import" — confirmed by
|
|
45
|
+
* reproducing it: dynamically importing `"motion/react"` directly, even
|
|
46
|
+
* from a completely different file than the static import, still collapsed
|
|
47
|
+
* back into one chunk). That's why `lazyDomAnimation`/`lazyDomMax` don't
|
|
48
|
+
* dynamically import `"motion/react"` themselves — they each dynamically
|
|
49
|
+
* import a tiny dedicated wrapper module (./motion/dom-animation,
|
|
50
|
+
* ./motion/dom-max) that statically re-exports just that one feature bundle,
|
|
51
|
+
* giving Rollup a module boundary that isn't already claimed elsewhere.
|
|
52
|
+
* fronton's own build (esbuild with `--splitting`) preserves that boundary
|
|
53
|
+
* as a real separate output chunk rather than inlining it back together —
|
|
54
|
+
* confirmed by building this package for real and feeding its actual
|
|
55
|
+
* `dist/client.js` output into a real downstream Vite build.
|
|
56
|
+
*
|
|
57
|
+
* Usage:
|
|
58
|
+
* ```tsx
|
|
59
|
+
* import { LazyMotion, m } from "motion/react";
|
|
60
|
+
* import { lazyDomAnimation } from "@mednours/fronton/client";
|
|
61
|
+
*
|
|
62
|
+
* <LazyMotion features={lazyDomAnimation}>
|
|
63
|
+
* <m.div animate={{ opacity: 1 }} initial={{ opacity: 0 }} />
|
|
64
|
+
* </LazyMotion>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* `motion` is an optional peer dependency (`bun add motion`) — these two
|
|
68
|
+
* exports are the only things in this file that need it, and only if you
|
|
69
|
+
* actually call one.
|
|
70
|
+
*/
|
|
71
|
+
export declare const lazyDomAnimation: () => Promise<import("motion/react").FeatureBundle>;
|
|
72
|
+
export declare const lazyDomMax: () => Promise<import("motion/react").FeatureBundle>;
|
|
21
73
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,gBAAgB,QAAO,OAAO,CAAC,OAAO,cAAc,EAAE,aAAa,CACnB,CAAC;AAC9D,eAAO,MAAM,UAAU,QAAO,OAAO,CAAC,OAAO,cAAc,EAAE,aAAa,CACnB,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -3,6 +3,10 @@ function resolveApiBaseUrl() {
|
|
|
3
3
|
const value = import.meta.env?.VITE_API_BASE_URL;
|
|
4
4
|
return typeof value === "string" && value.length > 0 ? value : "";
|
|
5
5
|
}
|
|
6
|
+
var lazyDomAnimation = () => import("./dom-animation-RYVDSRON.js").then((mod) => mod.default);
|
|
7
|
+
var lazyDomMax = () => import("./dom-max-SN3JCHFZ.js").then((mod) => mod.default);
|
|
6
8
|
export {
|
|
9
|
+
lazyDomAnimation,
|
|
10
|
+
lazyDomMax,
|
|
7
11
|
resolveApiBaseUrl
|
|
8
12
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-animation.d.ts","sourceRoot":"","sources":["../../src/motion/dom-animation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-max.d.ts","sourceRoot":"","sources":["../../src/motion/dom-max.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mednours/fronton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Opinionated runtime pieces for fronton-scaffolded Vite projects — Tailwind class obfuscation, gzip/brotli compression, and backon API wiring.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,19 +32,29 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "bun test",
|
|
34
34
|
"typecheck": "tsc --noEmit",
|
|
35
|
-
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && esbuild src/index.ts src/client.ts --bundle --platform=node --format=esm --target=node18 --packages=external --outdir=dist",
|
|
35
|
+
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && esbuild src/index.ts src/client.ts --bundle --platform=node --format=esm --target=node18 --packages=external --splitting --outdir=dist",
|
|
36
36
|
"prepublishOnly": "bun run typecheck && bun run test && bun run build"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"vite": "^8.0.0",
|
|
40
40
|
"sharp": "^0.35.0",
|
|
41
41
|
"fluent-ffmpeg": "^2.1.3",
|
|
42
|
-
"ffmpeg-static": "^5.3.0"
|
|
42
|
+
"ffmpeg-static": "^5.3.0",
|
|
43
|
+
"motion": "^12.0.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependenciesMeta": {
|
|
45
|
-
"sharp": {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
"sharp": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"fluent-ffmpeg": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"ffmpeg-static": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"motion": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
48
58
|
},
|
|
49
59
|
"dependencies": {
|
|
50
60
|
"magic-string": "^1.2.0",
|
|
@@ -58,6 +68,8 @@
|
|
|
58
68
|
"esbuild": "^0.28.2",
|
|
59
69
|
"ffmpeg-static": "^5.3.0",
|
|
60
70
|
"fluent-ffmpeg": "^2.1.3",
|
|
71
|
+
"motion": "^12.42.2",
|
|
72
|
+
"react": "^19.2.8",
|
|
61
73
|
"sharp": "^0.35.3",
|
|
62
74
|
"typescript": "^7.0.2",
|
|
63
75
|
"vite": "^8.2.1"
|