docs
docs copied to clipboard
Add: Explain how to use .yml data files
I had to ask this on discord because I couldn't find it in the docs. I think it might help others looking for the same thing, since in my opinion you'd expect it to be much simpler than it is.
Proposal
Somewhere near the JSON section, explain that in order to import .yml files, the user needs to:
- Install @rollup/plugin-yaml:
npm install @rollup/plugin-yaml --save-dev
- In astro.config.js import it and add it to the vite plugins array:
import { defineConfig } from 'astro/config';
+ import yaml from '@rollup/plugin-yaml';
export default defineConfig(
{
+ vite: {
+ plugins: [yaml()]
+ }
});
- Import .yml files as such:
const data = await Astro.glob('data.yml');
Please let me know what you think. I can make a PR if this was desirable. Thanks!
Thanks for this @swift502! Firstly, I'm glad that importing .yml files is working for you. 🙌
Secondly, I'm going to confirm with our Technical Steering Committee that this is the process they want documented. While you certainly can add Vite plugins directly, I think in some cases that's thought of as a bit of an escape hatch solution. So I first want to make sure there's not a different way that engineering is expecting you to do this and/or that this isn't something they want to try to change internally so that a Vite plugin wouldn't be necessary.
But yes, after we have confirmation, then I'd love for you to contrubute a PR! Sit tight! I'll be back...
💡 Idea!
We recently updated our Imports guide. We think this could be a cool addition there, under a “Extending file type support” heading maybe right at the bottom of the page. This would be a good example for how to do this.
One question: step three in the example here shows Astro.glob to import the .yml. Does this also work using a plain import statement?
@delucis Oh wow, you're right. import does work.
Demo: https://stackblitz.com/edit/github-g5iwb3?file=src/pages/index.astro
The third step should then probably use the import statement.
If this example is going to be a generic "unusual file format" example, should we then also mention how/where users should look to find the specific plugin they need for their spcific format? So probably the https://github.com/rollup/plugins repo, and maybe there's other places?
should we then also mention how/where users should look to find the specific plugin they need for their spcific format?
Something small would be helpful yes! I guess Vite plugins are the other option to look out for?
@delucis I'll make a draft PR then. 👍 Let's discuss the wording in the PR.
Awesome — thanks so much @swift502!