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

Using SnapSVG inside of NodeJS #640

Open
addijhaq opened this issue Sep 17, 2020 · 0 comments
Open

Using SnapSVG inside of NodeJS #640

addijhaq opened this issue Sep 17, 2020 · 0 comments

Comments

@addijhaq
Copy link

addijhaq commented Sep 17, 2020

Found a way to do this using JSDOM, however all examples are using outdated code

const jsdom = require('jsdom');
const xmlserializer = require('xmlserializer');

jsdom.env('', ['node_modules/snapsvg/dist/snap.svg.js'], (error, window) => {
    if (error) throw error;

    const paper = window.Snap(100, 100);

    const rect = paper.rect(20, 20, 60, 60);
    rect.attr({fill: 'red'});

    const svg = xmlserializer.serializeToString(paper.node);
    window.close();

    console.log(svg);
});

This no longer works.

Any suggestions on how to get SnapSVG running inside of Node.js with JSDOM without using webpack?

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

No branches or pull requests

1 participant