Skip to content

Commit

Permalink
chore: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
amihhs committed Aug 25, 2023
1 parent 87db5da commit f89dd77
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 20 deletions.
84 changes: 82 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,95 @@
export default {
plugins: [
FilesLoader()
FilesLoader({
paths: './demos',
resolveChildrenBase: 'src',
enableResolveLongChildren: true,
})
],
}
```

3. Usage

```ts
/**
* |-demos
* |-button
* |-src
* |-basic
* |-index.html
*/
import DEMOS from 'virtual:files-loader' // => /demos/..
import BUTTON_DEMOS from 'virtual:files-loader/button' // => /demos/button/src/..
import BUTTON_BASIC_DEMOS from 'virtual:demo-loader/button/basic' // => /demos/button/src/basic/..
```

```json
// virtual:files-loader
{
"__default": [
{
"name": "button",
"children": [
{
"name": "basic",
"children": [
{
"name": "index.html",
"content": "...",
"language": "html"
}
]
}
]
},
{
"name": "index.html",
"content": "...",
"language": "html"
}
]
}
// virtual:files-loader/button
{
"name": "button",
"children": [
{
"name": "basic",
"children": [
{
"name": "index.html",
"content": "...",
"language": "html"
}
]
}
]
}
// virtual:demo-loader/button/basic
{
"name": "basic",
"children": [
{
"name": "index.html",
"content": "...",
"language": "html"
}
]
}
```

## Options

```ts
export interface DemoLoaderPluginOptions {
export interface FilesLoaderPluginOptions {
/**
* Relative paths will be based on root
* @default process.cwd()
Expand Down
9 changes: 2 additions & 7 deletions client.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@

declare module 'virtual:files-loader' {
const demos: Record<string, import('./src/types').DemoItem[]>
declare module 'virtual:files-loader*' {
const demos: Record<string, import('./src/types').FilesLoaderItem[]>

export default demos
}

declare module 'virtual:files-loader/*' {
const demos: Record<string, import('./src/types').DemoItem[]>

export default demos
}
11 changes: 11 additions & 0 deletions playground/demo/button/src/basic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

</body>
</html>
6 changes: 0 additions & 6 deletions playground/demo/index copy.html

This file was deleted.

10 changes: 7 additions & 3 deletions playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import './style.css'
import DEMOS from 'virtual:files-loader'
import DEMOS from 'virtual:files-loader' // => /demos/..
import BUTTON_DEMOS from 'virtual:files-loader/button' // => /demos/button/src/..
import BUTTON_BASIC_DEMOS from 'virtual:files-loader/button/basic' // => /demos/button/src/basic/..

const app = document.getElementById('app')!

const settled = DEMOS
const settled = JSON.stringify(DEMOS, null, 2)
+ '\n' + JSON.stringify(BUTTON_DEMOS, null, 2)
+ '\n' + JSON.stringify(BUTTON_BASIC_DEMOS, null, 2)

app.textContent = JSON.stringify(settled, null, 2)
app.textContent = settled
1 change: 0 additions & 1 deletion playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"strict": true,
"jsx": "preserve",
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node",
Expand Down
4 changes: 3 additions & 1 deletion playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default defineConfig({
},
plugins: [
FilesLoader({
paths: './demo'
paths: './demo',
resolveChildrenBase: 'src',
enableResolveLongChildren: true,
}),
],
build: {
Expand Down

0 comments on commit f89dd77

Please sign in to comment.