Skip to content

Commit 39470fd

Browse files
antfubotantfu
andauthored
feat: serve the client UI as devframe remote assets via @nuxt/devtools-assets (#1071)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent f7b1719 commit 39470fd

21 files changed

Lines changed: 239 additions & 228 deletions

File tree

‎knip.jsonc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
"playground/nuxt.config.ts"
6464
]
6565
},
66+
// The assets package is never imported: it only satisfies the runtime
67+
// package resolution of the client UI's remote-assets source (see
68+
// `resolveClientAssetsSource` in `src/module-main.ts`), keeping the
69+
// monorepo/e2e flows serving the local build with zero network.
70+
"ignoreDependencies": [
71+
"@nuxt/devtools-assets"
72+
],
6673
"entry": [
6774
"scripts/*.mjs",
6875
"src/webcomponents/scripts/*.ts",

‎packages/devtools-assets/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# @nuxt/devtools-assets
2+
3+
Pre-built client UI assets for [Nuxt DevTools](https://github.com/nuxt/devtools).
4+
5+
`@nuxt/devtools` does not bundle its client UI. Instead, it declares this
6+
version-locked package as [devframe remote assets](https://devfra.me/guide/client-assets.html#remote-assets):
7+
files are resolved from a locally installed copy of this package when present,
8+
otherwise streamed on demand from a CDN mirror of npm and cached on disk.
9+
10+
You normally don't need to install this package. For offline or air-gapped
11+
environments, install it explicitly so the UI is served with zero network:
12+
13+
```sh
14+
npm install -D @nuxt/devtools-assets
15+
```
16+
17+
Keep its version in lockstep with `@nuxt/devtools` (it is published together
18+
with each release).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@nuxt/devtools-assets",
3+
"type": "module",
4+
"version": "4.0.0-alpha.12",
5+
"description": "Pre-built client UI assets for Nuxt DevTools, resolved on demand.",
6+
"license": "MIT",
7+
"homepage": "https://devtools.nuxt.com",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/nuxt/devtools.git",
11+
"directory": "packages/devtools-assets"
12+
},
13+
"exports": {
14+
"./package.json": "./package.json"
15+
},
16+
"files": [
17+
"dist"
18+
],
19+
"scripts": {
20+
"build": "pnpm -C ../devtools run build:client",
21+
"prepack": "turbo run build --filter=@nuxt/devtools-assets"
22+
}
23+
}

‎packages/devtools-kit/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build": "unbuild",
2525
"stub": "unbuild --stub",
2626
"dev:prepare": "nr stub",
27-
"prepack": "pnpm build"
27+
"prepack": "turbo run build --filter=@nuxt/devtools-kit"
2828
},
2929
"peerDependencies": {
3030
"@nuxt/kit": "^4.0.0-0 || ^5.0.0-0",

‎packages/devtools-kit/src/_types/client-api.ts‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ import type { NuxtDevtoolsNotifyInput } from './notify'
1111
importtype{ServerFunctions}from'./rpc'
1212
importtype{TimelineMetrics}from'./timeline-metrics'
1313

14-
exportinterfaceDevToolsFrameState{
15-
width: number
16-
height: number
17-
top: number
18-
left: number
19-
open: boolean
20-
route: string
21-
position: 'left'|'right'|'bottom'|'top'
22-
closeOnOutsideClick: boolean
23-
minimizePanelInactive: number
24-
}
25-
2614
exportinterfaceNuxtDevtoolsClientHooks{
2715
/**
2816
* When the DevTools navigates, used for persisting the current tab
@@ -57,8 +45,6 @@ export interface NuxtDevtoolsHostClient {
5745
nuxt: NuxtApp
5846
hooks: Hookable<NuxtDevtoolsClientHooks>
5947

60-
getIframe: ()=>HTMLIFrameElement|undefined
61-
6248
inspector?: {
6349
enable: ()=>void
6450
disable: ()=>void
@@ -80,7 +66,6 @@ export interface NuxtDevtoolsHostClient {
8066
navigate: (path: string,hard?: boolean)=>void
8167
appConfig: AppConfig
8268
colorMode: Ref<'dark'|'light'>
83-
frameState: Ref<DevToolsFrameState>
8469
$fetch: $Fetch
8570
}
8671

@@ -95,12 +80,6 @@ export interface NuxtDevtoolsHostClient {
9580
* A counter to trigger reactivity updates
9681
*/
9782
revision: Ref<number>
98-
99-
/**
100-
* Update client
101-
* @internal
102-
*/
103-
syncClient: ()=>NuxtDevtoolsHostClient
10483
}
10584

10685
exportinterfaceCodeHighlightOptions{
@@ -152,7 +131,3 @@ export interface NuxtDevtoolsIframeClient {
152131
host: NuxtDevtoolsHostClient
153132
devtools: NuxtDevtoolsClient
154133
}
155-
156-
exportinterfaceNuxtDevtoolsGlobal{
157-
setClient: (client: NuxtDevtoolsHostClient)=>void
158-
}

‎packages/devtools-kit/src/_types/options.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ export interface ModuleOptions {
6969
*/
7070
disableAuthorization?: boolean
7171

72-
/**
73-
* Props for the iframe element, useful for environment with stricter CSP
74-
*/
75-
iframeProps?: Record<string,string|boolean>
76-
7772
/**
7873
* Experimental features
7974
*/

‎packages/devtools-ui-kit/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"build": "nuxt-build-module build",
2424
"stub": "nuxt-build-module build --stub",
2525
"dev": "nuxi dev playground",
26-
"prepack": "pnpm build",
26+
"prepack": "turbo run build --filter=@nuxt/devtools-ui-kit",
2727
"playground:build": "nuxi generate playground"
2828
},
2929
"peerDependencies": {

‎packages/devtools/client/app.vue‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ useHead({
3232
{
3333
rel: 'icon',
3434
type: 'image/svg+xml',
35-
href: '/nuxt.svg',
35+
// Relative: resolves against the document URL, which is always the
36+
// client's mount root (the production build uses hash routing).
37+
href: './nuxt.svg',
3638
},
3739
],
3840
})

‎packages/devtools/client/composables/storage.ts‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎packages/devtools/client/nuxt.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export default defineNuxtConfig({
6161
// We set a placeholder for the middleware to be replaced with the correct base URL
6262
baseURL: '/__NUXT_DEVTOOLS_BASE__/',
6363
},
64+
router: {
65+
options: {
66+
// Hash routing keeps the document URL at the mount root, so relative
67+
// asset URLs always resolve regardless of the active tab route.
68+
hashMode: true,
69+
},
70+
},
6471
},
6572

6673
ssr: false,

0 commit comments

Comments
 (0)