text
stringlengths
0
1.36k
**Mikeal Rogers:** Yeah. We talked about create-react-app on the show before, but Alex, why don't you give us a little bit of that back-story and a little bit about this in less than 12 minutes, how about that? \[laughter\]
**Alex Sexton:** That's tough... That's an Alex problem. Alright, create-react-app is very similar to Ember CLI, if you've ever used Ember. I think Angular has its own CLI tool as well that I don't know the name of, but pretty much the goal of create-react-app is to manage all of the things that Mikeal's always complai...
If you want to color completely in the lines of the suggested React world set of tools...
**Mikeal Rogers:** And Webpack, for that matter...
**Alex Sexton:** Yeah, that's included in the suggested React world set of tools... Then you can use create-react-app. The idea is that you can say "Create create-react-app to do" and then you have a React app for to-do's that automatically compiles your ES6, has a way to do CSS in JavaScript, does error handling and b...
The history is interesting... It was like a hack weekend project, because React was one of -- a lot of the feedback React got was that there's no kind of baseline of guaranteed, supported tools that work together, and this is kind of like an answer to say like "Well, this stuff all works together." So it's kind of like...
The idea is you have to stay within their -- so it even configures your ESLint, it configures your Webpack, it configures your CSS, it configures your Babel... All these different things. And that configuration is even hidden from you, because if you change it, then it's harder for them to make the assumptions that the...
Does that make sense as kind of a background?
**Rachel White:** Makes sense to me...
**Alex Sexton:** Cool. In general, I found that with the things at work that are difficult to do, if I wanna do a create-react-app, I have to eject pretty fast, because we need to change one ESLint thing in order to work with our build servers, and it's "Ugh, that kind of stinks." And that's like part of the deal... It...
In general, I haven't paid enough attention to create-react-app to get mad when they have an update and my thing can't update with them, but this release would be maybe a good example of something that's like "Well, if you stayed in the coloring lines, this would be a really nifty change." So we can go through the chan...
**Mikeal Rogers:** Sure, sure. My first question... So it says something on the order of like "Okay, you can use import/export semantics now without actually compiling down to CommonJS", but it's compiling down to something, just to get into the browser. It's not relying on the browser's support yet.
**Alex Sexton:** \[27:55\] It could... I think you skipped ahead. Webpack 2 is part of create-react-app now; it used to be based on Webpack 1. Most people were on Webpack 1. Webpack 2 is pretty new and it's a larger departure than a lot of 2.0 would be, so it's gonna take some work to get people moved over. But one of ...
Before, if you gave Webpack 2 imports and exports ES6 modules and you weren't using Babel, nothing would happen; it would break because it wouldn't understand that. So what the steps would be would be compile with Babel to require statements, and then pass this to Webpack, and then Webpack could understand the require ...
**Mikeal Rogers:** Oh, okay...
**Alex Sexton:** But there are some features in ES6 modules like static analysis and stuff like that that are more guaranteed in ES6 modules, so they were able to say "Alright, we no longer care if you pass this require or these things, and so may skip the Babel step in order to pass imports and exports rather than fir...
So it's more of a "What does Webpack understand?" rather than... You still more than likely at the end will compile it down to require statements from whatever library in order to bundle it all together - it's part of what Webpack does - but it natively understands imports and exports now. And that is now included auto...
**Mikeal Rogers:** Yeah, I'm just constantly sort of reframing how to think about Webpack. I think that for the longest time everybody thought of it as this compile tool, but in actuality it's more like a platform onto itself. It has a lot of primitives, like its own module system with more types and things like that t...
**Alex Sexton:** Yeah, it is an interesting tool. It kind of crosses over a few different boundaries of old tools that we've had, and so if you think about it as a Grunt type thing, you'll think about it as a Grunt type thing; if you think about it as a Babel type thing, you'll think about it as a Babel type thing. But...
**Rachel White:** I was going through and reading the whole What's New in the create-react-app article, and a bunch of it made sense to me, but there's some things in here that I never heard of and I have no idea what they are... One of those being Jest 20.
**Alex Sexton:** It's a React-specific thing, just like the test running framework for React...
**Rachel White:** Oh...
**Alex Sexton:** \[31:49\] So they've just upgraded Jest I guess two versions. It used to be Jest 18, or something like that. Testing - we should do a whole episode on testing some time in the future, but one of the hardest parts about testing in the past, if you guys have done testing at scale for a web app (which may...
**Rachel White:** Nice!
**Alex Sexton:** And it's a little different than running jsdom, which is essentially providing a subset of a browser. And you can do a lot of the tests that you used to do very slowly, very non-deterministically with browsers as a unit test, where you say "If a click is applied here, the DOM should then reflect these ...
So Jest is good at helping you manage those types of things. In general, if you're writing React code, there's a pretty -- Jest would be your default choice, even if it's not. I doubt it has more than 7D% saturation, but that's pretty good. There's still quite a few other options that people use... Ava, and a few diffe...
**Rachel White:** Yeah. So it this one just bundled with the new release?
**Alex Sexton:** Yes. Jest used to be bundled... It's just a new version, so there are new things; the highlights include immersive watch mode, better snapshot format... Snapshots are where you can say like "Once this is rendered with this data, the HTML should look exactly like X." It's kind of like whenever people do...
**Rachel White:** Cool. So it's kind of just like enforcing good practices on you anyway...
**Alex Sexton:** Yeah, and whenever you do a create-react-app it'll start you up with the test directory, with the test already written and imported and building and all that kind of stuff to where it's like really as soon as you write your thing it's a very fast and easy example on how to start writing tests for your ...
**Rachel White:** That's awesome.
**Alex Sexton:** One tough thing for writing web apps is if you wanna write tests in the same JavaScript that you write your components and stuff in, but if you're using Babel and Webpack and stuff in order to compile everything down, then you're starting to watch and compile your test directory... Which is cool, but t...
So there needs to be good configuration on whether you're kind of in a mode where tests run or get compiled, or whether it's important for them to get recompiled... And most of that's handled to where you're not doing unnecessary work as you're working, and then your tests can still be in new, cool, good ES6-y, Babel-y...
**Rachel White:** \[36:25\] Great.
**Mikeal Rogers:** So moving off of testing, because I think it's boring... \[laughter\] I see that one of the things that it also does is it adds a service worker automatically and has an offline caching strategy, which I think is great that service worker support and PWAs are landing in frameworks like this. I'm terr...
**Alex Sexton:** Sure...
**Mikeal Rogers:** ...because I've spent so much time fighting caches, it's just worrisome...
**Alex Sexton:** Yeah. I put a service worker early on the TXJS website in 2015 (I think) and if someone had hit it between 2 AM and 3 AM a week before the conference, then they would have been served that version of the website for the rest of their lives, unless they went in and cleared the service worker. \[laughter...
So there's definitely some danger to where you can get yourself in a place where you accidentally cache everything and there's no way to break out, and that can be unfortunate.
I haven't dug deep into their service worker implementation, but my gut is if you don't do anything weird it should be fine, and if you do something weird - sorry. My gut is that it's fine for normal stuff, and you'll probably need to turn it off for crazier stuff.
It's probably very baseline, very lazy in the sense that it isn't gonna do too much because it can't assume as much. But if you think about just like a caching strategy of "Have we seen this before?" \[unintelligible 00:38:10.23\] if we've seen it before, return the old one, and always go grab the new one. And if there...
**Mikeal Rogers:** Oh yeah, I hadn't really thought about that. React has a lot of understanding about the individual components, so it knows its rerenders need to happen when the backend updates. That's interesting.
**Alex Sexton:** Yeah, there's some nice synchronicity in some of that stuff, I think. It's not gonna be a silver bullet, but I think it's pretty good. Ember CLI doesn't have service worker, but by default whenever you do Ember serve a CSP (content security policy), which I think is a really cool default to have, just ...
So I really like these toolkit style CLI helper things doing things like solid generic defaults, that maybe aren't the best version of them, but maybe get people thinking about service workers or get people thinking about CSP. And it'll work in all the simple cases, as well.
**Mikeal Rogers:** Interesting... Very interesting.
**Alex Sexton:** You sound skeptical, but \[unintelligible 00:39:52.19\]
**Mikeal Rogers:** \[39:52\] No, I think just in general -- on the surface this looks like a boilerplate generator, and it's actually very much not just a boilerplate generator.
**Alex Sexton:** \[unintelligible 00:40:04.27\] It's like a living boilerplate generator, kind of...
**Mikeal Rogers:** Yeah. That's intense, though...
**Rachel White:** Well, it's a boilerplate generator but it keeps on helping. It just helps you continue on developing the app; it doesn't just run once and then you don't use it, right? Because it helps you put together all of the tools that you need for it.