Closed jonschlinkert closed 7 years ago
just saw this comment. That might be a solution too.
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?
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.
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.
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!
The goal is to make gray-matter easier to use in browsers/non-node.js environments.
Related: https://github.com/jonschlinkert/gray-matter/issues/49
My first thought is that we could achieve this by publishing
gray-matter-fs
or something. Any other ideas?cc @tech4him1