-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Does svg.js support node.js? #352
Comments
What do you want to do exactly? |
I'm planning to build a APIlike server that returns SVG data as plain text. |
As long as you dont use functions which relates on methods made available by the browser (e.g. bbox) it should work. But I am not sure with that. You have to try that yourself |
svg.js will not work inside node.js as it assumes the presence of a Anyway, this is not something svg.js should take care of, so this is ready to be closed. |
I think there's just one small part missing. If svg.js allowed me to pass the "global scope object", it would easily be possible. jsdom gives me a AFAIK, everything else works. |
I'd like svg.js to either respect environments without a global |
Any idea on how to accomplish this? |
No sry, I haven't gone through the code of svg.js. jQuery allows you to pass a |
Actually I cannot see the line where you can really pass the window objcect. It just checks for the window object to be present and passes |
Look at the lines 25-27. If the global scope has no |
Ok - I think I understand how it works. Please test this for me: (function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = root.document ? factory(root, root.document) : function(w){ return factory(w, w.document) };
} else {
root.SVG = factory(root, root.document);
}
}(typeof window !== "undefined" ? window : this, function(window, document) { You now can require your module via |
@derhuerst @y0ke @lweigand you all were that curios about that. What happend? :D |
My short-lasting motivation about SVG is over. I will have to wait until it comes back. :P Furthermore, my contribution to this discussion was not because I urgently need to use SVG.js in Node, but because i like isomorphic NPM modules in general. |
First of all, thank you againg for open sourcing and developing svg.js, it is the best svg lib you can find. Thank you also for the hints in this thread. I am using svg.js with Node for my flow-view project, where I am using SVG.js file for server side, and window.SVG.js file for the browserified version. I tryed the solution proposed, see fibo/flow-view@f1e5c1b where I used my svg.js custom build after modifying dist/svg.js with code found in #352 (comment). I only tryed with a trivial test, but, it works and I hope this solution will be merged (please let me know). It also open a big door to server side svg export to png or to svg file. A note about plugins: in the browserified version I am using require('svg.js.pluginfoo') and it works, so in this sense svg.js support Node too, at least when browserified. I am not sure if it is just a trick that I found or it is implicitly known by most of developers, since I did not found any documentation about how to use plugins from npm. |
Glad to hear, that this works. |
I am not a gulp expert (I currently use bare npm scripts) but I think you could even write your own task, so it would not be difficult if you cannot find a plugin that do specifically that. By the way, I am also testing it on client side and it still works too. |
I am curious if bbox works on serverside. Can anyone try that for me? (@fibo maybe?) |
@y0ke @leoweigand @derhuerst @fibo we just released the new project svgdom which enables svg.js to run on node. Its nothing big but give it a try and report back :) |
@Fuzzyma thanks for the heads-up! I'll make sure to look into it when I am tinkering with svg again ;) |
check out also svgx which renders SVG server side |
hi all.
Does svg.js support node.js?
Sorry If I missed the part of the document which states about it.
Thanks in advance.
The text was updated successfully, but these errors were encountered: