Coder Social home page Coder Social logo

Comments (2)

psychobolt avatar psychobolt commented on September 8, 2024

This solution seems to work for build: gatsbyjs/gatsby#13219 (comment) . Have you tried it?

from react-paperjs.

amcc avatar amcc commented on September 8, 2024

Thanks so much for the help here. This solves the jsdom issue. You also need @loadable/component to prevent build/ssr issues too.

Interestingly because we need named imports I couldn't use @loadable/component easily for the multiple named imports needed with this project (unless there's a trick i'm missing) so I made a component with react-paperjs normally then imported that component with @loadable/component. If there is a way to use @loadable/component or similar deferred loader directly with multiple named imports let me know.

Hope this helps someone else and thanks for the response....

For GatsbyJS - Create a component exactly like the documentation in this repo, add the code to gatsby-node.js as above, code below:

exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
  if (stage === "build-html") {
    actions.setWebpackConfig({
      module: { rules: [{ test: /node_modules\/paper/, use: loaders.null() }] },
    });
  }
};

Import your react-paperjs component with @loadable/component as below:

const PaperComponent = loadable(
  async () => (await import("../components/Paper")).PaperComponent,
  {
    fallback: <>Loading...</>,
  }
);

You can then use it normally in things like Gatsby and Next with SSR.

I chose a named export/import for my react-paperjs component, but if its a default export the import is simpler, docs here: https://loadable-components.com/

@psychobolt if the above all sounds like reasonable instructions and info I hope its useful.

I made a simple gatsby starter site with the above code here:
https://github.com/amcc/gatsby-paper-fiber

from react-paperjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.