A NestJS module to use EdgeJS templating language.
Request Feature
·
Report Bug
·
Request Modification
Table of Contents
The Edge module is based on the idea of using EdgeJS templating within a NestJS application. The main problem with using EdgeJS within Nest comes from the resolution of Edge in ESM. In this case, we're using a workaround to make use of the dynamic import.
This module is built dynamically, allowing you to define a customized configuration for each use case. We recommend that you create a dedicated custom configuration file by importing a configuration object such as edge.config.ts
.
We welcome contributions and improvements to this module. Don't hesitate to submit features and improvements ;)
For now the package isn't published to npm, but you can install it from the GitHub registry and can be installed in any project.
-
You need to create a
.npmrc
file at the root of your project with the following content:@lithium-apps:registry=https://npm.pkg.github.com
-
For the login process you need to set a personal access token with the
read:packages
scope. Then you can login to the GitHub registry with the following command:pnpm login --registry=https://npm.pkg.github.com --scope=@lithium-apps
-
You can now install the packages using the following command:
pnpm install @lithium-apps/edge
-
Create a configuration file for Edge.JS :
import { EdgeConfig } from '@lithium-apps/edge'; export const edgeConfig: EdgeConfig = { mount: { // Define all the named disk mount points views: join(__dirname, 'path_to_views'), }, // You can set plugins here plugins: [], // You can set globals here globals: {}, // Check other options in the EdgeConfig interface };
-
Import the
EdgeModule
in your application module:import { Module } from '@nestjs/common'; import { EdgeModule } from '@lithium-apps/edge'; import { edgeConfig } from './edge.config'; import { MyController } from './my.controller'; @Module({ imports: [ EdgeModule.forFeature(edgeConfig) ], controllers: [MyController] }) export class MyModule {}
-
Use the
@Render()
decorator in your controller:import { Controller, Get } from '@nestjs/common'; import { EdgeService } from '@lithium-apps/edge'; @Controller() export class MyController { @Get('/') @Render('views::welcome') // Specify the view to render async getHello() { return { name: 'Kylian' }; // Data to pass to the view } }
Here are a few useful links to help you use the module or learn more about it! Don't thank us, you'll sleep better :)
- Edge.JS documentation: The official documentation of the Edge.JS templating language.
- NestJS documentation: The official documentation of the NestJS framework.
- Kylian Mallet - @Kylian-Mallet - kylian.mallet@sklav.group