catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A solution using require hook to do server rendering without pre bundling

namnm opened this issue · comments

Thank you for this awesome package. I just want to share a way to do server rendering easier with webpack.

I guess that you guys have been struggling with server rendering for a long time like me. I have made a package that allows us to require files like sass or image directly without pre bundling. You can take a look at https://github.com/namnm/webpack-register and give me feedback if any. Hope it can help you simplify the server rendering part somehow.

I see, so what your library does is it runs Webpack when require('webpack-register') is called.
The webpack.config.js path is passed to that function.
When Webpack build finishes it populates the resources map.
If a file is changed on disk, node.js is restarted when using nodemon and server-side also restarts itself and updates the assets map.
Well, looks like your solution is clean and simple, compared to webpack-isomorphic-tools, for example.
Still not sure if your library's gonna work for non-extract-text-plugin styles, for example.
Anyway, it seems to be a good library.

As for the benefits, I don't see much benefits compared to creating the server-side bundle.
One benefit could be that your library uses MemoryFS.

With that minified bundle, it's impossible to debug if an error happens inside.

First, the bundle isn't minified in this example.
Second, even if it was minified, there are still source maps (which may not always work for everyone but that's another issue).
Third, the server-side bundle created by this libarary is the same one created by your library – it only contains client-side code.

As for now, I'm satisfied with this repository library's performance.
But your solution is clever too.
Thx for sharing.

@catamphetamine Thank you so much for your feedback! I will improve the README and include some more usage and caveat tips.