Skip to content

StackBlitz ​

npm versionnpm monthly downloadsnpm sizenpm license

Embed StackBlitz projects into VitePress pages. Supports embedding online editors via StackBlitz ID, GitHub repository, or local project files. Can also display as a button to open in a new tab.

Installation ​

sh
pnpm add vitepress-plugin-stackblitz
sh
npm install vitepress-plugin-stackblitz
sh
bun add vitepress-plugin-stackblitz
sh
deno add vitepress-plugin-stackblitz
sh
yarn add vitepress-plugin-stackblitz

Usage ​

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress-tuck'
import stackblitz from 'vitepress-plugin-stackblitz'

export default defineConfig({
  plugins: [stackblitz()],
})

Learn more about vitepress-tuck

Native Mode ​

.vitepress/config.ts
ts
import { defineConfig } from 'vitepress'
import { stackblitzMarkdownPlugin } from 'vitepress-plugin-stackblitz'

export default defineConfig({
  markdown: {
    config: (md) => {
      md.use(stackblitzMarkdownPlugin)
    },
  },
})
.vitepress/theme/index.ts
ts
import type { Theme } from 'vitepress'
import { enhanceAppWithStackBlitz } from 'vitepress-plugin-stackblitz/client'
import DefaultTheme from 'vitepress/theme'

export default {
  extends: DefaultTheme,
  enhanceApp(ctx) {
    enhanceAppWithStackBlitz(ctx)
  },
} satisfies Theme

Syntax ​

The plugin provides two syntaxes for embedding StackBlitz projects: embed syntax for referencing external projects, and container syntax for writing project files directly inline within Markdown.

Embed by StackBlitz ID ​

md
@[stackblitz](sdk-github-project)

Embed by GitHub Repository ​

md
@[stackblitz github](user/repo)

Embed Local Project ​

Place a stackblitz.config.json (or .yaml, .yml) configuration file in your project directory, then use the local attribute:

md
@[stackblitz local](path/to/your/project)

path supports the following prefixes:

PrefixDescription
@Relative to VitePress srcDir
/Relative to VitePress project root
-Relative to the current markdown file's directory

See Local Project Configuration for more details.

Button Mode ​

Display as a button that opens the project in a new tab:

md
@[stackblitz button](stackblitz-id)

It can also be combined with GitHub:

md
@[stackblitz github button](user/repo)

Container Syntax ​

Write project files directly inline within Markdown, ideal for quickly demonstrating simple projects:

md
::: stackblitz title="Project" description="Project description" template="javascript"

```yml [config]
title: Project
template: javascript
description: Project description
```

```json [package.json]
{
  "name": "project",
  "version": "1.0.0"
}
```

```js [index.js]
console.log('Hello StackBlitz!');
```

```html [index.html]
<!DOCTYPE html>
<html lang="en">
<body>
  <h1>Hello StackBlitz!</h1>
  <script src="./index.js"></script>
</body>
</html>
```

:::

Attribute Reference ​

Embed / Open Options ​

Applicable to both embed syntax and button mode:

AttributeTypeDefaultDescription
theme'dark' | 'light' | 'default'autoColor theme, auto follows VitePress dark mode
view'default' | 'preview' | 'editor''default'Initial UI view
heightnumber400Embed height (embed mode only)
widthnumber-Embed width (embed mode only)
clickToLoadbooleanfalseShow "click to run" dialog
openFilestring | string[]-File(s) to open on load
hideExplorerbooleanfalseHide the file explorer
hideDevToolsbooleanfalseHide the dev tools console
showSidebarbooleanfalseShow sidebar as open on load
terminalHeightnumber (0-100)-Terminal height percentage
devToolsHeightnumber (0-100)-Dev tools height percentage
newWindowbooleanfalseOpen project in a new tab
forceEmbedLayoutbooleanfalseForce embed layout (deprecated)
originstring-StackBlitz EE instance URL

Project Options ​

Only applicable to local project embed mode and container syntax:

AttributeTypeDefaultDescription
titlestring-Project title (required)
descriptionstring-Project description (required)
template'angular-cli' | 'create-react-app' | 'html' | 'javascript' | 'typescript' | 'polymer' | 'vue' | 'node'-Project template (required)
dependenciesRecord<string, string>-npm dependencies
filesRecord<string, string>-Project files (auto-loaded for local mode)

Build Settings ​

Set via settings-prefixed attributes, only applicable to local project embed mode and container syntax:

AttributeTypeDefaultDescription
settingsTrigger'auto' | 'save' | 'keystroke''auto'Compilation trigger timing
settingsAction'hmr' | 'refresh''hmr'How to inject compiled changes
settingsClearConsolebooleantrueClear console after compilation
md
@[stackblitz local title="Demo" description="A demo" template="html" settingsTrigger="save" settingsAction="refresh"](path/to/project)

Local Project Configuration ​

When using @[stackblitz local](path) to embed a local project, the plugin automatically:

  1. Loads all files from the specified directory (excluding node_modules)
  2. Searches for stackblitz.config.json, stackblitz.config.yaml, stackblitz.config.yml in order
  3. Merges the configuration file options with the loaded files

Example stackblitz.config.json:

json
{
  "$schema": "../../node_modules/vitepress-plugin-stackblitz/schema.json",
  "title": "Project",
  "description": "Project description",
  "template": "javascript",
  "dependencies": {
    "lodash": "^4.17.0"
  },
  "settings": {
    "trigger": "save"
  }
}

TIP

Including the $schema field provides intelligent autocompletion and validation for configuration files in your editor.

json
{
  "$schema": "https://unpkg.com/vitepress-plugin-stackblitz/schema.json"
}

Example ​

StackBlitz ID Embed ​

md
@[stackblitz](sdk-github-project)

Button Mode ​

md
@[stackblitz button](sdk-github-project)

Container Syntax ​

md
::: stackblitz button

```yml [config]
title: Project
template: javascript
description: Project description
```

```json [package.json]
{
  "name": "project",
  "version": "1.0.0",
  "description": "Project description",
  "main": "index.js",
  "keywords": ["project"],
  "author": "Project Author",
  "license": "MIT"
}
```

```js [index.js]
console.log('Hello StackBlitz!');
```

```html [index.html]
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Project</title>
</head>
<body>
  <h1>Hello StackBlitz!</h1>
  <script src="./index.js"></script>
</body>
</html>
```

:::

Local Project Embed ​

index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>StackBlitz</h1>
  <script src="./index.js"></script>
</body>
</html>
index.js
js
// eslint-disable-next-line no-console
console.log('StackBlitz')
package.json
json
{
  "name": "stackblitz",
  "type": "module",
  "private": true
}
stackblitz.config.json
json
{
  "$schema": "https://unpkg.com/vitepress-plugin-stackblitz/schema.json",
  "title": "Project",
  "description": "Project description",
  "template": "javascript",
  "dependencies": {}
}
md
@[stackblitz local](@/snippets/stack)

Released under the MIT License