universal-react icon indicating copy to clipboard operation
universal-react copied to clipboard

Getting Code Splitting to work

Open dalebaldwin opened this issue 8 years ago • 6 comments

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?

dalebaldwin avatar Aug 07 '17 12:08 dalebaldwin

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.

dominictobias avatar Aug 07 '17 17:08 dominictobias

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

dalebaldwin avatar Aug 07 '17 22:08 dalebaldwin

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 avatar Aug 08 '17 01:08 dalebaldwin

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.

dalebaldwin avatar Aug 08 '17 04:08 dalebaldwin

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.

dominictobias avatar Aug 08 '17 11:08 dominictobias

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.

dalebaldwin avatar Aug 10 '17 04:08 dalebaldwin