Hide / Deactivate Files in Astro With This Little Trick
TL;DR:
In Astro, you can deactivate .astro
or .md
files by renaming them to start with a dot (.
). This makes the files hidden and prevents them from being processed or included in the build. It’s an easy and reversible way to manage inactive files without deleting them.
Introduction
Managing inactive files during web development can be tricky, especially if you’re using a framework like Astro. You may want to temporarily remove a file from your site without losing its content or breaking your project’s structure. Fortunately, there’s a quick solution: simply prepend the filename with a dot (.
).
This blog post explains why this trick works in Astro, when to use it, and what to keep in mind.
Why Use the Dot Prefix?
In many systems, files with names starting with a dot are treated as “hidden” and are excluded from certain operations. Astro inherits this convention, skipping hidden files during its build process.
For example:
src/pages/.hidden.astro // Ignored by Astro
src/content/.draft.md // Ignored by Astro
Use Cases
-
Temporarily Deactivate a File
Hide the file to exclude it from routing or content processing without deleting it. -
Work in Progress
Mark files that are still under development so they’re not live on the site. -
Organizational Clarity
Keep your directory clean by signaling inactive files as “hidden.”
How to Implement the Dot Prefix
Simply rename the file with a dot (.
) at the beginning:
example.astro → .example.astro
draft.md → .draft.md
Astro will automatically exclude these files from:
- Page routing (
src/pages
) - Content collections (
src/content
) - Builds or static generation processes
Things to Keep in Mind
- Explicit References
If you import a hidden file in your project, it will still be processed. For instance:import HiddenPage from './.hidden.astro'; // This will still work
-
Version Control
Hidden files are included by default in Git, but double-check your.gitignore
settings to ensure they’re tracked if needed. - No Permanent Removal
This trick is ideal for temporary deactivation. For permanent removal, delete the file or remove its references.
Conclusion
Using a dot prefix is a simple yet effective way to deactivate files in Astro. It keeps your project organized and lets you manage inactive files without risking accidental deletion. Whether you’re working on a draft or hiding a page temporarily, this trick is a lifesaver for clean and efficient development.
Start using the dot prefix today, and make managing files in Astro easier than ever!