Skip to content

Commit 844618b

Browse files
committed
docs: update README.md
1 parent 345f5b5 commit 844618b

File tree

1 file changed

+168
-2
lines changed

1 file changed

+168
-2
lines changed

README.md

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Vue SFC To ES Modules
22

3-
> Compile Vue SFC File to ES Modules.
3+
> Transpiled Vue SFC File to ES modules.
44
55
## ✨ Features
66

@@ -11,7 +11,7 @@
1111

1212
## 💡 Inspiration
1313

14-
This project is heavily inspired by [Vue Sfc Playground](https://github.com/vuejs/vue-next/tree/master/packages/sfc-playground)
14+
This project is heavily inspired by [Vue SFC Playground](https://github.com/vuejs/vue-next/tree/master/packages/sfc-playground). Actually Copied from it.
1515

1616

1717
## 📦 Installation
@@ -22,6 +22,164 @@ or
2222
npm i vue-sfc2esm -S
2323
```
2424

25+
## How it Works?
26+
27+
You could imagine that `vue-sfc2esm` has a virtual file system like vue project.
28+
29+
`vue-sfc2esm` will help you transpiled your sfc code base on `Vue 3` into es modules code blocks with [@vue/compiler-sfc](https://www.npmjs.com/package/@vue/compiler-sfc)
30+
31+
You could use these code blocks directly on the modern browser with `type="module"` in the `<script>` element.
32+
33+
### Example
34+
35+
```html
36+
<script type="modules">
37+
// ES Modules Code Blocks Here.
38+
</script>
39+
```
40+
41+
## 📖 Usage
42+
43+
### addFile
44+
45+
> Add a file into the store, ready for compilation.
46+
47+
```js
48+
import { addFile } from 'vue-sfc2esm'
49+
50+
addFile('HelloWorld.vue', `<template>
51+
<h1>{{ msg }}</h1>
52+
</template>
53+
54+
<script setup>
55+
const msg = 'Hello World!'
56+
</script>
57+
`)
58+
```
59+
60+
### changeFile
61+
62+
> Change the file code, It will trigger `compileFile` action.
63+
64+
```js
65+
import { changeFile } from 'vue-sfc2esm'
66+
67+
changeFile('HelloWorld.vue', `<template>
68+
<h1>{{ msg }}</h1>
69+
</template>
70+
71+
<script setup>
72+
const msg = 'Hello Vue SFC2ESM!'
73+
</script>
74+
`)
75+
```
76+
77+
### deleteFile
78+
79+
> Delete the file in the store. with or without confirmation.
80+
81+
```js
82+
import { deleteFile } from 'vue-sfc2esm'
83+
84+
deleteFile('HelloWorld.vue')
85+
```
86+
87+
### CompileModules
88+
89+
> Transpiled Vue SFC File to ES modules with `@vue/compiler-sfc`.
90+
91+
```js
92+
import { compileModules } from 'vue-sfc2esm'
93+
94+
(async function () {
95+
// Compile Default App.vue Component Or Files In Store.
96+
const modules = await compileModules('App.vue')
97+
console.log(`Successfully compiled [App.vue] to ES Modules.`)
98+
console.log(modules)
99+
})()
100+
```
101+
102+
## Typed
103+
104+
```typescript
105+
/**
106+
* Transpiled Vue SFC File to ES modules with `@vue/compiler-sfc`.
107+
*
108+
* @param filename
109+
*/
110+
declare function compileModules(filename: string): Promise<Array<string>>;
111+
112+
/**
113+
* Record the code & errors when a sfc file has been compiled.
114+
*/
115+
interface FileCompiled {
116+
js: string;
117+
css: string;
118+
ssr: string;
119+
errors: Array<string | Error>;
120+
}
121+
/**
122+
* Simple Virtual File System
123+
*/
124+
declare class File {
125+
filename: string;
126+
code: string;
127+
compiled: FileCompiled;
128+
constructor(filename: string, code?: string);
129+
}
130+
/**
131+
* `vue-sfc2esm` built-in store.
132+
*/
133+
interface Store {
134+
files: Record<string, File>;
135+
activeFilename: string;
136+
readonly activeFile: File;
137+
readonly importMap: string | undefined;
138+
errors: Array<string | Error>;
139+
}
140+
declare const store: Store;
141+
/**
142+
* Export the files code.
143+
*
144+
* @returns exported
145+
*/
146+
declare function exportFiles(): Record<string, string>;
147+
/**
148+
* Record File errors when compiling file.
149+
*
150+
* @param errors
151+
*/
152+
declare function recordFileErrors(errors: Array<string | Error>): void;
153+
/**
154+
* Add a file into the store, ready for compilation.
155+
*
156+
* @param filename
157+
* @param code
158+
*/
159+
declare function addFile(filename: string, code: string): void;
160+
/**
161+
* Change the file code, It will trigger `compileFile` action.
162+
*
163+
* @param filename
164+
* @param code
165+
*/
166+
declare function changeFile(filename: string, code: string): void;
167+
/**
168+
* Delete the file in the store. with or without confirmation.
169+
*
170+
* @param filename
171+
* @param withConfirm
172+
*/
173+
declare function deleteFile(filename: string, withConfirm?: boolean): void;
174+
175+
/**
176+
* Compile the `activeFile` in the store. It will change the File.compiled info.
177+
*
178+
* @param File
179+
*/
180+
declare function compileFile({ filename, code, compiled }: File): Promise<void>;
181+
```
182+
25183
## 💻 Development
26184
```
27185
yarn install
@@ -37,6 +195,14 @@ yarn dev
37195
yarn build
38196
```
39197

198+
## Who is using this?
199+
200+
* [vue-sfc-sandbox](https://github.com/xiaoluoboding/vue-sfc-sandbox)
201+
202+
## 📝 Change Log
203+
204+
[Check out CHANGELOG.md](./CHANGELOG.md)
205+
40206
## 📄 License
41207

42208
MIT [@xiaoluoboding](https://github.com/xiaoluoboding)

0 commit comments

Comments
 (0)