Skip to content

Commit af0c14f

Browse files
committed
Fix @ aliases on Windows
1 parent 51b4d4b commit af0c14f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

packages/create-vue-lib/src/template/playground/config/packages/playground/vite.config.mts.ejs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<%_ if (config.includeAtAliases) { _%>
2+
import { relative, sep as pathSeparator } from 'node:path'
3+
<%_ } _%>
14
import { fileURLToPath, URL } from 'node:url'
25

36
import { defineConfig, type UserConfig } from 'vite'
@@ -28,10 +31,14 @@ export default defineConfig(({ mode }): UserConfig => ({
2831
find: '@',
2932
replacement: '@',
3033
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)
3542
3643
return this.resolve(filePath, importer, options)
3744
}

packages/create-vue-lib/src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<%_ if (config.includeAtAliases) { _%>
2+
import { relative, sep as pathSeparator } from 'node:path'
3+
<%_ } _%>
14
import { fileURLToPath, URL } from 'node:url'
25

36
import { defineConfigWithTheme } from 'vitepress'
@@ -50,10 +53,14 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
5053
find: '@',
5154
replacement: '@',
5255
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)
5764
5865
return this.resolve(filePath, importer, options)
5966
}

0 commit comments

Comments
 (0)