Next.js Tutorial - Introducing Create Next App

Next.js is self-branded as the React framework for static pages, progressive web apps, mobile web apps, SEO-friendly pages, and — most especially — server-side rendering. It facilitates static exporting with just a line of command, ships with a CSS-in-JS library called Styled JSX, and includes features like code splitting, universal rendering, and hot reloading.

About three months ago, the Next.js team released a new starter boilerplate called Create Next App, and in this post, we will look into the new features that shipped with it.

Create Next App

Like the very popular Create React App, Create Next App is the easiest way to create a Next application, which is essentially a React app with server-side rendering.

It was actually initially a Next community project, but the team at Next felt that is was very important to be a major part of the first channels through which developers get to experience Next, so they got the maintainers to transfer ownership to them three months ago.

We worked with Segment to transfer ownership of the package, and are very grateful for their prior stewardship, especially by Fouad Matin.

Before this time, Next was already fully supporting the project, as they listed it in the official docs in the Next.js examples collection.

Create Next App was rebuilt from the ground up to perfectly represent the official starter pack qualities you would expect from Next. I personally think this was a great move, considering the amount of growth Next.js has seen in the past year. Now let’s look into some of the features you would see in create-next-app.

Interactive experience

How do you feel when you run the npx command to create a new Next project? This is a critical point in your onboarding process, especially as a new Next developer. In the new revamp, the Next team has ensured a great experience when you run the command below:

npx create-next-app myApp

Even without any arguments at all, you get a whole interactive experience where you are guided through every step to set up a new project. This can be the turning point that makes a new user into a returning one, and Next has covered that really well.

Zero dependencies

With the new Create Next App boilerplate, you can start a project in a second today because it has no dependencies. According to the Next blog, the size of the starter app was about 5.4MB on the unofficial version, and after all the optimizations have been done, more than 4.7MB has been shredded off the app. Now on install, the Create Next App size is 604kB.

Offline support

Amazing features like this one make a very convincing case for Next.js: this new version has offline support shipped with it. So if you’re working on your Next app and you go offline before starting a new project, it will both automatically detect that you are offline and also load up your project using your local package cache, which I think is super amazing and thoughtful.

New default project template

Create Next App uses a new project template that is carefully designed for a modern Next.js application. Initially, versions on the current Next.js and versions displayed in Create Next App did not match, but now that the project is officially owned by Next.js, the template will always be up to date with the latest Next version.

Support for examples

This is another great feature that I am excited about. Next.js has a lot of code examples that show how to get started completing various tasks with Next. With this new release of Create Next App, you can now start up an application as a kind of instance of an example in the Next collection.

This is really brilliantly thought out, as I can assume that these examples are useful guides for Next developers. All you have to do is add the example name in your startup command, so if you wanted to deploy the blog starter example, all you have to do in your terminal is run the command below:

npx create-next-app --example blog-starter

This will automatically scaffold a Next.js app for you in the form it is illustrated in the Next blog starter example.

Extensive testing

The new Create Next App is now part of the Next.js mono repository, so it is extensively tested with the very same integration test suite as the Next.js project itself. This ensures an ecosystem in sync, and everything just works in every release.

Getting started

To get started using Create Next App, open up your terminal and change directory to your chosen folder. Run the command below:

npx create-next-app newapp

newapp is the application name of your choosing. Remember to use all lowercase letters when naming to conform to the npm rule, so you don’t get errors like this:

Could not create a project called “newApp” because of npm naming restrictions:
* name can no longer contain capital letters

If you get no errors, your terminal will successfully install the latest versions of React and Next:

+ react@16.12.0
+ react-dom@16.12.0
+ next@9.2.1
added 820 packages from 371 contributors and audited 8383 packages in 67.97s
found 0 vulnerabilities

You can now change the directory to your new folder and run the dev server with:

npm run dev

Make sure you have admin rights on the machine you are using so you avoid access errors. Your app on localhost:3000 should look exactly like this:

Preview Of Our App Created With Create Next App

In your file manager, you will see that everything you need at the start has been created for you, from the pages folder that contains the index.js file to the component folder that has the nav file.

Conclusion

This post has shown you the new Next.js boilerplate called Create Next App, which is the officially supported Next.js starter application. We looked at all the new features one by one and also talked about how to get started using it. Tell me about your favorite features in the comments — happy hacking!

#reactjs #react-js #nextjs #web-development

Next.js Tutorial - Introducing Create Next App
1 Likes7.90 GEEK