veslx 0.1.1 → 0.1.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/bin/lib/build.ts +2 -0
- package/bin/lib/serve.ts +2 -0
- package/package.json +1 -1
- package/plugin/src/plugin.ts +1 -1
- package/src/hooks/use-mdx-content.ts +26 -25
package/bin/lib/build.ts
CHANGED
|
@@ -52,6 +52,8 @@ export default async function buildApp() {
|
|
|
52
52
|
root: veslxRoot,
|
|
53
53
|
configFile,
|
|
54
54
|
mode: 'production',
|
|
55
|
+
// Cache in user's project so it persists across bunx runs
|
|
56
|
+
cacheDir: path.join(cwd, 'node_modules/.vite'),
|
|
55
57
|
build: {
|
|
56
58
|
outDir: tempOutDir,
|
|
57
59
|
emptyOutDir: true,
|
package/bin/lib/serve.ts
CHANGED
|
@@ -26,6 +26,8 @@ export default async function start() {
|
|
|
26
26
|
const server = await createServer({
|
|
27
27
|
root: veslxRoot,
|
|
28
28
|
configFile,
|
|
29
|
+
// Cache in user's project so it persists across bunx runs
|
|
30
|
+
cacheDir: path.join(cwd, 'node_modules/.vite'),
|
|
29
31
|
plugins: [
|
|
30
32
|
veslxPlugin(contentDir)
|
|
31
33
|
],
|
package/package.json
CHANGED
package/plugin/src/plugin.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react'
|
|
2
|
-
import { modules, slides } from 'virtual:content-modules'
|
|
3
2
|
import type { ComponentType } from 'react'
|
|
4
3
|
|
|
5
4
|
interface MDXModule {
|
|
@@ -13,6 +12,7 @@ interface MDXModule {
|
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
type ModuleLoader = () => Promise<MDXModule>
|
|
15
|
+
type ModuleMap = Record<string, ModuleLoader>
|
|
16
16
|
|
|
17
17
|
export function useMDXContent(path: string) {
|
|
18
18
|
const [Content, setContent] = useState<MDXModule['default'] | null>(null)
|
|
@@ -25,20 +25,20 @@ export function useMDXContent(path: string) {
|
|
|
25
25
|
setLoading(true)
|
|
26
26
|
setError(null)
|
|
27
27
|
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
28
|
+
// Dynamic import to avoid pre-bundling issues
|
|
29
|
+
import('virtual:content-modules')
|
|
30
|
+
.then(({ modules }) => {
|
|
31
|
+
const matchingKey = Object.keys(modules).find(key =>
|
|
32
|
+
key.endsWith(`/${path}/README.mdx`)
|
|
33
|
+
)
|
|
34
|
+
const loader = matchingKey ? (modules as ModuleMap)[matchingKey] : null
|
|
35
|
+
|
|
36
|
+
if (!loader) {
|
|
37
|
+
throw new Error(`MDX module not found for path: ${path}`)
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
return loader()
|
|
41
|
+
})
|
|
42
42
|
.then((mod) => {
|
|
43
43
|
if (!cancelled) {
|
|
44
44
|
setContent(() => mod.default)
|
|
@@ -72,19 +72,20 @@ export function useMDXSlides(path: string) {
|
|
|
72
72
|
setLoading(true)
|
|
73
73
|
setError(null)
|
|
74
74
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
// Dynamic import to avoid pre-bundling issues
|
|
76
|
+
import('virtual:content-modules')
|
|
77
|
+
.then(({ slides }) => {
|
|
78
|
+
const matchingKey = Object.keys(slides).find(key =>
|
|
79
|
+
key.endsWith(`/${path}/SLIDES.mdx`)
|
|
80
|
+
)
|
|
81
|
+
const loader = matchingKey ? (slides as ModuleMap)[matchingKey] : null
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
85
|
-
}
|
|
83
|
+
if (!loader) {
|
|
84
|
+
throw new Error(`Slides module not found for path: ${path}`)
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
return loader()
|
|
88
|
+
})
|
|
88
89
|
.then((mod) => {
|
|
89
90
|
if (!cancelled) {
|
|
90
91
|
setContent(() => mod.default)
|