-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Local developement module entry | ||
* | ||
* Change `@nuxt/devtools` to the absolute path of this module in any of your Nuxt projects, | ||
* allows you to try Nuxt Devtools locally directly from the source code. HMR is supported | ||
* for the front-end client. | ||
* | ||
* For example, if you clone this repo to `/users/me/nuxt-devtools`, update your nuxt config: | ||
* | ||
* ```diff | ||
* // nuxt.config.ts | ||
* export default defineNuxtConfig({ | ||
* modules: [ | ||
* - '@nuxt/devtools', | ||
* + '/users/me/nuxt-devtools/local', | ||
* ] | ||
* }) | ||
* ``` | ||
*/ | ||
import { defineNuxtModule, logger } from '@nuxt/kit' | ||
import { execa } from 'execa' | ||
import { resolve } from 'pathe' | ||
import { getPort } from 'get-port-please' | ||
import { ROUTE_CLIENT, defaultOptions } from './packages/devtools/src/constant' | ||
import type { ModuleOptions } from './packages/devtools/src/types' | ||
import { packageDir } from './packages/devtools/src/dirs' | ||
import { enableModule } from './packages/devtools/src/module-main' | ||
|
||
export type { ModuleOptions } | ||
|
||
export default defineNuxtModule<ModuleOptions>({ | ||
meta: { | ||
name: '@nuxt/devtools', | ||
configKey: 'devtools', | ||
}, | ||
defaults: defaultOptions, | ||
async setup(options, nuxt) { | ||
const clientDir = resolve(packageDir, 'client') | ||
const workspaceRoot = resolve(packageDir, '../..') | ||
const PORT = await getPort({ port: 12442 }) | ||
|
||
// TODO: add embedded terminal and forward logs to it | ||
const subprocess = execa('npx', ['nuxi', 'dev', '--port', PORT.toString()], { cwd: clientDir, stdio: 'pipe' }) | ||
subprocess.stderr?.pipe(process.stderr) | ||
|
||
nuxt.hook('vite:extendConfig', (config) => { | ||
config.server ||= {} | ||
// add proxy to client | ||
config.server.proxy ||= {} | ||
config.server.proxy[ROUTE_CLIENT] = { | ||
target: `http://localhost:${PORT}`, | ||
changeOrigin: true, | ||
followRedirects: true, | ||
} | ||
// add fs allow for local modules | ||
config.server.fs ||= {} | ||
config.server.fs.allow ||= [] | ||
config.server.fs.allow.push(workspaceRoot) | ||
}) | ||
|
||
logger.info(`Nuxt Devtools is using local client from \`${clientDir}\``) | ||
|
||
return enableModule(options, nuxt) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ModuleOptions } from '@nuxt/schema' | ||
|
||
export const ROUTE_PATH = '/__nuxt_devtools__' | ||
export const ROUTE_ENTRY = `${ROUTE_PATH}/entry` | ||
export const ROUTE_CLIENT = `${ROUTE_PATH}/client` | ||
|
||
export const defaultOptions: ModuleOptions = { | ||
enabled: undefined, | ||
vscode: { | ||
enabled: true, | ||
startOnBoot: false, | ||
port: 3080, | ||
reuseExistingServer: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ModuleCustomTab } from './types' | ||
|
||
declare module '@nuxt/schema' { | ||
interface NuxtHooks { | ||
/** | ||
* Called before devtools starts. Useful to detect if devtools is enabled. | ||
*/ | ||
'devtools:before': () => void | ||
|
||
/** | ||
* Called after devtools is initialized. | ||
*/ | ||
'devtools:initialized': () => void | ||
|
||
/** | ||
* Hooks to extend devtools tabs. | ||
*/ | ||
'devtools:customTabs': (tabs: ModuleCustomTab[]) => void | ||
|
||
/** | ||
* Retrigger update for custom tabs, `devtools:customTabs` will be called again. | ||
*/ | ||
'devtools:customTabs:refresh': () => void | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.