index.ts — astro Source File
Architecture documentation for index.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 55004deb_f74c_122b_7d00_ae962d3aa84d["index.ts"] c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 55004deb_f74c_122b_7d00_ae962d3aa84d --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] 55004deb_f74c_122b_7d00_ae962d3aa84d --> f16d8c76_2866_6150_bd14_0347b59abfe9 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] 55004deb_f74c_122b_7d00_ae962d3aa84d --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 style 55004deb_f74c_122b_7d00_ae962d3aa84d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { resolve } from 'node:path';
import type { AstroIntegration } from 'astro';
import type { Plugin } from 'vite';
interface Options {
/**
* You can extend Alpine by setting this option to a root-relative import specifier (for example, `entrypoint: "/src/entrypoint"`).
*
* The default export of this file should be a function that accepts an Alpine instance prior to starting, allowing the use of custom directives, plugins and other customizations for advanced use cases.
*
* ```js
* // astro.config.mjs
* import { defineConfig } from 'astro/config';
* import alpine from '@astrojs/alpinejs';
*
* export default defineConfig({
* // ...
* integrations: [alpine({ entrypoint: '/src/entrypoint' })],
* });
* ```
*
* ```js
* // src/entrypoint.ts
* import type { Alpine } from 'alpinejs'
*
* export default (Alpine: Alpine) => {
* Alpine.directive('foo', el => {
* el.textContent = 'bar';
* })
* }
* ```
*/
entrypoint?: string;
}
function virtualEntrypoint(options?: Options): Plugin {
const virtualModuleId = 'virtual:@astrojs/alpinejs/entrypoint';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
let isBuild: boolean;
let root: string;
let entrypoint: string | undefined;
return {
name: '@astrojs/alpinejs/virtual-entrypoint',
config(_, { command }) {
isBuild = command === 'build';
},
configResolved(config) {
root = config.root;
if (options?.entrypoint) {
entrypoint = options.entrypoint.startsWith('.')
? resolve(root, options.entrypoint)
: options.entrypoint;
}
},
resolveId: {
filter: {
id: new RegExp(`^${virtualModuleId}$`),
},
handler() {
return resolvedVirtualModuleId;
},
},
load: {
filter: {
id: new RegExp(`^${resolvedVirtualModuleId}$`),
},
handler() {
if (entrypoint) {
return `\
import * as mod from ${JSON.stringify(entrypoint)};
export const setup = (Alpine) => {
if ('default' in mod) {
mod.default(Alpine);
} else {
${
!isBuild
? `console.warn("[@astrojs/alpinejs] entrypoint \`" + ${JSON.stringify(
entrypoint,
)} + "\` does not export a default function. Check out https://docs.astro.build/en/guides/integrations-guide/alpinejs/#entrypoint.");`
: ''
}
}
}`;
}
return `export const setup = () => {};`;
},
},
};
}
export default function createPlugin(options?: Options): AstroIntegration {
return {
name: '@astrojs/alpinejs',
hooks: {
'astro:config:setup': ({ injectScript, updateConfig }) => {
// This gets injected into the user's page, so the import will pull
// from the project's version of Alpine.js in their package.json.
injectScript(
'page',
`import Alpine from 'alpinejs';
import { setup } from 'virtual:@astrojs/alpinejs/entrypoint';
setup(Alpine);
window.Alpine = Alpine;
document.addEventListener('DOMContentLoaded', () => Alpine.start());`,
);
updateConfig({
vite: {
plugins: [virtualEntrypoint(options)],
},
});
},
},
};
}
Domain
Subdomains
Functions
Types
Dependencies
- astro
- node:path
- vite
Source
Frequently Asked Questions
What does index.ts do?
index.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in index.ts?
index.ts defines 2 function(s): createPlugin, virtualEntrypoint.
What does index.ts depend on?
index.ts imports 3 module(s): astro, node:path, vite.
Where is index.ts in the architecture?
index.ts is located at packages/integrations/alpinejs/src/index.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/alpinejs/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free