npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rspress-plugin-sandpack

v0.0.5

Published

A plugin for rspress to live code with Sandpack.

Downloads

123

Readme

rspress-plugin-sandpack

rspress基于sandpack的在线实时编码环境,目前已实现大部分功能。

1. Install

npm install -D rspress-plugin-sandpack
# or
yarn add -D rspress-plugin-sandpack
# or
pnpm add -D rspress-plugin-sandpack

2. Configuration

// rspress.config.js // or .ts, .mjs ...
import { defineConfig } from 'rspress/config';
import { pluginSandpack } from 'rspress-plugin-sandpack';

export default defineConfig({
  // ...
  plugins: [
    // ... other plugins
    pluginSandpack({
      prefix: 'sp', // 自定义前缀, 不能为空,默认 sandpack
      // consoleView: {
      //   templateNames: true, // 命令行控制台输出一共支持哪些模板
      // },
    }),
  ],
  // ...
});

3. Usage

可自定义添加依赖,如:deps=sass;less@latest;stylus@^0.6.3(不能有空格)


````sp:react-ts deps=sass

// 引入外部文件代码作为源代码,一个路径参数,
// 参数 path 部分是引入源代码路径,支持相对路径、绝对路径以及项目中配置的路径别名
// 参数 search 部分是展示到 Sandpack 的文件名、状态等信息,省略后默认是源代码文件名
// 如下表示:引入`@/CustomComponentCode`文件,展示名为: `CustomName.tsx`, 状态包括:hidden=true
// 支持的状态有:hidden/active/readonly, 均为 boolean 类型
@include('@/CustomComponentCode?name=CustomName.tsx&hidden');

// 声明代码块,必须包含完整文件名,格式如下:
// 直接文件名表示:```App.tsx
// 代码类型+文件名: ```tsx App.tsx
// 代码类型+用name指定: ```tsx name=App.tsx
```App.tsx
import React from 'react';
import './index.scss';

export default function App() {
  
  return (
    <div className="color-red">
      App.tsx
    </div>
  );
}
```

// 代码类型的状态可直接在后面写,如:
// ```scss name=index.scss hidden=true active=true readonly=true
```scss name=index.scss
.color-red {
  color: red;
}
```
````

4. 向Sandpack传递参数

````sp:react-ts deps=sass;less theme=dark options:editorHeight=600

// 没有指定展示文件名时,默认是源代码的文件名,此时需明确包含后缀
// @include 指令里的源文件可以用路径别名、相对路径或绝对路径
@include('@/CustomComponentCode.tsx');

````

5. 引用代码块

若当前页面某代码块通过sp:code(sp 是自定义前缀)声明了文件名:

```js sp:code=format.js
export function format(str) {
  return str.replace(/\B(?=(\d{3})+$)/g, ',');
}
```
````sp:react
// 直接 @include 当前页通过 sp:code 指定的代码块
@include('code:format.js');

````