search

Home  >  Q&A  >  body text

Nest.js app using React and resources for server-side rendering

Because I have a bit of a misunderstanding of the core principles of server rendering, there is no code.

I have:

Nest.js is configured with Handlebars. It is built using TypeScript out of the box. I don't use webpack here. I also created a separate folder that contains the client portion of my application. React, webpack, etc. are already configured and working fine.

I need to create a server render. For this I use ReactDOMServer. Everything works fine except when encountering SVG components and CSS modules.

This is my question - how to deal with it? What is the correct approach? Should I copy the webpack configuration on the server side (referring to resources), or is there a way to make it work with TypeScript (npm run build)?

thank you for your help!

P粉134288794P粉134288794352 days ago487

reply all(1)I'll reply

  • P粉237029457

    P粉2370294572024-03-26 12:15:58

    You need to provide static resource files https://docs.nestjs.com/recipes/serve-static

    You need to install @nestjs/serve-static

    imports: [
      ServeStaticModule.forRoot({
        rootPath: join(__dirname, 'directory') // 文件路径,
      }),
    ],

    reply
    0
  • Cancelreply