Skip to content

Commit 00d2884

Browse files
committed
feat: new --inspect option
1 parent 0f4a8c7 commit 00d2884

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

demo/starter/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"@slidev/theme-default": "^0.21.2",
1111
"@slidev/theme-seriph": "^0.21.3",
1212
"@slidev/types": "workspace:*",
13-
"nodemon": "^2.0.19",
14-
"vite-plugin-inspect": "^0.7.1"
13+
"nodemon": "^2.0.19"
1514
}
1615
}

demo/starter/vite.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import Inspect from 'vite-plugin-inspect'
21
import { defineConfig } from 'vite'
32

43
export default defineConfig({
54
plugins: [
6-
Inspect({
7-
dev: true,
8-
}),
95
],
106
})

packages/slidev/node/cli.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ cli.command(
6363
choices: ['error', 'warn', 'info', 'silent'],
6464
describe: 'log level',
6565
})
66+
.option('inspect', {
67+
default: false,
68+
type: 'boolean',
69+
describe: 'enable the inspect plugin for debugging',
70+
})
6671
.option('force', {
6772
alias: 'f',
6873
default: false,
@@ -71,7 +76,7 @@ cli.command(
7176
})
7277
.strict()
7378
.help(),
74-
async ({ entry, theme, port: userPort, open, log, remote, force }) => {
79+
async ({ entry, theme, port: userPort, open, log, remote, force, inspect }) => {
7580
if (!fs.existsSync(entry) && !entry.endsWith('.md'))
7681
entry = `${entry}.md`
7782

@@ -94,7 +99,7 @@ cli.command(
9499
async function initServer() {
95100
if (server)
96101
await server.close()
97-
const options = await resolveOptions({ entry, remote, theme }, 'dev')
102+
const options = await resolveOptions({ entry, remote, theme, inspect }, 'dev')
98103
port = userPort || await findFreePort(3030)
99104
server = (await createServer(
100105
options,
@@ -204,12 +209,17 @@ cli.command(
204209
type: 'boolean',
205210
describe: 'allow download as PDF',
206211
})
212+
.option('inspect', {
213+
default: false,
214+
type: 'boolean',
215+
describe: 'enable the inspect plugin for debugging',
216+
})
207217
.strict()
208218
.help(),
209-
async ({ entry, theme, watch, base, download, out }) => {
219+
async ({ entry, theme, watch, base, download, out, inspect }) => {
210220
const { build } = await import('./build')
211221

212-
const options = await resolveOptions({ entry, theme }, 'build')
222+
const options = await resolveOptions({ entry, theme, inspect }, 'build')
213223
if (download && !options.data.config.download)
214224
options.data.config.download = download
215225

@@ -411,6 +421,8 @@ function printInfo(options: ResolvedSlidevOptions, port?: number, remote?: strin
411421
if (query)
412422
console.log(`${dim(' private slide show ')} > ${cyan(`http://localhost:${bold(port)}/${query}`)}`)
413423
console.log(`${dim(' presenter mode ')} > ${blue(`http://localhost:${bold(port)}${presenterPath}`)}`)
424+
if (options.inspect)
425+
console.log(`${dim(' inspector')} > ${yellow(`http://localhost:${bold(port)}/__inspect/`)}`)
414426

415427
if (remote !== undefined) {
416428
Object.values(os.networkInterfaces())

packages/slidev/node/options.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface SlidevEntryOptions {
4242
* @default process.cwd()
4343
*/
4444
userRoot?: string
45+
46+
/**
47+
* Enable inspect plugin
48+
*/
49+
inspect?: boolean
4550
}
4651

4752
export interface ResolvedSlidevOptions {
@@ -56,6 +61,7 @@ export interface ResolvedSlidevOptions {
5661
roots: string[]
5762
mode: 'dev' | 'build'
5863
remote?: string
64+
inspect?: boolean
5965
}
6066

6167
export interface SlidevPluginOptions extends SlidevEntryOptions {
@@ -116,7 +122,7 @@ export async function resolveOptions(
116122
mode: ResolvedSlidevOptions['mode'],
117123
promptForInstallation = true,
118124
): Promise<ResolvedSlidevOptions> {
119-
const { remote } = options
125+
const { remote, inspect } = options
120126
const {
121127
entry,
122128
userRoot,
@@ -175,5 +181,6 @@ export async function resolveOptions(
175181
addonRoots,
176182
roots,
177183
remote,
184+
inspect,
178185
}
179186
}

packages/slidev/node/plugins/preset.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Components from 'unplugin-vue-components/vite'
77
import RemoteAssets, { DefaultRules } from 'vite-plugin-remote-assets'
88
import ServerRef from 'vite-plugin-vue-server-ref'
99
import { notNullish } from '@antfu/utils'
10+
import Inspect from 'vite-plugin-inspect'
1011
import type { ResolvedSlidevOptions, SlidevPluginOptions, SlidevServerOptions } from '../options'
1112
import { loadDrawings, writeDrawings } from '../drawings'
1213
import { createConfigPlugin } from './extendConfig'
@@ -167,6 +168,13 @@ export async function ViteSlidevPlugin(
167168
createClientSetupPlugin(options),
168169
createMonacoTypesLoader(),
169170
createFixPlugins(options),
171+
172+
options.inspect
173+
? Inspect({
174+
dev: true,
175+
build: true,
176+
})
177+
: null,
170178
]
171179
.flat()
172180
.filter(notNullish)

packages/slidev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"unplugin-icons": "^0.14.9",
8989
"unplugin-vue-components": "^0.22.6",
9090
"vite": "^3.1.0",
91+
"vite-plugin-inspect": "^0.7.1",
9192
"vite-plugin-remote-assets": "^0.3.0",
9293
"vite-plugin-vue-markdown": "~0.20.1",
9394
"vite-plugin-vue-server-ref": "^0.3.0",

pnpm-lock.yaml

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)