This is what the code that will get executed by next when loading our module. It's a function that can be asynchronous if need be, but it's recommended to keep it synchronous otherwise it can have some performance headache. It receives two arguments, the options the user provided match against the default options we defined here, and the next object we can use to interact with next. And here, we have some boilerplate code by default but we can safely get rid of it as we will come back later to it.
So, all right, that was a pretty dense section during our module anatomy, and well, this is really the most important thing to know about it. But just to recap what we learned. First of all, creating a module can be done with NextC in it. Modules come with new defaults and a bundler by Next. This is quite a new improvement since the developer experience of module. NextKit is a set of helpers to develop our module, and modules are tested by default, And finally, modules are defined using the new defined NextModule helper, also provided by NextKit.
So, as I said, just knowing the basic structure is already the most important part. But let's now try and do some few things with our module. Well, I'm a bit constrained with time today, so I only have time for one demo. So, I want to ask you, do you want me to show you how a module can provide stylesheets and helpers to your project, or do you want me to show you how a module can integrate with Next DevTools, which is this new tool that was released with Next earlier this year, that is pretty exciting. So, once again, please grab your phone and submit your vote, and well, I will do one of those two.
All right. Well, it's pretty even, but, well, we have like a majority for assets, so let's go with assets. And, maybe, in extra time, we'll try to do the next DevTools. We'll see. So, well, assets it is. And this is an interesting path to take, because it's maybe the most like straightforward way for you to provide to get value out of the modules you do. When we think about assets with a module, we think about the runtime directory, which is this directory, this right here that I ignored until now. Inside it you can provide any kind of assets you want the module to inject, whether it's a style sheet, a view component, composables, or even 3D modules, as we've seen before. It's treacherous. And, well, let's start and do something really basic to start with. We'll start by just, like, try to provide a style sheet. So, right now, my next application, it has a white background here. We'll create a style that's CSS-fine. We'll add some style to it. So, go, like, background.
Comments