Dev Server - Enable `--remote` by Default in Containers
Is your feature request related to a problem? Please describe.
When developing inside a devcontainer, the "Slidev: Start the dev server" option is useless due to the fact the ethernet device is not bound.
The dev server absolute does open the browser, but the page will never load.
Describe the solution you'd like
I would like to add is-inside-container to the dev server. When true, make --remote the default. Additionally, consider adding a new --no-remote option to turn off the binding.
Describe alternatives you've considered
Running the server manually...
Seems like the change would be something like this?
diff --git a/packages/slidev/node/cli.ts b/packages/slidev/node/cli.ts
index 1d23fe3ce110..e5953510237d 100644
--- a/packages/slidev/node/cli.ts
+++ b/packages/slidev/node/cli.ts
@@ -6,6 +6,7 @@ import * as readline from 'node:readline'
import process from 'node:process'
import fs from 'fs-extra'
import openBrowser from 'open'
+import isInsideContainer from 'is-inside-container'
import type { Argv } from 'yargs'
import yargs from 'yargs'
import { blue, bold, cyan, dim, gray, green, underline, yellow } from 'kolorist'
@@ -80,6 +81,7 @@ cli.command(
.option('remote', {
type: 'string',
describe: 'listen public host and enable remote control',
+ default: isInsideContainer() ? "" : undefined,
})
.option('tunnel', {
default: false,
diff --git a/packages/slidev/package.json b/packages/slidev/package.json
index 4ac690998f11..9991c74e7019 100644
--- a/packages/slidev/package.json
+++ b/packages/slidev/package.json
@@ -74,6 +74,7 @@
"get-port-please": "^3.1.2",
"global-directory": "^4.0.1",
"htmlparser2": "^9.1.0",
+ "is-inside-container": "^1.0.0",
"is-installed-globally": "^1.0.0",
"jiti": "^1.21.6",
"katex": "^0.16.11",
I am unsure how to go about testing. This is the first time I've used pnpm monorepo.
This can now be done by customizing the slidev.dev-command configuration of the VSCode extension.
Also, if VSCode's env.remoteName != null, now the --remote flag will be automatically added.