Creating a new Vue-based meta-framework from scratch with live coding.
This talk has been presented at Vue.js London 2023, check out the latest edition of this JavaScript Conference.
Creating a new Vue-based meta-framework from scratch with live coding.
This talk has been presented at Vue.js London 2023, check out the latest edition of this JavaScript Conference.
NUXT is a framework built on top of Vue for creating web applications. It integrates best practices and allows for customization. NUXT provides a composable approach, enabling features to be included as needed, and supports server optimization for serverless environments. It's designed to enhance both developer experience and application performance.
Nitro is the new server architecture introduced in NUXT for building web applications. It is designed for the serverless world and edge computing, focusing on high efficiency and low resource utilization. Nitro allows developers to build and deploy applications rapidly with its streamlined framework.
Yes, NUXT is suitable for both server-rendered and static applications. It provides a rich set of features that enhance development even if server-side rendering is not required, such as automatic component imports, type safety, and comprehensive utilities for routing and state management.
NUXT 3 introduces significant changes including a transition from Vue 2 to Vue 3, updates to accommodate breaking changes in dependencies like PostCSS and Webpack, and the adoption of Vite over Webpack. It also features a shift from a singleton design pattern to a more modular and composable architecture.
Pinia is recommended as the state management solution for NUXT in the Vue 3 ecosystem, succeeding VueX. It offers a modern API, improved devtools integration, and is designed to work seamlessly with Vue 3's composition API.
Vite provides a fast development setup with features like instant server start and hot module replacement. Most NUXT developers choose Vite due to its efficiency and the active development of plugins within the ecosystem, enhancing the overall developer experience and application performance.
NUXT has collaborated with the Chrome team to improve web performance, particularly focusing on source mapping and script loading optimizations. These efforts aim to enhance debugging capabilities and ensure that best practices are applied in performance-critical areas.
NUXT supports legacy Vue 2 projects by allowing integration through its architecture, but transitioning to NUXT 3 with Vue 3 is recommended to take full advantage of the latest features and improvements in performance and scalability.
I am a member of the NUXT Core Team and have worked on projects like Magic Regex and Fontane. I helped build Nuxt, a framework for building web apps. We had an opportunity to rethink Nuxt and made significant changes. I want to show off Nitro, our new server, and demonstrate building Nuxt from scratch on top of it.
♪♪ Can move on. So I am a member of the NUXT Core Team, along with a number of other folk here. You've already heard from Lucy. Sebastien's going to speak in a moment, Alex as well. I'm also involved in a number of other projects like Magic Regex, Fontane, which makes your layout shift disappear if you have custom web fonts. Elk, which is a client for Mastodon, and I have a website as well. So feel free to check out any of those that may interest you.
This is my milieu. If you ever message me on Twitter or Discord or whatever, I'm probably sitting at this desk. One of my three cats is probably stopping me from working. I don't know if you've ever experienced that you have changed your priorities for the day based on what your pet is doing, because I 100% have. Like, there are times when I just cannot code because I actually have a cat here. So, the only thing I can do is read through GitHub issues or something like that, but sorry, I'm losing track.
So I helped build Nuxt, which is a framework for building web apps, and it's built on top of Vue, of course. Can I have a show of hands, who here has used Nuxt? Okay. Well, that will skip the next ten slides. So, recently, we had a – well, a couple of years ago. We had a significant opportunity to rethink what Nuxt was about, what we would do with it. I mean, the core philosophy, the idea that you would be able to get started with best practice built in and customize as you went, that was still there, but a lot of things were changing.
So, the move from Vue 2 to Vue 3, there was a breaking change in PostCSS, huge breaking changes in Webpack, at the same time, just as we were about to be all ready to go with Webpack, Evan, for goodness' sake, releases Vite. What was that about? But I'm a big fan, but lots of opportunities to rethink. And alongside those, we had philosophical changes, like moving from a sort of singleton approach where you sort of have everything defined centrally and available to you, to a composable approach where you can actually pull in features that you want and need and actually only those get included in the bundle, an idea that you can actually share logic between components, lots of stuff that really made us think about what we wanted Nuxt to do. And I'm not going to talk about a lot of that, actually. I'm going to focus on the next piece, which we did, which was actually, we think, the server and how it was that we could write a server that would be designed for the serverless world, for a world of edge computing, for a world where you don't necessarily have a Docker container just always on or a server that's just constantly ready to return responses, but maybe you might need to fire something up. We moved, by the way, in Nuxt 2 from 300 milliseconds called Start to five in Nuxt 3, and we moved from 52 meg of bundle size to three in server node modules in Nuxt 2 to Nuxt 3. So there are huge changes we made, but in particular what I want to talk about today is I want to show off Nitro, which is the name we've given to our new server. We've released it so anyone can build on it, and I want to show you what it would look like to build Nuxt from scratch in a few minutes. I want to really very much try and do this, and I apologize as possible I might go into my cue. I'm going to build Nuxt from scratch on top of Nitro, powered by lots and lots of tools, which I'll show you as we go. So here we go.
Let's dive in and build a framework powered by Nitro. We install Nitro and H3, a server framework like Express. We create a web server that returns a JSON response. We provide type safety on fetches across the app and make it performant. In NUX, the fetch call works isomorphically.
Let's dive in and build a framework powered by Nitro. So the first thing to do, this is an empty repository, basically, nothing much there. I'm going to install Nitro and H3, which is the server framework, a little bit like Express that we built on top of that, and start it.
Okay, so off the top of our head we have a web server that's running. Let's go to local host 3000, nothing there. Let's create a root, foo. Nitro and Nuxt, we have very much the idea that we want to be as minimal as possible and as intuitive as possible. So we can do something like this. And actually, if we hit that endpoint, I'll hit it actually just in this terminal here, which seems to be tiny. If I hit local host, what was that, foo, I get back a JSON response. I've just returned an object. We also as much as possible try and auto-import things, and we do that in a pattern that we started with Nuxt. We provide our own TS config to let your editor know, your IDE know what's available both in terms of, well, in terms of everything that we make available, whether that's type aliases, buffer paths, or making your editor know about what is auto-importable and what isn't. We can also do really cool things like this. Say I, let's see, duplicate this, as another, another handler. I can actually get type safety on fetches across my app, so it knows the routes that exist, it knows the return types for that data, and so I could do something like this and actually get full type safety, and it's quite fun. And what you'll also notice, might not, is that this dollar sign fetch thing, when used in a server context, actually doesn't hit the network layer, it just makes a function call. So it's as much as possible, we're trying to make it as performant as we can. In NUX, as it happens, when you run that fetch call, it will make a request to the server, so it works isomorphically.
We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career
Comments