🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket
Sign inDemoInstall
Socket

@jackdbd/fastify-webc

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jackdbd/fastify-webc

Fastify plugin to render WebC templates and components.

0.1.0
latest
npm
Version published
Weekly downloads
4
-86.21%
Maintainers
1
Weekly downloads
 
Created
Source

@jackdbd/fastify-webc

npm version install size CodeCov badge Socket Badge

Fastify plugin to render WebC templates and components.

Installation

npm install @jackdbd/fastify-webc

Configuration

Register this plugin by telling it where to find your WebC components and templates.

This plugin decorates FastifyReply with a render method. This method takes two arguments: a WebC template and an optional data object.

import webc from '@jackdbd/fastify-webc'

fastify.register(webc, {
  components: ['src/components/**/*.webc'],
  templates: [path.join(__dirname, 'templates')]
})

fastify.get('/demo', function (request, reply) {
  const data = { foo: 'bar' }
  return reply.render('demo.webc', data)
})

TypeScript

To ensure TypeScript recognizes the render method as part of the FastifyReply object, you must use declaration merging to extend the FastifyReply interface.

declare module 'fastify' {
  interface FastifyReply {
    render(template: string, data?: Record<string, any>): Promise<void>
  }
}

Tips

You can access the WebC instance from your WebC template/component using this.webc.

<code>this.webc</code>
<pre @text="JSON.stringify(this.webc, null, 2)"></pre>

You can access the data available to the WebC template/component using this.$data.

<code>this.$data</code>
<pre @text="JSON.stringify(this.$data, null, 2)"></pre>

Dependencies

PackageVersion
@11ty/webc^0.11.4
fastify-plugin^5.0.1

⚠️ Peer Dependencies

This package defines 1 peer dependency.

PeerVersion range
fastify>=5.0.0

References

License

© 2024 - 2025 Giacomo Debidda // MIT License

Keywords

fastify

FAQs

Package last updated on 25 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts