server side rendering switch to preact webpack.config.js issue
See original GitHub issueI 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
@thangngoc89 is correct - the best way to properly alias in Node (without webpack) is module-alias:
or, specify this in your
package.json
:… and install the hook: