Skip to content

Commit 2779dcc

Browse files
chore(docs): v0.3.0 API docs & examples
1 parent f3c303d commit 2779dcc

File tree

6 files changed

+145
-61
lines changed

6 files changed

+145
-61
lines changed

docs/api/README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [Module](interfaces/module.md)
1313
* [ModuleHandler](interfaces/modulehandler.md)
1414
* [Options](interfaces/options.md)
15+
* [PathHandlers](interfaces/pathhandlers.md)
1516

1617
### Type aliases
1718

@@ -25,13 +26,17 @@
2526

2627
* [loadModule](README.md#loadmodule)
2728

29+
### Object literals
30+
31+
* [defaultPathHandlers](README.md#defaultpathhandlers)
32+
2833
## Type aliases
2934

3035
### File
3136

3237
Ƭ **File**: string \| { content: string ; extname: string }
3338

34-
*Defined in [index.ts:75](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L75)*
39+
*Defined in [index.ts:84](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L84)*
3540

3641
Represents the content of the file or the content and the extension name.
3742

@@ -41,28 +46,30 @@ Represents the content of the file or the content and the extension name.
4146

4247
`Const` **version**: string = process.env.VERSION
4348

44-
*Defined in [index.ts:327](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L327)*
49+
*Defined in [index.ts:343](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L343)*
4550

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

4853
## Functions
4954

5055
### loadModule
5156

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

54-
*Defined in [index.ts:796](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L796)*
59+
*Defined in [index.ts:819](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L819)*
5560

5661
This is the main function.
62+
This function is intended to be used only to load the entry point of your application.
63+
If for some reason you need to use it in your components, be sure to share at least the options.`compiledCache` object between all calls.
5764

5865
#### Parameters:
5966

6067
Name | Type | Default value | Description |
6168
------ | ------ | ------ | ------ |
6269
`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. |
63-
`options` | [Options](interfaces/options.md) | throwNotDefined('options') | The options |
70+
`options_` | [Options](interfaces/options.md) | throwNotDefined('options') | - |
6471

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

6774
A Promise of the component
6875

@@ -96,3 +103,20 @@ A Promise of the component
96103
.catch(ex => console.error(ex));
97104

98105
```
106+
107+
## Object literals
108+
109+
### defaultPathHandlers
110+
111+
`Const` **defaultPathHandlers**: object
112+
113+
*Defined in [index.ts:766](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L766)*
114+
115+
Default implementation of PathHandlers
116+
117+
#### Properties:
118+
119+
Name | Type | Value |
120+
------ | ------ | ------ |
121+
`extname` | function | (filepath: string) => string |
122+
`resolve` | function | (absoluteFilepath: string, dependencyPath: string) => string |

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/f07a644/src/index.ts#L67)*
24+
*Defined in [index.ts:67](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/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/f07a644/src/index.ts#L68)*
40+
*Defined in [index.ts:68](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/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:310](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L310)*
18+
*Defined in [index.ts:326](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L326)*
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: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [compiledCache](options.md#compiledcache)
1818
* [delimiters](options.md#delimiters)
1919
* [moduleCache](options.md#modulecache)
20+
* [pathHandlers](options.md#pathhandlers)
2021

2122
### Methods
2223

@@ -31,7 +32,7 @@
3132

3233
`Optional` **additionalBabelPlugins**: any[]
3334

34-
*Defined in [index.ts:193](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L193)*
35+
*Defined in [index.ts:202](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L202)*
3536

3637
Additional babel plugins. [TBD]
3738

@@ -46,7 +47,7 @@ ___
4647

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

49-
*Defined in [index.ts:200](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L200)*
50+
*Defined in [index.ts:209](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L209)*
5051

5152
Additional module type handlers. see [ModuleHandler](modulehandler.md)
5253

@@ -56,7 +57,7 @@ ___
5657

5758
`Optional` **compiledCache**: [Cache](cache.md)
5859

59-
*Defined in [index.ts:240](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L240)*
60+
*Defined in [index.ts:249](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L249)*
6061

6162
[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`).
6263
Since compilation consume a lot of CPU, is is always a good idea to provide this object.
@@ -100,42 +101,42 @@ ___
100101

101102
`Optional` **delimiters**: SFCTemplateCompileOptions[\"compilerOptions\"][\"delimiters\"]
102103

103-
*Defined in [index.ts:182](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L182)*
104+
*Defined in [index.ts:191](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L191)*
104105

105106
Sets the delimiters used for text interpolation within the template.
106107
Typically this is used to avoid conflicting with server-side frameworks that also use mustache syntax.
107108

108109
```javascript
109-
...
110-
<script>
111-
112-
// <!--
113-
const vueContent = `
114-
<template> Hello [[[[ who ]]]] !</template>
115-
<script>
116-
export default {
117-
data() {
118-
return {
119-
who: 'world'
110+
...
111+
<script>
112+
113+
// <!--
114+
const vueContent = `
115+
<template> Hello [[[[ who ]]]] !</template>
116+
<script>
117+
export default {
118+
data() {
119+
return {
120+
who: 'world'
121+
}
120122
}
121123
}
124+
</script>
125+
`;
126+
// -->
127+
128+
const options = {
129+
moduleCache: { vue: Vue },
130+
getFile: () => vueContent,
131+
addStyle: () => {},
132+
delimiters: ['[[[[', ']]]]'],
122133
}
123-
</script>
124-
`;
125-
// -->
126-
127-
const options = {
128-
moduleCache: { vue: Vue },
129-
getFile: () => vueContent,
130-
addStyle: () => {},
131-
delimiters: ['[[[[', ']]]]'],
132-
}
133134

134-
const app = Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('file.vue', options)));
135-
app.mount(document.body);
135+
const app = Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('file.vue', options)));
136+
app.mount(document.body);
136137

137-
</script>
138-
...
138+
</script>
139+
...
139140
```
140141

141142
___
@@ -144,11 +145,11 @@ ___
144145

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

147-
*Defined in [index.ts:99](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L99)*
148+
*Defined in [index.ts:108](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L108)*
148149

149150
Initial cache that will contain resolved dependencies. All new modules go here.
150151
`vue` must initially be contained in this object.
151-
[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.
152+
[moduleCache](options.md#modulecache) is mandatory for the lib. If you do not provide it, the library will create one.
152153
It is recommended to provide a prototype-less object (`Object.create(null)`) to avoid potential conflict with `Object` properties (constructor, __proto__, hasOwnProperty, ...).
153154
​ *
154155
See also [[options.loadModule]].
@@ -162,13 +163,23 @@ See also [[options.loadModule]].
162163
...
163164
```
164165

166+
___
167+
168+
### pathHandlers
169+
170+
**pathHandlers**: [PathHandlers](pathhandlers.md)
171+
172+
*Defined in [index.ts:295](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L295)*
173+
174+
Abstact path handling
175+
165176
## Methods
166177

167178
### addStyle
168179

169180
**addStyle**(`style`: string, `scopeId`: string): void
170181

171-
*Defined in [index.ts:142](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L142)*
182+
*Defined in [index.ts:151](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L151)*
172183

173184
Called by the library when CSS style must be added in the HTML document.
174185

@@ -200,7 +211,7 @@ ___
200211

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

203-
*Defined in [index.ts:120](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L120)*
214+
*Defined in [index.ts:129](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L129)*
204215

205216
Called by the library when it needs a file.
206217

@@ -233,7 +244,7 @@ ___
233244

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

236-
*Defined in [index.ts:279](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L279)*
247+
*Defined in [index.ts:288](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L288)*
237248

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

@@ -266,7 +277,7 @@ ___
266277

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

269-
*Defined in [index.ts:258](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f07a644/src/index.ts#L258)*
280+
*Defined in [index.ts:267](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L267)*
270281

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

docs/api/interfaces/pathhandlers.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
**[vue3-sfc-loader](../README.md)**
2+
3+
> [Globals](../README.md) / PathHandlers
4+
5+
# Interface: PathHandlers
6+
7+
## Hierarchy
8+
9+
* **PathHandlers**
10+
11+
## Index
12+
13+
### Methods
14+
15+
* [extname](pathhandlers.md#extname)
16+
* [resolve](pathhandlers.md#resolve)
17+
18+
## Methods
19+
20+
### extname
21+
22+
**extname**(`filepath`: string): string
23+
24+
*Defined in [index.ts:73](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L73)*
25+
26+
#### Parameters:
27+
28+
Name | Type |
29+
------ | ------ |
30+
`filepath` | string |
31+
32+
**Returns:** string
33+
34+
___
35+
36+
### resolve
37+
38+
**resolve**(`absoluteFilepath`: string, `dependencyPath`: string): string
39+
40+
*Defined in [index.ts:77](https://github.com/FranckFreiburger/vue3-sfc-loader/blob/f3c303d/src/index.ts#L77)*
41+
42+
#### Parameters:
43+
44+
Name | Type |
45+
------ | ------ |
46+
`absoluteFilepath` | string |
47+
`dependencyPath` | string |
48+
49+
**Returns:** string

0 commit comments

Comments
 (0)