Svgo: Use svgo without node / less dependancies

Created on 1 Jun 2016  路  8Comments  路  Source: svg/svgo

So I'm trying to svgo in a project which does not, and will not have node.
The project has its own require function, etc.

Note:
I'm trying to use svgo similar to this:
https://github.com/svg/svgo/blob/master/examples/test.js
Except I already have the svg file as a string... in fact there is no svg file on the filesystem.

svgo has a bunch of npm dependancies, some of which may be easy to remove.

Here are some guesses from me:

  • fs, and js-yaml are only used to load configuration from a yml file,
    Instead I want to pass in config as a js data structure, so then those two would no longer be required, yes?
  • coa and mkdir are only used when svgo is run from the command line, and since I want to use svgo as a js library, I don't need that?
  • colors is only used when using the convertcolor plugin, which I don't need.

Perhaps svgo needs to be modularized into even more packages?

Most helpful comment

What about svgo-core and svgo?

All 8 comments

If you bundle svgo using Broserify, it will only bundle the dependencies required by the entrypoint. Thus, the CLI dependencies won't be included.

Hello! Sorry for the late response.

fs, and js-yaml are only used to load configuration from a yml file,

Yes, but fs is also used to load and save files (full folders). So, yes, if you pass in everything they aren't needed, that's true.

coa and mkdir are only used when svgo is run from the command line, and since I want to use svgo as a js library, I don't need that?

Yep.

colors is only used when using the convertcolor plugin, which I don't need.

Are you talking about require('colors'); in coa.js? It's being used for coloring CLI. Quick search in the repo shows, that's there no other colors.

It seems as if svgo could be easily split into svgo and svgo-cli.

Yeah, but people got used to npm install svgo for the CLI utility, so I don't think it's a good idea to change this for sake of backward compatibility. It can break many CI-processes.

What about svgo-core and svgo?

Maybe. But it's not on top of priorities.

@ben-eb Thanks!

Let's close this in favor of #436 because that issue fits better.

Was this page helpful?
0 / 5 - 0 ratings