getConfigAlias() — astro Function Reference
Architecture documentation for the getConfigAlias() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 1ba10327_e048_1b04_3323_048810802c61["getConfigAlias()"] 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c["index.ts"] 1ba10327_e048_1b04_3323_048810802c61 -->|defined in| 7996ca89_cb81_c0ba_4ce2_f1ad1a93890c 41c9f435_8602_aa44_336c_21df75b6be30["configAliasVitePlugin()"] 41c9f435_8602_aa44_336c_21df75b6be30 -->|calls| 1ba10327_e048_1b04_3323_048810802c61 style 1ba10327_e048_1b04_3323_048810802c61 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/vite-plugin-config-alias/index.ts lines 14–68
const getConfigAlias = (settings: AstroSettings): Alias[] | null => {
const { tsConfig, tsConfigPath } = settings;
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions) return null;
const { baseUrl, paths } = tsConfig.compilerOptions as CompilerOptions;
// If paths exist but baseUrl doesn't, default to "." (tsconfig directory)
const effectiveBaseUrl = baseUrl ?? (paths ? '.' : undefined);
if (!effectiveBaseUrl) return null;
// resolve the base url from the configuration file directory
const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), effectiveBaseUrl);
const aliases: Alias[] = [];
// compile any alias expressions and push them to the list
if (paths) {
for (const [alias, values] of Object.entries(paths)) {
/** Regular Expression used to match a given path. */
const find = new RegExp(
`^${[...alias]
.map((segment) =>
segment === '*' ? '(.+)' : segment.replace(/[\\^$*+?.()|[\]{}]/, '\\$&'),
)
.join('')}$`,
);
for (const value of values) {
/** Internal index used to calculate the matching id in a replacement. */
let matchId = 0;
/** String used to replace a matched path. */
const replacement = [...normalizePath(path.resolve(resolvedBaseUrl, value))]
.map((segment) => (segment === '*' ? `$${++matchId}` : segment === '$' ? '$$' : segment))
.join('');
aliases.push({ find, replacement });
}
}
}
// compile the baseUrl expression and push it to the list
// - `baseUrl` changes the way non-relative specifiers are resolved
// - if `baseUrl` exists then all non-relative specifiers are resolved relative to it
// - only add this if an explicit baseUrl was provided (not the default)
if (baseUrl) {
aliases.push({
find: /^(?!\.*\/|\.*$|\w:)(.+)$/,
replacement: `${[...normalizePath(resolvedBaseUrl)]
.map((segment) => (segment === '$' ? '$$' : segment))
.join('')}/$1`,
});
}
return aliases;
};
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getConfigAlias() do?
getConfigAlias() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-config-alias/index.ts.
Where is getConfigAlias() defined?
getConfigAlias() is defined in packages/astro/src/vite-plugin-config-alias/index.ts at line 14.
What calls getConfigAlias()?
getConfigAlias() is called by 1 function(s): configAliasVitePlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free