Skip to content

Commit ffe58e1

Browse files
Fix a 'Pre-transform error' using aliases with Vite (#8)
1 parent f729e66 commit ffe58e1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ export default defineConfig(({ mode }): UserConfig => ({
2121
{
2222
find: '@',
2323
replacement: '@',
24-
customResolver(source, importer) {
25-
return source.replace(
24+
customResolver(source, importer, options) {
25+
const filePath = source.replace(
2626
/^@\//,
2727
importer?.startsWith(librarySrc) ? librarySrc : playgroundSrc
2828
)
29+
30+
return this.resolve(filePath, importer, options)
2931
}
3032
}, {
3133
find: '<%- config.scopedPackageName %>',

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfigWithTheme } from 'vitepress'
44

55
<%_ if (config.includeAtAliases) { _%>
66
const librarySrc = fileURLToPath(new URL('../../<%- config.mainPackageDirName %>/src/', import.meta.url))
7-
const playgroundSrc = fileURLToPath(new URL('../src/', import.meta.url))
7+
const docsSrc = fileURLToPath(new URL('../src/', import.meta.url))
88
<%_ } _%>
99
1010
export default ({ mode }: { mode: string }) => defineConfigWithTheme({
@@ -40,11 +40,13 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
4040
{
4141
find: '@',
4242
replacement: '@',
43-
customResolver(source, importer) {
44-
return source.replace(
43+
customResolver(source, importer, options) {
44+
const filePath = source.replace(
4545
/^@\//,
46-
importer?.startsWith(librarySrc) ? librarySrc : playgroundSrc
46+
importer?.startsWith(librarySrc) ? librarySrc : docsSrc
4747
)
48+
49+
return this.resolve(filePath, importer, options)
4850
}
4951
}, {
5052
find: '<%- config.scopedPackageName %>',

0 commit comments

Comments
 (0)