Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser compatible #633

Closed
wants to merge 6 commits into from
Closed

browser compatible #633

wants to merge 6 commits into from

Conversation

caub
Copy link
Contributor

@caub caub commented Dec 13, 2016

  • browser bundle
  • promise api:
new SVGO(svgoConfig).optim(svgStr)
.then(svgjs => {
	console.log('result:', svgjs.data)
})
.catch(console.error);

@caub
Copy link
Contributor Author

caub commented Mar 21, 2017

added below a commit to round viewBox to floatPrecision too, simplified removeViewBox plugin, I can make it a separate PR later when more time

Also we should use this to Math.round to round values:

var p=3; console.time(1); var factor=Math.pow(10,p); for(var i=0;i<1e6;i++){ var x=Math.random(); Math.round(x*factor)/factor } console.timeEnd(1);
var p=3, re=/0+$/; console.time(2); for(var i=0;i<1e6;i++){ var x=Math.random(); x.toFixed(p).replace(re, '') } console.timeEnd(2);

it's faster than toFixed, and I can't think of a reason to keep trailing zeros? (2.30 instead of 2.3)

@caub caub force-pushed the browser branch 3 times, most recently from 546c58f to 2ccd1b6 Compare March 22, 2017 11:57
@GreLI
Copy link
Member

GreLI commented Mar 25, 2017

I'm afraid it's too much change to accept. I don't want to stick to webpack or any compiler to keep code base as simple, compact and effective as possible. Lazy plugins requiring, when plugins are loaded only when needed, also follows this goal.

Unfortunately, I don't know a graceful way to make it compatible with non-Node.js environment. Hopefully, there'll be a solution in future like new module system.

@GreLI GreLI closed this Mar 25, 2017
@caub
Copy link
Contributor Author

caub commented Apr 6, 2017

Do you accept if I clean it? this PR was really dirty

For webpack, I don't especially love it myself too, but I'm sure many users would benefit if SVGO can run in browser without effort, I need it for work, like https://github.com/jakearchibald/svgomg too.
But webpack is just a dev dependency, I would just need to change the .svgo.yml to .js or .json because yml doesn't work well with webpack, else everything is almost unchanged

Would it be ok? and thanks for all the hard work

Will do, in hope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants