jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert

Home Page:https://github.com/jonschlinkert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

consider removing fs

jonschlinkert opened this issue · comments

The goal is to make gray-matter easier to use in browsers/non-node.js environments.

Related: #49

My first thought is that we could achieve this by publishing gray-matter-fs or something. Any other ideas?

cc @tech4him1

just saw this comment. That might be a solution too.

commented

Another way that would work for us if you don't want to change the sources would be to have a re-packaged version for browsers that was run through Babel or something like that and left out the Node functions like matter.read/fs.

If we did it that way, then you should be able to build the sources however you want, then publish it as two separate packages (maybe gray-matter and gray-matter-browser or something like that).

If we did it that way, then you should be able to build the sources however you want, then publish it as two separate packages (maybe gray-matter and gray-matter-browser or something like that).

yeah, that's not a bad idea. Let me think about it for a little bit (today). @doowb?

commented

Another option if we are just considering fs is wrapping the require in an if:

if (require) { require('fs'); }

I'd still have to test this though, I'm not sure that it works with WebPack.

what if we did gray-matter-lite or something, then we could require that into this module for the time being to keep the API the same here.

commented

That sounds really good.

I like the idea of having a separate module with browser compatible features that is then required into gray-matter.

The if(require) { require('fs'); } won't work for webpack because webpack does static analysis to determine which modules to include by looking at the require keyword.

Another option that might work is for gray-matter to add a browser property to package.json with {"fs": false} since webpack supports the package browser field spec now. I haven't tested this to know if it would work for you or not.

That would be awesome.

commented

This is working as of version 3.0.6. Thanks!

This is working as of version 3.0.6. Thanks!

Great! I was going to ask. Thanks!