vitepress-plugin-sfc 2.0.0-beta.1 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,156 +1,66 @@
1
- # Vitepress Plugin Component
1
+ # VitePress Plugin SFC
2
2
 
3
- [简体中文](README-zh-CN.md)
3
+ [Documentation](https://vitepress-plugin-sfc-playgrou.vercel.app/) | [中文](README-zh-CN.md)
4
4
 
5
- A VitePress plugin to display Vue components in your documentation with an automatically generated two-tab interface: one for the component's preview and another to show its source code.
5
+ Allows you to write Vue SFC within Markdown files and render them in VitePress.
6
6
 
7
- ## Features
7
+ ## Install
8
8
 
9
- - [x] **Component Preview** - Directly view the rendered output of your component within the documentation.
10
- - [x] **Syntax Highlighting** - Compatible with VitePress's syntax highlighting.
11
- - [x] **Code Copying** - One-click copy for the component's source code.
12
- - [x] **Dark Mode Support** - Automatically adapts to VitePress's light and dark themes.
13
- - [x] **Lightweight** - No complex dependencies, only `2kb` / gzip:`1kb`.
14
- - [x] **Internationalization Support** - Default support for Chinese and English, configurable for other languages.
15
-
16
- ## Installation
17
-
18
- ```bash
19
- npm install vitepress-plugin-sfc --save-dev
9
+ ```shell
10
+ npm install -D vitepress-plugin-sfc@latest
20
11
  ```
21
12
 
22
13
  ## Configuration
23
14
 
24
- ### Add Markdown Plugin
15
+ Configure it in `.vitepress/config.ts` and `.vitepress/theme/index.ts`:
25
16
 
26
- Add the plugin to your VitePress configuration file (`.vitepress/config.js` or `.vitepress/config.ts`):
17
+ `.vitepress/config.ts`
27
18
 
28
19
  ```ts
29
- import { defineConfig } from 'vitepress'
30
- import { componentViewMarkdownPlugin } from 'vitepress-plugin-sfc'
20
+ import { defineConfig } from "vitepress";
21
+ import { sfcPlugin, sfcRegistryVitePlugin } from "vitepress-plugin-sfc";
31
22
 
32
23
  export default defineConfig({
33
- // ... other configurations
34
-
35
24
  markdown: {
36
25
  config: (md) => {
37
- md.use(componentViewMarkdownPlugin)
38
- }
26
+ md.use(sfcPlugin);
27
+ },
39
28
  },
40
- })
29
+ vite: {
30
+ plugins: [sfcRegistryVitePlugin()],
31
+ },
32
+ });
41
33
  ```
42
34
 
43
- ### Configure Client
44
-
45
- VitePress resolves themes from `.vitepress/theme/index.js` or `.vitepress/theme/index.ts`, and we configure the client here as well.
35
+ `.vitepress/theme/index.ts`
46
36
 
47
37
  ```ts
48
- // theme/index.ts
49
38
  import DefaultTheme from "vitepress/theme";
50
- import { enhanceAppWithComponentView } from 'vitepress-plugin-sfc/client'
39
+ import { enhanceAppWithComponentView } from "vitepress-plugin-sfc/client";
51
40
 
52
41
  export default {
53
- extends: DefaultTheme, // Use VitePress's default theme
42
+ extends: DefaultTheme,
54
43
  enhanceApp({ app }) {
55
- enhanceAppWithComponentView(app)
56
- }
57
- }
58
- ```
59
-
60
- The `enhanceAppWithComponentView` function automatically registers the preview component on the passed root component.
61
-
62
- ### Configure Internationalization
63
-
64
- The plugin gets language configuration from the `locales.lang` option in VitePress and supports `zh` and `en` languages by default. You can also manually configure other languages or even override the default languages.
65
-
66
- Configure internationalization in the client configuration:
67
-
68
- ```ts
69
- export default {
70
- // Other configurations
71
- enhanceApp({ app }) {
72
- enhanceAppWithComponentView(app, {
73
- // Configure corresponding languages through localeMappings option
74
- localeMappings: {
75
- fr: {
76
- previewLabel: "foo",
77
- codeLabel: "bar",
78
- },
79
- },
80
- });
44
+ enhanceAppWithComponentView(app);
81
45
  },
82
46
  };
83
47
  ```
84
48
 
85
- ## Example
86
-
87
- This is an example of button SFC:
88
-
89
- ```vue
90
- <script setup lang="ts">
91
- import { ref } from 'vue';
49
+ ## Usage
92
50
 
93
- const count = ref(0)
94
- </script>
95
-
96
- <template>
97
- <button class="my-button" @click="count++">
98
- Clicked {{ count }} times
99
- </button>
100
- </template>
101
-
102
- <style>
103
- .my-button {
104
- background-color: #3eaf7c;
105
- color: white;
106
- border: none;
107
- padding: 8px 16px;
108
- border-radius: 4px;
109
- cursor: pointer;
110
- }
111
- </style>
112
- ```
113
-
114
- VitePress supports [importing Vue components in markdown files](https://vitepress.dev/guide/using-vue#using-components), we import the Button component in the same way:
115
-
116
- ```bash
117
- <script setup>
118
- import Button from './Button.vue'
119
- </script>
120
- ```
121
-
122
- Then use the specified syntax:
123
-
124
- ```markdown
125
- ::: component-view
126
- <Button />
127
- :::
128
- ```
129
-
130
- Here is the complete example code in a markdown file:
51
+ Wrap **valid** Vue SFC content with `:::sfc`:
131
52
 
132
53
  ```markdown
54
+ :::sfc
133
55
  <script setup>
134
- import Button from './Button.vue'
56
+ import { ref } from "vue"
57
+ const msg = ref("");
135
58
  </script>
136
59
 
137
- # This will render a button with click count and a tab bar showing **Preview** and **Source Code**
138
-
139
- ::: component-view
140
- <Button />
60
+ <template>
61
+ <input v-model="msg" placeholder="Please enter text" />
62
+ </template>
141
63
  :::
142
-
143
- ##
144
64
  ```
145
65
 
146
- You can view the component's preview and source code in the tabs above.
147
-
148
- You can check out the [live demo here](https://vitepress-plugin-sfc-playgrou.vercel.app/).
149
-
150
- ## Notes
151
-
152
- - Component paths should be relative to the project root.
153
- - Current version supports simple Vue components; complex components might require additional configuration. - Components must be valid Single File Components (SFCs).
154
- ## License
155
-
156
66
  [MIT](LICENSE)