question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

server side rendering switch to preact webpack.config.js issue

See original GitHub issue

I am converting my project from React to Preact. Some React.Component is shared for client side and server side rendering.

The following only solves the client side rendering when the dependencies are bundling together

"resolve": {
    "alias": {
      "react": "preact-compat",
      "react-dom": "preact-compat"
    }
  }

As for the server side, I don’t need the bundling because it will be run by node. How can I config the webpack.config.js to resolve require("react-dom/server"), require("react-dom") and require("react"). I don’t want to change all require statement from react-dom to preact-compat. I dont want the preact-compat bundle with my server side rendering code.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
thangngoc89commented, Jun 4, 2017

You can transpile your code with babel using module-alias


@wood1986 why the downvote? If you dont want to touch your server code, than transpiling with babel is your best bet. No change in the codebase require. Or you can bundle everything with webpack (commonjs mode) and execute the bundle for SSR

1reaction
developitcommented, Jul 2, 2017

@thangngoc89 is correct - the best way to properly alias in Node (without webpack) is module-alias:

require('module-alias').addAliases({
  'react'  : 'preact-compat',
  'react-dom': 'preact-compat'
});

or, specify this in your package.json:

"_moduleAliases": {
  "react": "preact-compat",
  "react-dom": "preact-compat"
}

… and install the hook:

require('module-alias/register');
Read more comments on GitHub >

github_iconTop Results From Across the Web

server side rendering switch to preact webpack.config.js issue
I am converting my project from React to Preact. Some React.Component is shared for client side and server side rendering.
Read more >
Switching to Preact (from React)
There are two different approaches to switch from React to Preact: ... Simply add the following resolve.alias configuration to your webpack.config.js :.
Read more >
Aliasing Preact correctly for Server Side Rendering
While aliasing client side modules, we're able to swap react with preact/compat for all dependencies. But when these modules are externalized,  ...
Read more >
Switching from React to Preact (Server-side Rendering with ...
Serve Dynamic Content with Cloud Functions: https://goo.gl/kCEuPdPreact: https://preactjs.comPreact is a really small React alternative ...
Read more >
Code splitting and Server side rendering for preact async routes.
In this blog, we'll try to build a small app with two routes, with which we will try to fix the above-said problems....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found