Skip to content

Commit b516d12

Browse files
committed
fix: update Vite configuration and TypeScript settings for improved type handling and asset resolution
1 parent 3e1f0cb commit b516d12

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

scripts/rollup.dts.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import dts from 'rollup-plugin-dts'
22

3+
// Bundle the generated declaration entry into a single dist/index.d.ts.
4+
// Treat workspace deps as external so we don't try to resolve them during
5+
// bundling (the consumer will have their own types for those packages).
36
export default [
47
{
8+
// Vite emits declarations under dist/types
59
input: './dist/types/exports.d.ts',
6-
plugins: [dts()],
10+
plugins: [
11+
dts({
12+
// Leave external type imports in place
13+
respectExternal: true,
14+
}),
15+
],
16+
external: [
17+
/^(?:stream-markdown-parser)(?:\/.*)?$/,
18+
],
719
output: [
820
{
921
file: 'dist/index.d.ts',

src/shims-vue.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@ declare module '*.vue' {
33
const component: ReturnType<typeof defineComponent>
44
export default component
55
}
6+
7+
// Vite asset imports used in this project
8+
declare module '*.svg?raw' {
9+
const src: string
10+
export default src
11+
}
12+
13+
declare module '*.svg?url' {
14+
const src: string
15+
export default src
16+
}

tsconfig.build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"lib": ["DOM", "ESNext"],
66
"module": "ESNext",
77
"moduleResolution": "node",
8+
"types": ["vite/client"],
89
"resolveJsonModule": true,
910
"declaration": true,
1011
"emitDeclarationOnly": true,

vite.config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default defineConfig(({ mode }) => {
2626
Vue(),
2727
dts({
2828
outDir: 'dist/types',
29+
// Use a build-only tsconfig without path aliases to avoid rewriting
30+
// imports like "stream-markdown-parser" into relative workspace paths
31+
// in the emitted .d.ts (which breaks type bundling).
32+
tsconfigPath: './tsconfig.build.json',
2933
}),
3034
UnpluginClassExtractor({
3135
output: 'dist/tailwind.ts',
@@ -111,6 +115,15 @@ export default defineConfig(({ mode }) => {
111115
}
112116
}
113117

118+
// Alias resolution: during dev/test, point workspace dep to source to avoid needing its dist build
119+
const alias: Record<string, string> = {
120+
'@': '/src',
121+
}
122+
if (mode !== 'npm') {
123+
alias['stream-markdown-parser'] = '/packages/markdown-parser/src/index.ts'
124+
alias['stream-markdown-parser/*'] = '/packages/markdown-parser/src/*'
125+
}
126+
114127
return {
115128
base,
116129
plugins,
@@ -137,10 +150,6 @@ export default defineConfig(({ mode }) => {
137150
css: {
138151
postcss: './postcss.config.cjs',
139152
},
140-
resolve: {
141-
alias: {
142-
'@': '/src',
143-
},
144-
},
153+
resolve: { alias },
145154
}
146155
})

0 commit comments

Comments
 (0)