Skip to content

Commit ebfd411

Browse files
chore(docs): v0.2.20 API docs & examples
1 parent c0792ec commit ebfd411

File tree

5 files changed

+46
-37
lines changed

5 files changed

+46
-37
lines changed

docs/api/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
Ƭ **File**: string \| { content: string ; extname: string }
3333

34-
*Defined in [index.ts:75](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L75)*
34+
*Defined in [index.ts:75](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L75)*
3535

3636
Represents the content of the file or the content and the extension name.
3737

@@ -41,17 +41,17 @@ Represents the content of the file or the content and the extension name.
4141

4242
`Const` **version**: string = process.env.VERSION
4343

44-
*Defined in [index.ts:278](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L278)*
44+
*Defined in [index.ts:287](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L287)*
4545

4646
the version of the library (process.env.VERSION is set by webpack, at compile-time)
4747

4848
## Functions
4949

5050
### loadModule
5151

52-
**loadModule**(`path`: string, `options?`: [Options](interfaces/options.md)): Promise<[Module](interfaces/module.md)\>
52+
**loadModule**(`path`: string, `options?`: [Options](interfaces/options.md)): Promise<any\>
5353

54-
*Defined in [index.ts:750](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L750)*
54+
*Defined in [index.ts:759](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L759)*
5555

5656
This is the main function.
5757

@@ -62,7 +62,7 @@ Name | Type | Default value | Description |
6262
`path` | string | - | The path of the `.vue` file. If path is not a path (eg. an string ID), your [getFile](interfaces/options.md#getfile) function must return a [File](README.md#file) object. |
6363
`options` | [Options](interfaces/options.md) | throwNotDefined('options') | The options |
6464

65-
**Returns:** Promise<[Module](interfaces/module.md)\>
65+
**Returns:** Promise<any\>
6666

6767
A Promise of the component
6868

docs/api/interfaces/cache.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
**get**(`key`: string): Promise<string\>
2323

24-
*Defined in [index.ts:67](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L67)*
24+
*Defined in [index.ts:67](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L67)*
2525

2626
#### Parameters:
2727

@@ -37,7 +37,7 @@ ___
3737

3838
**set**(`key`: string, `value`: string): Promise<void\>
3939

40-
*Defined in [index.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L68)*
40+
*Defined in [index.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L68)*
4141

4242
#### Parameters:
4343

docs/api/interfaces/modulehandler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ see [additionalModuleHandlers](options.md#additionalmodulehandlers)
1515

1616
▸ (`source`: string, `path`: string, `options`: [Options](options.md)): Promise<[Module](module.md)\>
1717

18-
*Defined in [index.ts:261](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L261)*
18+
*Defined in [index.ts:270](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L270)*
1919

2020
Used by the library when it does not know how to handle a given file type (eg. `.json` files).
2121
see [additionalModuleHandlers](options.md#additionalmodulehandlers)

docs/api/interfaces/options.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
`Optional` **additionalBabelPlugins**: any[]
3232

33-
*Defined in [index.ts:146](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L146)*
33+
*Defined in [index.ts:153](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L153)*
3434

3535
Additional babel plugins. [TBD]
3636

@@ -45,7 +45,7 @@ ___
4545

4646
`Optional` **additionalModuleHandlers**: Record<string, [ModuleHandler](modulehandler.md)\>
4747

48-
*Defined in [index.ts:153](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L153)*
48+
*Defined in [index.ts:160](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L160)*
4949

5050
Additional module type handlers. see [ModuleHandler](modulehandler.md)
5151

@@ -55,7 +55,7 @@ ___
5555

5656
`Optional` **compiledCache**: [Cache](cache.md)
5757

58-
*Defined in [index.ts:193](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L193)*
58+
*Defined in [index.ts:200](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L200)*
5959

6060
[get](cache.md#get)() and [set](cache.md#set)() functions of this object are called when the lib needs to save or load already compiled code. get and set functions must return a `Promise` (or can be `async`).
6161
Since compilation consume a lot of CPU, is is always a good idea to provide this object.
@@ -99,17 +99,21 @@ ___
9999

100100
`Optional` **moduleCache**: Record<string, [Module](module.md)\>
101101

102-
*Defined in [index.ts:95](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L95)*
102+
*Defined in [index.ts:99](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L99)*
103103

104104
Initial cache that will contain resolved dependencies. All new modules go here.
105105
`vue` must initially be contained in this object.
106+
[moduleCache](options.md#modulecache) is mandatory for the lib but optional for you. If you do not provide it, the lib will automatically add it to the [[options]] object.
107+
It is recommended to provide a prototype-less object (`Object.create(null)`) to avoid potential conflict with `Object` properties (constructor, __proto__, hasOwnProperty, ...).
108+
​ *
109+
See also [[options.loadModule]].
106110

107111
**example:**
108112
```javascript
109113
...
110-
moduleCache: {
114+
moduleCache: Object.assign(Object.create(null), {
111115
vue: Vue,
112-
},
116+
}),
113117
...
114118
```
115119

@@ -119,7 +123,7 @@ Initial cache that will contain resolved dependencies. All new modules go here.
119123

120124
**addStyle**(`style`: string, `scopeId`: string): void
121125

122-
*Defined in [index.ts:135](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L135)*
126+
*Defined in [index.ts:142](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L142)*
123127

124128
Called by the library when CSS style must be added in the HTML document.
125129

@@ -151,7 +155,7 @@ ___
151155

152156
**getFile**(`path`: string): Promise<[File](../README.md#file)\>
153157

154-
*Defined in [index.ts:113](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L113)*
158+
*Defined in [index.ts:120](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L120)*
155159

156160
Called by the library when it needs a file.
157161

@@ -168,9 +172,12 @@ a Promise of the file content (UTF-8)
168172
**example:**
169173
```javascript
170174
...
171-
getFile(url) {
175+
async getFile(url) {
172176

173-
return fetch(url).then(response => response.ok ? response.text() : Promise.reject(response));
177+
const res = await fetch(url);
178+
if ( !res.ok )
179+
throw Object.assign(new Error(url+' '+res.statusText), { res });
180+
return await res.text();
174181
},
175182
...
176183
```
@@ -181,7 +188,7 @@ ___
181188

182189
`Optional`**loadModule**(`path`: string, `options`: [Options](options.md)): Promise<[Module](module.md) \| undefined\>
183190

184-
*Defined in [index.ts:230](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L230)*
191+
*Defined in [index.ts:239](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L239)*
185192

186193
Called when the lib requires a module. Do return `undefined` to let the library handle this.
187194

@@ -196,6 +203,8 @@ Name | Type | Description |
196203

197204
A Promise of the module or undefined
198205

206+
[moduleCache](options.md#modulecache) and [Options.loadModule](options.md#loadmodule) are strongly related, in the sense that the result of [[options.loadModule]] is stored in [moduleCache](options.md#modulecache).
207+
However, [[options.loadModule]] is asynchronous and may help you to handle modules or components that are conditionally required (optional features, current languages, plugins, ...).
199208
```javascript
200209
...
201210
loadModule(path, options) {
@@ -212,7 +221,7 @@ ___
212221

213222
`Optional`**log**(`type`: string, ...`data`: any[]): void
214223

215-
*Defined in [index.ts:211](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/547328e/src/index.ts#L211)*
224+
*Defined in [index.ts:218](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/c0792ec/src/index.ts#L218)*
216225

217226
Called by the library when there is somthing to log (eg. scripts compilation errors, template compilation errors, template compilation tips, style compilation errors, ...)
218227

0 commit comments

Comments
 (0)