File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
packages/create-vue-lib/src/template
playground/config/packages/playground
vitepress/config/packages/docs/.vitepress Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change
1
+ <% _ if (config .includeAtAliases ) { _% >
2
+ import { relative , sep as pathSeparator } from ' node:path'
3
+ < % _ } _%>
1
4
import { fileURLToPath, URL } from 'node:url'
2
5
3
6
import { defineConfig, type UserConfig } from 'vite'
@@ -28,10 +31,14 @@ export default defineConfig(({ mode }): UserConfig => ({
28
31
find: ' @' ,
29
32
replacement: ' @' ,
30
33
customResolver (source , importer , options ) {
31
- const filePath = source .replace (
32
- / ^ @\/ / ,
33
- importer? .startsWith (librarySrc) ? librarySrc : playgroundSrc
34
- )
34
+ let target = playgroundSrc
35
+
36
+ // If the importer is inside librarySrc we resolve @ to that path
37
+ if (importer && relative (importer, librarySrc).split (pathSeparator).every (p => p === ' ..' )) {
38
+ target = librarySrc
39
+ }
40
+
41
+ const filePath = source .replace (/ ^ @\/ / , target)
35
42
36
43
return this .resolve (filePath, importer, options)
37
44
}
Original file line number Diff line number Diff line change
1
+ <% _ if (config .includeAtAliases ) { _% >
2
+ import { relative , sep as pathSeparator } from ' node:path'
3
+ < % _ } _%>
1
4
import { fileURLToPath, URL } from 'node:url'
2
5
3
6
import { defineConfigWithTheme } from 'vitepress'
@@ -50,10 +53,14 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
50
53
find: ' @' ,
51
54
replacement: ' @' ,
52
55
customResolver (source , importer , options ) {
53
- const filePath = source .replace (
54
- / ^ @\/ / ,
55
- importer? .startsWith (librarySrc) ? librarySrc : docsSrc
56
- )
56
+ let target = docsSrc
57
+
58
+ // If the importer is inside librarySrc we resolve @ to that path
59
+ if (importer && relative (importer, librarySrc).split (pathSeparator).every (p => p === ' ..' )) {
60
+ target = librarySrc
61
+ }
62
+
63
+ const filePath = source .replace (/ ^ @\/ / , target)
57
64
58
65
return this .resolve (filePath, importer, options)
59
66
}
You can’t perform that action at this time.
0 commit comments