docs icon indicating copy to clipboard operation
docs copied to clipboard

Add: Explain how to use .yml data files

Open swift502 opened this issue 3 years ago • 1 comments
trafficstars

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:

  1. Install @rollup/plugin-yaml:
npm install @rollup/plugin-yaml --save-dev
  1. 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()]
+  }
});
  1. 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!

swift502 avatar Aug 12 '22 08:08 swift502

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...

sarah11918 avatar Aug 15 '22 11:08 sarah11918

💡 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 avatar Nov 03 '22 15:11 delucis

@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.

swift502 avatar Nov 03 '22 15:11 swift502

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?

swift502 avatar Nov 03 '22 15:11 swift502

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 avatar Nov 03 '22 16:11 delucis

@delucis I'll make a draft PR then. 👍 Let's discuss the wording in the PR.

swift502 avatar Nov 03 '22 16:11 swift502

Awesome — thanks so much @swift502!

delucis avatar Nov 03 '22 16:11 delucis