Skip to content

Fix a 'Pre-transform error' using aliases with Vite #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export default defineConfig(({ mode }): UserConfig => ({
{
find: '@',
replacement: '@',
customResolver(source, importer) {
return source.replace(
customResolver(source, importer, options) {
const filePath = source.replace(
/^@\//,
importer?.startsWith(librarySrc) ? librarySrc : playgroundSrc
)

return this.resolve(filePath, importer, options)
}
}, {
find: '<%- config.scopedPackageName %>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfigWithTheme } from 'vitepress'

<%_ if (config.includeAtAliases) { _%>
const librarySrc = fileURLToPath(new URL('../../<%- config.mainPackageDirName %>/src/', import.meta.url))
const playgroundSrc = fileURLToPath(new URL('../src/', import.meta.url))
const docsSrc = fileURLToPath(new URL('../src/', import.meta.url))
<%_ } _%>

export default ({ mode }: { mode: string }) => defineConfigWithTheme({
Expand Down Expand Up @@ -40,11 +40,13 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
{
find: '@',
replacement: '@',
customResolver(source, importer) {
return source.replace(
customResolver(source, importer, options) {
const filePath = source.replace(
/^@\//,
importer?.startsWith(librarySrc) ? librarySrc : playgroundSrc
importer?.startsWith(librarySrc) ? librarySrc : docsSrc
)

return this.resolve(filePath, importer, options)
}
}, {
find: '<%- config.scopedPackageName %>',
Expand Down