sveltejs / prettier-plugin-svelte

Format your svelte components using prettier.
MIT License
735 stars 95 forks source link

Add browser build #417

Closed curran closed 7 months ago

curran commented 8 months ago

Closes #69

Heavily inspired by the great work already done by @cfraz89 in https://github.com/sveltejs/prettier-plugin-svelte/pull/239, this PR is a slightly more surgical approach, introducing the bare minimum changes to get a browser build to work.

I have tested it locally using npm link and it does work!

One drawback of this implementation is that it still exposes the reference to the global Buffer. This makes the code changes to this project minimal, but shifts the burden to consumers to perform some nasty hackery to get it to work, namely this:

import * as prettierPluginSvelte from 'prettier-plugin-svelte/browser';
import { Buffer } from 'buffer';
globalThis.Buffer = Buffer;

I propose to make the change that removes the Buffer dependency separately, treating that as a separate issue that would be an enhancement to the browser build.

curran commented 7 months ago

Just want to give a heads up that I plan to publish this build as a separate package in NPM in the next week or so, so that I can use it in my app.

Please let me know if there are any blockers to merge that I can help with here. Thanks!

dummdidumm commented 7 months ago

I wanted to do a few edits but wasn't able to, therefore opened #430