#Include globally a module
3 messages · Page 1 of 1 (latest)
Hi @stone kindle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To include a JavaScript module globally on every page in Astro, you can add the necessary import statement to each .astro file in your project. This will apply the imported module to every page of your site. Here's an example of how to do this:
---import '../your-module.js';---
You would add this line of code to each .astro file in your project. For instance, if you have src/pages/index.astro and src/pages/blog.astro, you would add the import statement to both of these files.
However, please note that the import statement is added to every page exactly as-is. This means that for deeper pages, like src/pages/blog/[slug].astro, you might need to adjust the import path to correctly locate the module.
For local integrations, you can use aliasing to simplify this process. For instance, you could alias src/your-module.js to something like @your-module. This way, you can use the same import statement across all your .astro files, regardless of their depth in the project structure.