rough-stuff / rough

Create graphics with a hand-drawn, sketchy, appearance
http://roughjs.com
MIT License
19.88k stars 615 forks source link

Use in Nextjs #187

Open kaisiant opened 3 years ago

kaisiant commented 3 years ago

import rough from "roughjs/bundled/rough.esm" image

import rough from "roughjs/bin/rough" image

I need some help, thanks

pshihn commented 2 years ago

Seems like you are having trouble loading es6 modules in next. Not sure how to configure that. You can also try loading from roughjs/bundled/rough.cjs.js

ShahriarKh commented 2 years ago

AFAIK it's resolved in Next 12.

williamsjokvist commented 2 years ago

AFAIK it's resolved in Next 12.

Can you get it working? No luck here, even tried using next-transpile-modules.

museumhotel commented 1 year ago

AFAIK it's resolved in Next 12.

Can you get it working? No luck here, even tried using next-transpile-modules.

was able to achieve rough-like effect in next using the thi.ng geom-fuzz library 🤷‍♂️

ShahriarKh commented 1 year ago

Here is a simple example in Next:

import rough from "roughjs/bundled/rough.cjs.js";

export default function ComponentName() {
    useEffect(() => {
        let svg = document.getElementById('some-id');
        const rc = rough.svg(svg);
        let node = rc.circle(12, 12, 20);
        svg.appendChild(node);
    }, [])

    return <svg id='some-id' />
}

be sure to set height ad width for your <svg> element. I'm using useEffect here to ensure the element is created in client-side (not server-side) and document is available.