#Remove node_modules used in SSG from client bundle

12 messages · Page 1 of 1 (latest)

tacit grove
#

I am using react-markdown to render parts of a static page at build only, is there a way to remove the dependencies from client bundle? (it is 80KBs which i would like to remove)

warm oyster
#

If you would be able to do this work inside your getStaticProps/getServersideProps function, Next.js will automatically not include this node module in the final client side bundle. But not sure if this will be possible for react-markdown..

tacit grove
#

I tried to, but I doesnt seem like I can render jsx inside getserveside props, I am not sure tho?

warm oyster
#

Hm no I’m afraid not…

tacit grove
#

Maybe there is a webpack config or smth to exclude the module from bundle? The webpack docs are a nigjtmare to navigate, I can't find it.

fickle cedar
#

its not possible at the moment

#

you need to be able to rehydrate the page in the client so the library is necessary

#

the only exception is if you render the entire thing at once and dont care for interactivity afterwards

#

then you can render the JSX inside gSP/gSSP and send the built HTML as props to the page

tacit grove
#

Ps. The only method that worked was to use ReactDOMServer.renderToStaticMarkup() which returned an html string

fickle cedar