sekoyo / universal-react

A universal react starter, with routing, meta, title, and data features
242 stars 50 forks source link

Getting Code Splitting to work #34

Open dalebaldwin opened 7 years ago

dalebaldwin commented 7 years ago

Possible just a feature request if you have time (I'll put a pull request if I work it out) but this one has me a bit stuck and I'm still a bit of newbie with React. I'm trying to get code splitting to work on routes but can't find documentation that works with and the webpack 3.4.1 instructions don't work for me either.

My current guess is that node can't work with the newer import() operator. If I switch it out to require() I can get the server to start up. If I then switch it over to import() it will generate the files so I know webpack is at least working with it but then Node will error out.

Any ideas?

sekoyo commented 7 years ago

I've only done it with client-side projects so you might be right, just a few days ago a contributor to webpack made a blog saying he is able to achieve the first real code splitting universally (it's merged into webpack but not released yet): https://medium.com/faceyspacey/announcing-react-universal-component-2-0-babel-plugin-universal-import-5702d59ec1f4

At some point I'd like to look into that and maybe make an overhaul of this project using what is mentioned there.

dalebaldwin commented 7 years ago

I looked through the change log and I think it's been merged. Will see if I can get it working today.

dalebaldwin commented 7 years ago

Looks like the required code has been added to webpack it just hasn't made it over to NPM yet. Will try and get it working once it comes out.

dalebaldwin commented 7 years ago

Got it working on my fork https://github.com/quantumninja/universal-react but there is an issue with code flashing up so working on fixing that next.

sekoyo commented 7 years ago

Nice! I'll have a look at this when I've got some time. Saw your post on the universal github page, yep probably a good idea to see if you can build something off of that one and see if you have the same issue. I was thinking about doing a major refactor on this to more closely reflect the example from that blog too.

dalebaldwin commented 7 years ago

I started on it but haven't had any luck getting it to work with your repo yet. I've gone back and am trying to build from scratch at the moment. The number of interacting elements on this really doesn't help.