You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:infraIssues about CI, publishing to npm, or similar
The Babel REPL has been using Prettier via bundle.run for some time. Version 1.7.0 broke our ability to do this with the error: "cosmiconfig requires at least version 4 of Node". Version 1.8.0 introduced a different error: "os$2.homedir is not a function".
It would be ideal if Prettier output a browser-friendly UMD bundle for use-cases like this, but in lieu of that maybe it could at least work via a solution like rundle.run? 😄
For the time being, we've pinned Babel to use Prettier version 1.6.1. You can try it out here if you'd like.
Reacted by Glavin Wiechert, Johannes Schickling, Lipis, Liu YuanYuan, Tim Suchanek, u3u and Nicky McCurdy
A UMD bundle would be so-so-so great ❤️ If there's support for that idea, I'd also be happy to help (although I am not familiar with Prettier's codebase)
How about extracting prettier.format() to another file? The browser version seems no need to read config file (fs-related), it only cares about prettier.format().
Reacted by Lily Skye, Glavin Wiechert and Nicky McCurdy
The parsers are already bundled separately! Seems like we could do is have another bundle for the format function and we’ll have all the pieces in place, just needing some work so they can work together in the browser
I think we should ship the shims, but instead of doing the lazy require stuff or using a custom require, we should ship a UMD bundle containing a factory function that users plug the parsers into, and we should ship the parser versions we vendor as UMD bundles.
So eventual CommonJS usage would be something like:
constmakePrettier=require("prettier/bundle/makePrettier");// or whateverconstflowParser=require("prettier/bundle/flow");constprettier=makePrettier({ flowParser })
And you would only ship the parsers you need
Reacted by Lucas Duailibe, u3u, Axetroy and Phil Cockfield
For my usage, it would be nice to be able to export prettier without a parser. I'm currently developing a parser out-of-tree, and I need to use the printDoc functions but not necessarily any parsing functions.
help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:infraIssues about CI, publishing to npm, or similar
Activity
mitermayer commentedon Nov 20, 2017
This sounds reasonable to me, I can try looking into this during the weekend, unless @azz , @suchipi @ikatyang wants to look into this first
bvaughn commentedon Nov 20, 2017
A UMD bundle would be so-so-so great ❤️ If there's support for that idea, I'd also be happy to help (although I am not familiar with Prettier's codebase)
suchipi commentedon Nov 20, 2017
I think we can fix "os$2.homedir is not a function" with the same approach as in this PR (adding to the rollup-plugin-replace config): #2930
"cosmiconfig requires at least version 4 of Node" might require a change to cosmiconfig.
suchipi commentedon Nov 20, 2017
Also, since we are already using rollup, we are probably not too far from generating a working UMD bundle.
ikatyang commentedon Nov 20, 2017
How about extracting
prettier.format()to another file? The browser version seems no need to read config file (fs-related), it only cares aboutprettier.format().bvaughn commentedon Nov 20, 2017
A trimmed down version for the browser would be slick.
Would also be nice if there were multiple UMD targets - so we could avoid loading parsers for targets/languages we don't care about (eg CSS).
But I don't want to be greedy. 😁
duailibe commentedon Nov 20, 2017
The parsers are already bundled separately! Seems like we could do is have another bundle for the format function and we’ll have all the pieces in place, just needing some work so they can work together in the browser
azz commentedon Nov 21, 2017
It already kind of works - the files here are built with rollup and already run in the browser, you just need this gross patch:
prettier/website/static/worker.js
Lines 5 to 26 in b4e7942
We can definitely improve this, splitting the cli into a separate bundle is a great idea. I like the idea of making a UMD bundle, too.
duailibe commentedon Dec 10, 2017
Now that I've worked a bit more on the playground there are a few problemas we need to sort to get this working:
require).Does it make sense to ship a version with those shims and a custom
require(not the hackish version we use) ?suchipi commentedon Dec 10, 2017
I think we should ship the shims, but instead of doing the lazy require stuff or using a custom require, we should ship a UMD bundle containing a factory function that users plug the parsers into, and we should ship the parser versions we vendor as UMD bundles.
suchipi commentedon Dec 10, 2017
So eventual CommonJS usage would be something like:
And you would only ship the parsers you need
siefkenj commentedon Dec 21, 2017
For my usage, it would be nice to be able to export prettier without a parser. I'm currently developing a parser out-of-tree, and I need to use the printDoc functions but not necessarily any parsing functions.
j-f1 commentedon Dec 21, 2017
@siefkenj Check out #3511 and #3536.
duailibe commentedon Dec 26, 2017
I'm gonna start working on this now :)
azz commentedon Dec 26, 2017
@duailibe Wow, I was just typing up #3574.
duailibe commentedon Dec 27, 2017
Can't work on this right now, if anyone wants to take a shot at it (cc @azz)
huv1k commentedon Feb 24, 2018
Any news on this? :) I think a lot of tools could benefit from it for example Graphql playground graphql/graphql-playground#327
nickserv commentedon Apr 28, 2018
This would also be great for using Prettier in browser extensions! See https://github.com/krawaller/prettier-js-extension.
suchipi commentedon May 2, 2018
@duailibe has been doing some refactoring work that is getting us closer to this but we aren't all the way there yet, if I understand correctly.
huv1k commentedon May 27, 2018
Thx we are rocking it in playground now :) graphql/graphql-playground#702
azz commentedon May 27, 2018
Yep, shipped in 1.13.0:
https://prettier.io/docs/en/browser.html