veslx 0.1.16 → 0.1.18
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/package.json +1 -1
- package/vite.config.ts +47 -11
package/package.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
1
|
+
import { defineConfig, Plugin } from 'vite'
|
|
2
2
|
import react from '@vitejs/plugin-react'
|
|
3
3
|
import tailwindcss from '@tailwindcss/vite'
|
|
4
4
|
import mdx from '@mdx-js/rollup'
|
|
@@ -9,10 +9,48 @@ import remarkGfm from 'remark-gfm'
|
|
|
9
9
|
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
|
|
10
10
|
import { remarkSlides } from './plugin/src/remark-slides'
|
|
11
11
|
import { fileURLToPath } from 'url'
|
|
12
|
+
import { createRequire } from 'module'
|
|
12
13
|
import path from 'path'
|
|
13
14
|
import fs from 'fs'
|
|
14
15
|
|
|
15
16
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
17
|
+
const require = createRequire(import.meta.url)
|
|
18
|
+
|
|
19
|
+
// Resolve React packages from veslx's node_modules for MDX files in user content
|
|
20
|
+
// This is needed when veslx runs via bunx from a temp directory
|
|
21
|
+
function reactResolverPlugin(): Plugin {
|
|
22
|
+
const reactPackages = [
|
|
23
|
+
'react',
|
|
24
|
+
'react/jsx-runtime',
|
|
25
|
+
'react/jsx-dev-runtime',
|
|
26
|
+
'react-dom',
|
|
27
|
+
'react-dom/client',
|
|
28
|
+
'@mdx-js/react',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
const resolved = new Map<string, string>()
|
|
32
|
+
for (const pkg of reactPackages) {
|
|
33
|
+
try {
|
|
34
|
+
resolved.set(pkg, require.resolve(pkg))
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
name: 'veslx-react-resolver',
|
|
40
|
+
// Only resolve for user content MDX files (outside veslx's own src)
|
|
41
|
+
async resolveId(id, importer, options) {
|
|
42
|
+
if (!resolved.has(id)) return null
|
|
43
|
+
// Only intercept if importer is outside veslx (user content)
|
|
44
|
+
if (!importer || importer.includes('/veslx/') || importer.includes('node_modules')) {
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
// Let Vite try first, only fallback to our resolution
|
|
48
|
+
const resolution = await this.resolve(id, importer, { ...options, skipSelf: true })
|
|
49
|
+
if (resolution) return null
|
|
50
|
+
return resolved.get(id)
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
16
54
|
|
|
17
55
|
const distClientPath = path.join(__dirname, 'dist/client')
|
|
18
56
|
const srcPath = path.join(__dirname, 'src')
|
|
@@ -38,6 +76,8 @@ export default defineConfig(({ command }) => {
|
|
|
38
76
|
cacheDir: path.join(__dirname, 'node_modules/.vite'),
|
|
39
77
|
publicDir: path.join(__dirname, 'public'),
|
|
40
78
|
plugins: [
|
|
79
|
+
// Resolve React from veslx's dependencies for user MDX content (handles bunx installs)
|
|
80
|
+
reactResolverPlugin(),
|
|
41
81
|
tailwindcss(),
|
|
42
82
|
// MDX for slides - splits at --- into <Slide> components
|
|
43
83
|
{
|
|
@@ -67,13 +107,13 @@ export default defineConfig(({ command }) => {
|
|
|
67
107
|
resolve: {
|
|
68
108
|
alias: {
|
|
69
109
|
'@': clientPath,
|
|
70
|
-
// Ensure React resolves from veslx's node_modules for MDX files in user content
|
|
71
|
-
'react': path.join(__dirname, 'node_modules/react'),
|
|
72
|
-
'react-dom': path.join(__dirname, 'node_modules/react-dom'),
|
|
73
|
-
'react/jsx-runtime': path.join(__dirname, 'node_modules/react/jsx-runtime'),
|
|
74
|
-
'react/jsx-dev-runtime': path.join(__dirname, 'node_modules/react/jsx-dev-runtime'),
|
|
75
|
-
'@mdx-js/react': path.join(__dirname, 'node_modules/@mdx-js/react'),
|
|
76
110
|
},
|
|
111
|
+
// Ensure single copies of React packages are used
|
|
112
|
+
dedupe: ['react', 'react-dom', '@mdx-js/react'],
|
|
113
|
+
},
|
|
114
|
+
build: {
|
|
115
|
+
chunkSizeWarningLimit: 1500,
|
|
116
|
+
reportCompressedSize: false,
|
|
77
117
|
},
|
|
78
118
|
server: {
|
|
79
119
|
host: '0.0.0.0',
|
|
@@ -90,10 +130,6 @@ export default defineConfig(({ command }) => {
|
|
|
90
130
|
strictPort: true,
|
|
91
131
|
allowedHosts: true,
|
|
92
132
|
},
|
|
93
|
-
build: {
|
|
94
|
-
chunkSizeWarningLimit: 1500,
|
|
95
|
-
reportCompressedSize: false,
|
|
96
|
-
},
|
|
97
133
|
optimizeDeps: {
|
|
98
134
|
entries: [path.join(clientPath, usePrebuilt ? 'main.js' : 'main.tsx')],
|
|
99
135
|
include: [
|