@barefootjs/cli 0.30.6 → 0.31.1
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/dist/docs/core/adapters/csr.md +17 -11
- package/dist/docs/core/adapters/go-template-adapter.md +2 -8
- package/dist/docs/core/adapters/hono-adapter.md +11 -17
- package/dist/docs/core/adapters/perl-adapter.md +20 -11
- package/dist/docs/core/adapters/php-adapter.md +20 -14
- package/dist/docs/core/adapters/python-adapter.md +10 -7
- package/dist/docs/core/adapters/ruby-adapter.md +10 -7
- package/dist/docs/core/adapters/rust-adapter.md +10 -7
- package/dist/docs/core/advanced/code-splitting.md +18 -142
- package/dist/docs/core/advanced/xyflow-browser-bundle.md +11 -0
- package/dist/docs/core/llms.txt +1 -1
- package/dist/docs/core/quick-start.mdx +4 -4
- package/dist/index.js +1512 -3692
- package/package.json +7 -5
|
@@ -17,25 +17,31 @@ When you do control the server (Hono, Go, etc.), prefer SSR + hydration instead.
|
|
|
17
17
|
|
|
18
18
|
## Configuration
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Pass `CSRAdapter` (from `@barefootjs/client/csr-adapter`) as the `adapter` option to `@barefootjs/vite`'s `barefoot()` plugin. Its `generate()` always returns empty output — CSR has no template-language backend — so `templates` stays unset; the Vite plugin verifies that claim itself:
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
//
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
// vite.config.ts
|
|
24
|
+
import { defineConfig } from 'vite'
|
|
25
|
+
import { barefoot } from '@barefootjs/vite'
|
|
26
|
+
import { CSRAdapter } from '@barefootjs/client/csr-adapter'
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
build: { outDir: 'dist' },
|
|
30
|
+
plugins: [
|
|
31
|
+
barefoot({
|
|
32
|
+
adapter: new CSRAdapter(),
|
|
33
|
+
components: ['./components'],
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
29
36
|
})
|
|
30
37
|
```
|
|
31
38
|
|
|
32
|
-
Build output:
|
|
39
|
+
Build output (`vite build`):
|
|
33
40
|
|
|
34
41
|
```
|
|
35
42
|
dist/
|
|
36
|
-
└──
|
|
37
|
-
|
|
38
|
-
└── Counter.client.js # compiled component
|
|
43
|
+
└── assets/
|
|
44
|
+
└── Counter.tsx-<hash>.js # compiled component (imports the runtime as a shared chunk)
|
|
39
45
|
```
|
|
40
46
|
|
|
41
47
|
## API
|
|
@@ -280,15 +280,9 @@ Client components register their scripts via the `.Scripts` interface:
|
|
|
280
280
|
The `ScriptCollector` tracks needed scripts and renders `<script>` tags at page end. Each script loads at most once.
|
|
281
281
|
|
|
282
282
|
|
|
283
|
-
##
|
|
283
|
+
## Vendor code-splitting
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
```go-template
|
|
288
|
-
{{ template "barefoot-importmap.html" . }}
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
See [Code splitting & externals](../advanced/code-splitting.md#template-string-adapters) for what the snippet contains and how the manifest is generated.
|
|
285
|
+
Vendor code-splitting is Vite's job now, via stock `build.rollupOptions.output.manualChunks` — see [Vendor code-splitting](../advanced/code-splitting.md). There is no BarefootJS-specific importmap manifest to generate or include: Vite resolves and bundles component + vendor chunks ahead of time, and `combineGoTypes`'s generated `components.go` only carries type definitions, not asset URLs.
|
|
292
286
|
|
|
293
287
|
|
|
294
288
|
## Go Helper Functions
|
|
@@ -200,21 +200,15 @@ Loop markers (`<!--bf-loop-->...<!--bf-/loop-->`) are used for reconciliation. F
|
|
|
200
200
|
|
|
201
201
|
## Deploying to Cloudflare Workers
|
|
202
202
|
|
|
203
|
-
`
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
barefoot-externals.json
|
|
215
|
-
components/Counter.tsx
|
|
216
|
-
components/manifest.json
|
|
217
|
-
# <<< barefoot managed block <<<
|
|
203
|
+
`@barefootjs/hono/vite`'s `barefoot()` plugin takes separate `templates` and `build.outDir` options — the compiled SSR `.tsx` templates land under `templates` (a server-side source directory your app imports from), while Vite's own client build (`barefoot.js`, `*.client.js`, vendor chunks) lands under stock `build.outDir`. Point Workers Assets' `assets.directory` at `build.outDir` only; the SSR template directory never needs to be — and should not be — publicly served. No `.assetsignore` bookkeeping is required: the two output trees are separate directories by construction, e.g.:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// vite.config.ts
|
|
207
|
+
export default defineConfig({
|
|
208
|
+
build: { outDir: 'dist/static/components' }, // → assets.directory
|
|
209
|
+
plugins: barefoot({
|
|
210
|
+
components: ['components'],
|
|
211
|
+
templates: 'dist/components', // server-only, not deployed as an asset
|
|
212
|
+
}),
|
|
213
|
+
})
|
|
218
214
|
```
|
|
219
|
-
|
|
220
|
-
Anything you add outside the managed markers is preserved across rebuilds. The browser-served outputs (`barefoot.js`, `*.client.js`, vendor chunks) are intentionally left out so they still deploy.
|
|
@@ -66,14 +66,18 @@ Scaffold a runnable starter:
|
|
|
66
66
|
npm create barefootjs@latest -- --adapter mojo
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Configure the build (`
|
|
69
|
+
Configure the build (`vite.config.ts`):
|
|
70
70
|
|
|
71
71
|
```typescript
|
|
72
|
-
import {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
outDir: 'dist',
|
|
72
|
+
import { defineConfig } from 'vite'
|
|
73
|
+
import { barefoot } from '@barefootjs/mojolicious/vite'
|
|
74
|
+
|
|
75
|
+
export default defineConfig({
|
|
76
|
+
build: { outDir: 'dist/client' },
|
|
77
|
+
plugins: barefoot({
|
|
78
|
+
components: ['./components'],
|
|
79
|
+
templates: 'dist/templates',
|
|
80
|
+
}),
|
|
77
81
|
})
|
|
78
82
|
```
|
|
79
83
|
|
|
@@ -108,11 +112,16 @@ npm create barefootjs@latest -- --adapter xslate
|
|
|
108
112
|
```
|
|
109
113
|
|
|
110
114
|
```typescript
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
// vite.config.ts
|
|
116
|
+
import { defineConfig } from 'vite'
|
|
117
|
+
import { barefoot } from '@barefootjs/xslate/vite'
|
|
118
|
+
|
|
119
|
+
export default defineConfig({
|
|
120
|
+
build: { outDir: 'dist/client' },
|
|
121
|
+
plugins: barefoot({
|
|
122
|
+
components: ['./components'],
|
|
123
|
+
templates: 'dist/templates',
|
|
124
|
+
}),
|
|
116
125
|
})
|
|
117
126
|
```
|
|
118
127
|
|
|
@@ -63,18 +63,21 @@ is shared unchanged between `TwigBackend` and `BladeBackend`.
|
|
|
63
63
|
npm install @barefootjs/twig
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Configure the build (`
|
|
66
|
+
Configure the build (`vite.config.ts`):
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
|
-
import {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
import { defineConfig } from 'vite'
|
|
70
|
+
import { barefoot } from '@barefootjs/twig/vite'
|
|
71
|
+
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
plugins: barefoot({
|
|
74
|
+
components: ['./src/components'],
|
|
75
|
+
templates: './dist/templates',
|
|
76
|
+
}),
|
|
74
77
|
})
|
|
75
78
|
```
|
|
76
79
|
|
|
77
|
-
`
|
|
80
|
+
`vite build` emits `.twig` templates plus client JS under `templates` / Vite's own `build.outDir`. On the PHP
|
|
78
81
|
side, require `barefootjs/twig` via Composer and point a `TwigBackend` at the
|
|
79
82
|
emitted templates — it builds a `FilesystemLoader`-backed `Twig\Environment`
|
|
80
83
|
with the defaults the templates assume (`autoescape: 'html'`,
|
|
@@ -105,18 +108,21 @@ backends.
|
|
|
105
108
|
npm install @barefootjs/blade
|
|
106
109
|
```
|
|
107
110
|
|
|
108
|
-
Configure the build (`
|
|
111
|
+
Configure the build (`vite.config.ts`):
|
|
109
112
|
|
|
110
113
|
```typescript
|
|
111
|
-
import {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
import { defineConfig } from 'vite'
|
|
115
|
+
import { barefoot } from '@barefootjs/blade/vite'
|
|
116
|
+
|
|
117
|
+
export default defineConfig({
|
|
118
|
+
plugins: barefoot({
|
|
119
|
+
components: ['./src/components'],
|
|
120
|
+
templates: './dist/templates',
|
|
121
|
+
}),
|
|
116
122
|
})
|
|
117
123
|
```
|
|
118
124
|
|
|
119
|
-
`
|
|
125
|
+
`vite build` emits `.blade.php` templates plus client JS under `templates` / Vite's own `build.outDir`. Blade
|
|
120
126
|
runs on `illuminate/view` used **standalone** — no Laravel application or
|
|
121
127
|
service container required. Construct a `Factory` (`Filesystem` + an event
|
|
122
128
|
`Dispatcher` + an `EngineResolver` registering a `blade` engine over a
|
|
@@ -55,18 +55,21 @@ array/string helpers, `spread_attrs`, `query`, …).
|
|
|
55
55
|
npm install @barefootjs/jinja
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
Configure the build (`
|
|
58
|
+
Configure the build (`vite.config.ts`):
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
import { defineConfig } from 'vite'
|
|
62
|
+
import { barefoot } from '@barefootjs/jinja/vite'
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
plugins: barefoot({
|
|
66
|
+
components: ['./src/components'],
|
|
67
|
+
templates: './dist/templates',
|
|
68
|
+
}),
|
|
66
69
|
})
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
`
|
|
72
|
+
`vite build` emits `.jinja` templates plus client JS under `templates` / Vite's own `build.outDir`. On the
|
|
70
73
|
Python side, vendor `python/barefootjs/` (from `@barefootjs/jinja`) into
|
|
71
74
|
your app and render a component by constructing a `jinja2.Environment` over
|
|
72
75
|
a `FileSystemLoader` pointed at the emitted templates, with the exact
|
|
@@ -48,18 +48,21 @@ that already produce finished HTML (e.g. `spread_attrs`) share one
|
|
|
48
48
|
npm install @barefootjs/erb
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
Configure the build (`
|
|
51
|
+
Configure the build (`vite.config.ts`):
|
|
52
52
|
|
|
53
53
|
```typescript
|
|
54
|
-
import {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
import { defineConfig } from 'vite'
|
|
55
|
+
import { barefoot } from '@barefootjs/erb/vite'
|
|
56
|
+
|
|
57
|
+
export default defineConfig({
|
|
58
|
+
plugins: barefoot({
|
|
59
|
+
components: ['./components'],
|
|
60
|
+
templates: 'dist/templates',
|
|
61
|
+
}),
|
|
59
62
|
})
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
`
|
|
65
|
+
`vite build` emits one `.erb` file per component plus the client JS bundle. On
|
|
63
66
|
the Ruby side, vendor `lib/barefoot_js.rb` (from `@barefootjs/erb`) into your
|
|
64
67
|
app and construct the ERB backend against the output directory:
|
|
65
68
|
|
|
@@ -78,18 +78,21 @@ array/string helpers, `spread_attrs`, `query`, …).
|
|
|
78
78
|
npm install @barefootjs/rust
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
Configure the build (`
|
|
81
|
+
Configure the build (`vite.config.ts`):
|
|
82
82
|
|
|
83
83
|
```typescript
|
|
84
|
-
import {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
import { defineConfig } from 'vite'
|
|
85
|
+
import { barefoot } from '@barefootjs/rust/vite'
|
|
86
|
+
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
plugins: barefoot({
|
|
89
|
+
components: ['./src/components'],
|
|
90
|
+
templates: './dist/templates',
|
|
91
|
+
}),
|
|
89
92
|
})
|
|
90
93
|
```
|
|
91
94
|
|
|
92
|
-
`
|
|
95
|
+
`vite build` emits `.j2` templates plus client JS under `templates` / Vite's own `build.outDir`. On the Rust
|
|
93
96
|
side, depend on the `barefootjs` crate, build the `Environment` via
|
|
94
97
|
`build_environment` (per the contract above), and render a component
|
|
95
98
|
through a `RenderSession` + root `BfInstance`:
|
|
@@ -1,157 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Vendor code-splitting
|
|
3
|
-
description: Split large vendor libraries into separately-cached browser chunks via
|
|
3
|
+
description: Split large vendor libraries into separately-cached browser chunks via Vite's own `manualChunks`
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Vendor code-splitting
|
|
7
7
|
|
|
8
|
-
Apps that embed large libraries (xyflow, yjs, etc.) alongside BarefootJS components can reach 700–800 KB of client JS on first visit. Splitting those libraries out as separate browser chunks dramatically cuts repeat-visit transfer
|
|
8
|
+
Apps that embed large libraries (xyflow, yjs, etc.) alongside BarefootJS components can reach 700–800 KB of client JS on first visit. Splitting those libraries out as separate browser chunks dramatically cuts repeat-visit transfer.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
- **Warm visit**: ~70 % faster because only the changed component JS hits the network
|
|
12
|
-
|
|
13
|
-
## Configuration
|
|
14
|
-
|
|
15
|
-
Add an `externals` map to `barefoot.config.ts`. The CLI copies each package's browser-ready bundle to your output directory and emits `barefoot-externals.json`.
|
|
10
|
+
BarefootJS has no config of its own for this — vendor code-splitting is Vite's job. Use stock Vite/Rollup config alongside the `barefoot()` plugin:
|
|
16
11
|
|
|
17
12
|
```ts
|
|
18
|
-
//
|
|
19
|
-
import { defineConfig } from '
|
|
20
|
-
import {
|
|
13
|
+
// vite.config.ts
|
|
14
|
+
import { defineConfig } from 'vite'
|
|
15
|
+
import { barefoot } from '@barefootjs/vite'
|
|
21
16
|
|
|
22
17
|
export default defineConfig({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// CDN passthrough — no local copy, importmap points at the remote URL
|
|
35
|
-
lodash: { url: 'https://esm.sh/lodash@4.17.21', preload: true },
|
|
18
|
+
plugins: [barefoot({ /* ... */ })],
|
|
19
|
+
build: {
|
|
20
|
+
rollupOptions: {
|
|
21
|
+
output: {
|
|
22
|
+
// Split heavy vendor libraries into their own cacheable chunk.
|
|
23
|
+
manualChunks: {
|
|
24
|
+
xyflow: ['@barefootjs/xyflow'],
|
|
25
|
+
yjs: ['yjs'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
36
29
|
},
|
|
37
30
|
})
|
|
38
31
|
```
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
| Shape | Effect |
|
|
43
|
-
|---|---|
|
|
44
|
-
| `true` | Copy browser-ready entry to `outDir`, auto-resolve via `umd` → `unpkg` → `jsdelivr` → `import` |
|
|
45
|
-
| `{ preload: true }` | Same as `true`, also adds a preload hint to `barefoot-externals.json` |
|
|
46
|
-
| `{ url: string }` | CDN passthrough — skip copy, use URL as-is in importmap |
|
|
47
|
-
| `{ url: string, preload: true }` | CDN passthrough + preload hint |
|
|
48
|
-
|
|
49
|
-
### externalsBasePath
|
|
50
|
-
|
|
51
|
-
URL prefix for vendor chunk entries in the emitted importmap. Defaults to `/<runtimeSubdir>/` (e.g., `/components/` when using the default output layout). Set this explicitly if your static files are served from a different path:
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
externalsBasePath: '/static/components/'
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## What the CLI emits
|
|
58
|
-
|
|
59
|
-
After build, `dist/barefoot-externals.json` contains three sections:
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"importmap": {
|
|
64
|
-
"imports": {
|
|
65
|
-
"@barefootjs/xyflow": "/static/components/xyflow.js",
|
|
66
|
-
"yjs": "/static/components/yjs.js",
|
|
67
|
-
"lodash": "https://esm.sh/lodash@4.17.21",
|
|
68
|
-
"@barefootjs/client": "/static/components/barefoot.js",
|
|
69
|
-
"@barefootjs/client/runtime": "/static/components/barefoot.js",
|
|
70
|
-
"@barefootjs/client/reactive": "/static/components/barefoot.js"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
"preloads": [
|
|
74
|
-
"/static/components/yjs.js",
|
|
75
|
-
"https://esm.sh/lodash@4.17.21"
|
|
76
|
-
],
|
|
77
|
-
"externals": [
|
|
78
|
-
"@barefootjs/xyflow",
|
|
79
|
-
"yjs",
|
|
80
|
-
"lodash",
|
|
81
|
-
"@barefootjs/client",
|
|
82
|
-
"@barefootjs/client/runtime",
|
|
83
|
-
"@barefootjs/client/reactive"
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
**`@barefootjs/client*` dedup is automatic.** Whenever `externals` is non-empty, the three `@barefootjs/client*` importmap entries are added unconditionally. This prevents reactive-primitive duplication — a class of silent failure where forgetting one entry inlines a second copy of the reactive runtime and breaks signals / context across the module boundary (see #927).
|
|
89
|
-
|
|
90
|
-
## Wiring the importmap into your renderer
|
|
91
|
-
|
|
92
|
-
Read `barefoot-externals.json` at startup and inject it into the HTML shell:
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
// renderer.tsx
|
|
96
|
-
import externalsManifest from './dist/barefoot-externals.json'
|
|
97
|
-
|
|
98
|
-
const importMapScript = JSON.stringify(externalsManifest.importmap)
|
|
99
|
-
|
|
100
|
-
export const renderer = jsxRenderer(({ children }) => (
|
|
101
|
-
<html>
|
|
102
|
-
<head>
|
|
103
|
-
<script type="importmap" dangerouslySetInnerHTML={{ __html: importMapScript }} />
|
|
104
|
-
{externalsManifest.preloads.map(href => (
|
|
105
|
-
<link rel="modulepreload" href={href} />
|
|
106
|
-
))}
|
|
107
|
-
</head>
|
|
108
|
-
<body>
|
|
109
|
-
{children}
|
|
110
|
-
<BfScripts />
|
|
111
|
-
</body>
|
|
112
|
-
</html>
|
|
113
|
-
))
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## Template-string adapters
|
|
117
|
-
|
|
118
|
-
Some adapters have no render-time component like Hono's `BfImportMap` to read the manifest — they target a template-string language where you hand-write the HTML `<head>`. An adapter declares this by setting `importMapInjection: 'html-snippet'` (component-based adapters set `'component'` instead). For `html-snippet` adapters, `bf build` also emits a ready-to-include **`barefoot-importmap.html`** snippet next to `barefoot-externals.json`, generated from the same manifest:
|
|
119
|
-
|
|
120
|
-
```html
|
|
121
|
-
<!-- dist/barefoot-importmap.html -->
|
|
122
|
-
<script type="importmap">{"imports":{"@barefootjs/client":"/static/components/barefoot.js","yjs":"/static/components/yjs.js","lodash":"https://esm.sh/lodash@4.17.21"}}</script>
|
|
123
|
-
<link rel="modulepreload" href="/static/components/yjs.js" crossorigin>
|
|
124
|
-
<link rel="modulepreload" href="https://esm.sh/lodash@4.17.21" crossorigin>
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Include this file in your page `<head>` using your template language's native include directive, and wire the build's output directory into the template search path so it resolves. The exact directive is language-specific — see your adapter's own documentation for the form it uses.
|
|
128
|
-
|
|
129
|
-
Which strategy an adapter uses is the single source of truth in its `TemplateAdapter.importMapInjection` value, enforced for every adapter by the cross-adapter importmap-injection contract in `@barefootjs/adapter-tests` — so this page does not need an entry per adapter.
|
|
130
|
-
|
|
131
|
-
## Using the externals list in your own bun build
|
|
132
|
-
|
|
133
|
-
The `externals` array in `barefoot-externals.json` lists every package that the browser will load via the importmap. Pass these as `--external` flags when bundling your app entries:
|
|
134
|
-
|
|
135
|
-
```sh
|
|
136
|
-
# Shell — build your DeskCanvas.tsx with all externals applied
|
|
137
|
-
EXTERNALS=$(jq -r '.externals[]' dist/barefoot-externals.json | sed 's/^/--external /' | tr '\n' ' ')
|
|
138
|
-
bun build worker/components/canvas/DeskCanvas.tsx \
|
|
139
|
-
--outfile dist/static/components/canvas.js \
|
|
140
|
-
--format esm --minify \
|
|
141
|
-
$EXTERNALS
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Or in JavaScript:
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
import manifest from './dist/barefoot-externals.json'
|
|
148
|
-
|
|
149
|
-
await Bun.build({
|
|
150
|
-
entrypoints: ['./worker/components/canvas/DeskCanvas.tsx'],
|
|
151
|
-
outdir: './dist/static/components',
|
|
152
|
-
naming: 'canvas.[ext]',
|
|
153
|
-
format: 'esm',
|
|
154
|
-
minify: true,
|
|
155
|
-
external: manifest.externals,
|
|
156
|
-
})
|
|
157
|
-
```
|
|
33
|
+
Vite's dev server and production build both content-hash and cache these chunks automatically — no manifest to wire up by hand, and no `--external` flags to compute for a separate bundler pass. See [Vite's own code-splitting docs](https://vite.dev/guide/build.html#chunking-strategy) for `manualChunks`, dynamic `import()`, and `build.rollupOptions.output`.
|
|
@@ -49,6 +49,17 @@ cp node_modules/@barefootjs/xyflow/dist/xyflow.browser.min.js.map \
|
|
|
49
49
|
|
|
50
50
|
The three `@barefootjs/client*` entries all pointing at the same file is what makes the browser deduplicate them into a single module instance, so reactive primitives share one `Listener`/`Owner` global.
|
|
51
51
|
|
|
52
|
+
Two things to get right when hand-writing this snippet:
|
|
53
|
+
|
|
54
|
+
- **Escape `<` inside the importmap JSON.** A mapped URL containing `</script>` (unlikely for a static local path like the ones above, but possible if a URL is assembled dynamically) would close the `<script type="importmap">` element early. Before writing the serialized JSON into the `<script>` tag, replace every `<` character with its six-character Unicode escape for code point U+003C (backslash, `u`, `0`, `0`, `3`, `c`) — the JSON parser decodes that escape straight back to the original character, so the mapping itself is unaffected.
|
|
55
|
+
- **Add `crossorigin` if you also `modulepreload` a cross-origin URL** — e.g. pointing straight at the unpkg/jsDelivr URL from "package.json fields" below instead of the copied local file:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<link rel="modulepreload" href="https://unpkg.com/@barefootjs/xyflow" crossorigin>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The actual `import` of a cross-origin module is always a CORS fetch, so without `crossorigin` the preload request doesn't match it — the browser discards the preload and fetches the module a second time. Harmless to include on a same-origin preload too, since the credentials mode is the same either way.
|
|
62
|
+
|
|
52
63
|
## package.json fields
|
|
53
64
|
|
|
54
65
|
The file is also exposed via the `umd` export condition and the `unpkg`/`jsdelivr` top-level fields:
|
package/dist/docs/core/llms.txt
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
|
|
53
53
|
## Advanced
|
|
54
54
|
|
|
55
|
-
- [Vendor code-splitting](https://barefootjs.dev/docs/advanced/code-splitting.md): Split large vendor libraries into separately-cached browser chunks via
|
|
55
|
+
- [Vendor code-splitting](https://barefootjs.dev/docs/advanced/code-splitting.md): Split large vendor libraries into separately-cached browser chunks via Vite's own `manualChunks`
|
|
56
56
|
- [Compiler Internals](https://barefootjs.dev/docs/advanced/compiler-internals.md): How the BarefootJS compiler transforms JSX into marked templates and client JavaScript.
|
|
57
57
|
- [Error Codes Reference](https://barefootjs.dev/docs/advanced/error-codes.md): BF-prefixed compiler error codes with explanations and fixes.
|
|
58
58
|
- [IR Schema Reference](https://barefootjs.dev/docs/advanced/ir-schema.md): JSON tree structure of the Intermediate Representation consumed by adapters and client-JS generation.
|
|
@@ -33,7 +33,7 @@ npm run dev
|
|
|
33
33
|
|
|
34
34
|
`npm run dev` runs three processes in parallel:
|
|
35
35
|
|
|
36
|
-
- `
|
|
36
|
+
- `vite dev` — the BarefootJS compiler, wired in as a Vite plugin. Watches `components/` and serves marked templates plus client JS from `public/components/`.
|
|
37
37
|
- `unocss --watch` — scans your JSX for utility classes and writes `public/uno.css`.
|
|
38
38
|
- `wrangler dev --live-reload` — Cloudflare's local Workers runtime. Serves the app and reloads the browser on rebuilds.
|
|
39
39
|
|
|
@@ -52,8 +52,8 @@ my-app/
|
|
|
52
52
|
├── public/ # Static assets served by Workers
|
|
53
53
|
│ ├── tokens.css # CSS design tokens
|
|
54
54
|
│ ├── styles.css # Counter + page styles
|
|
55
|
-
│ └── components/ # Generated client JS (
|
|
56
|
-
├──
|
|
55
|
+
│ └── components/ # Generated client JS (vite build writes here)
|
|
56
|
+
├── vite.config.ts # Compiler (barefoot plugin) + Vite build config
|
|
57
57
|
├── wrangler.jsonc # Cloudflare Workers config
|
|
58
58
|
└── uno.config.ts # UnoCSS scan patterns
|
|
59
59
|
```
|
|
@@ -148,7 +148,7 @@ When you're ready to ship:
|
|
|
148
148
|
npm run deploy
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
This runs `
|
|
151
|
+
This runs `vite build`, generates the final `uno.css`, and calls `wrangler deploy`. The first deploy will prompt you to log into Cloudflare. After that, your app is live on `*.workers.dev`.
|
|
152
152
|
|
|
153
153
|
## Next steps
|
|
154
154
|
|