配置
大约 3 分钟
选项
你可以设置以下插件选项来启用或禁用一些功能。
playground
PlaygroundGlobalOptions交互演示选项。
参考:交互演示。
playground.presets必填
(BuiltInPlaygroundPreset | PlaygroundOptions)[]交互演示预设。BuiltInPlaygroundPreset 为 "ts"、"vue" 或 "unocss" 之一,会启用内置预设,而对象则用于配置自定义交互演示。
playground.presets[*].name必填
string交互演示容器名。
playground.presets[*].component
string默认值
"Playground"交互演示组件名称。
playground.presets[*].propsGetter必填
(data: PlaygroundData) => Record<string, string>属性获取器。其 data 参数类型如下:
interface PlaygroundCodeConfig {
/**
* 代码块扩展名
*
* @description 它基于文件名,而不是代码块语言
*/
ext: string;
/** 代码块内容 */
content: string;
}
interface PlaygroundData {
/** 交互演示标题 */
title?: string;
/**
* Import map 文件名
*
* @default "import-map.json"
*/
importMap?: string;
/** 交互演示文件信息 */
files: Record<
/** 文件名 */
string,
/** 文件详情 */
PlaygroundCodeConfig
>;
/**
* 交互演示设置
*
* @description 它是设置指令后的 json 内容的解析结果
*/
settings: Record<string, unknown>;
/**
* hash key based on playground content
*
* 根据交互演示内容生成的 hash key
*/
key: string;
}playground.config
{ ts?: TSPresetPlaygroundOptions; vue?: VuePresetPlaygroundOptions; unocss?: UnoPresetPlaygroundOptions }内置预设的交互演示配置。
playground.config.ts
TSPresetPlaygroundOptionsts 预设的选项。
playground.config.ts.service
string默认值
"https://www.typescriptlang.org/play"交互演示外部地址。
playground.config.vue
VuePresetPlaygroundOptionsvue 预设的选项。
playground.config.vue.service
string默认值
"https://sfc.vuejs.org/"交互演示外部地址。
playground.config.vue.dev
boolean是否启用开发版本。
playground.config.vue.ssr
boolean是否启用 SSR。
playground.config.unocss
UnoPresetPlaygroundOptionsunocss 预设的选项。
playground.config.unocss.service
string默认值
"https://unocss.dev/play"交互演示外部地址。
kotlinPlayground
boolean是否启用 Kotlin 交互演示支持。
参考:Kotlin 交互演示。
vuePlayground
boolean是否启用 Vue 交互演示支持。
参考:Vue 交互演示。
demo
Partial<CodeDemoOptions> | boolean是否启用代码案例支持。
参考:代码案例。
demo.jsLib
string[]CodePen, JsFiddle 需要引入的外部 JS 库。
demo.cssLib
string[]CodePen, JsFiddle 需要引入的外部 CSS 库。
注意
上述两个选项仅仅是给第三方代码演示使用的,你需要自行在 head 中导入这些库。
demo.jsfiddle
boolean默认值
true是否显示 JSFiddle 按钮。
demo.codepen
boolean默认值
true是否显示 CodePen 按钮。
demo.codepenLayout
"top" | "left" | "right"默认值
"left"CodePen 编辑器布局。
demo.codepenEditors
string默认值
"101"CodePen 编辑器状态。
以下是第三方代码演示使用的库地址,除非你的环境无法访问 unpkg 或访问缓慢,否则无需覆盖默认设置。
demo.babel
string默认值
"https://unpkg.com/@babel/standalone/babel.min.js"demo.vue
string默认值
"https://unpkg.com/vue/dist/vue.global.prod.js"demo.react
string默认值
"https://unpkg.com/react/umd/react.production.min.js"demo.reactDOM
string默认值
"https://unpkg.com/react-dom/umd/react-dom.production.min.js"sandpack
boolean是否启用 Sandpack 交互演示。
客户端配置
defineKotlinPlaygroundConfig
interface KotlinPlaygroundOptions {
server?: string;
version?: string;
onChange?: (code: string) => void;
onRun?: () => void;
onError?: () => void;
getJsCode?: (code: string) => void;
onTestPassed?: () => void;
onTestFailed?: () => void;
onOpenConsole?: () => void;
onCloseConsole?: () => void;
callback?: (targetNode: HTMLElement, mountNode: HTMLElement) => void;
getInstance?: (instance: KotlinPlaygroundInstance) => void;
}
const defineKotlinPlaygroundConfig: (options: KotlinPlaygroundOptions) => void;定义需要传递给 kotlin-playground 的配置选项。
defineSandpackConfig
interface SandpackConfig {
/**
* 指定模板
*/
template?: SandpackPredefinedTemplate;
/**
* sandpack 配置项
*/
options?: SandpackOptions;
/**
* sandpack customSetup 配置项
*/
customSetup?: SandpackSetup;
}
const defineSandpackConfig = (config: SandpackConfig)=> void定义需要传递给 sandpack-vue3 的选项。
defineVuePlaygroundConfig
export interface VuePlaygroundOptions extends Omit<
ReplProps,
"store" | "editor"
> {
/**
* 指定 vue 版本
*/
vueVersion?: string;
/**
* 指定默认的 Vue 开发运行时
*
* @default "https://unpkg.com/@vue/runtime-dom@${version}/dist/runtime-dom.esm-browser.js"
*/
vueRuntimeDevUrl?: string | (() => string);
/**
* 指定默认的 Vue 生产运行时
*
* @default "https://unpkg.com/@vue/runtime-dom@${version}/dist/runtime-dom.esm-browser.prod.js"
*/
vueRuntimeProdUrl?: string | (() => string);
/**
* 指定默认的 Vue 服务端渲染器
*
* @default "https://unpkg.com/@vue/server-renderer@${version}/dist/server-renderer.esm-browser.js"
*/
vueServerRendererUrl?: string | (() => string);
}
const defineVuePlaygroundConfig: (options: VuePlaygroundOptions) => void;定义需要传递给 @vue/repl 的选项。
更新日志
2026/9/28 12:45
查看所有更新日志
0c1aa-于9a4c3-于7d390-于660a5-于c9017-于70692-于22787-于99f51-于6ad69-于3dcc0-于913bb-于f0fcc-于92957-于8cb86-于d544c-于95198-于497db-于fa8af-于1669d-于7bc15-于bac94-于2dbdd-于55ea3-于f55f2-于8e9aa-于539b3-于f0736-于def96-于254c5-于ef5af-于a648a-于f6ff7-于573c3-于16ff1-于d06e4-于a7a28-于12ecd-于91679-于d0c25-于0eb18-于af82c-于edf2d-于4104e-于1c52f-于74050-于c5742-于1433d-于6e91a-于b4289-于6639c-于8b5af-于0e45a-于9fcf5-于23f74-于3dac6-于feeb6-于637b2-于7c8cf-于2fa50-于1d7fa-于86cc2-于5498b-于099d8-于80eb7-于57c57-于48bca-于63d09-于ad023-于88e69-于6d302-于e07b5-于904c0-于227bc-于1d0f9-于67429-于4d1ba-于907b9-于8dc9f-于fca17-于ace60-于