Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created February 14, 2022 22:43
Show Gist options
  • Save DavidWells/d8710a3c8489c38ce8a00c4e5161a9e7 to your computer and use it in GitHub Desktop.
Save DavidWells/d8710a3c8489c38ce8a00c4e5161a9e7 to your computer and use it in GitHub Desktop.
“infamous triplet” set up to support TS, faux esm, esm and commonjs
// https://github.com/fastify/fastify/blob/224dc104260ad26f9baa0e46962f917963d41fe5/fastify.js#L711
// https://twitter.com/matteocollina/status/1493198259212406784
/**
* These export configurations enable JS and TS developers
* to consumer fastify in whatever way best suits their needs.
* Some examples of supported import syntax includes:
* - `const fastify = require('fastify')`
* - `const { fastify } = require('fastify')`
* - `import * as Fastify from 'fastify'`
* - `import { fastify, TSC_definition } from 'fastify'`
* - `import fastify from 'fastify'`
* - `import fastify, { TSC_definition } from 'fastify'`
*/
module.exports = fastify
module.exports.fastify = fastify
module.exports.default = fastify
{
"name": "fastify",
"version": "3.27.1",
"description": "Fast and low overhead web framework, for Node.js",
"main": "fastify.js",
"type": "commonjs",
"types": "fastify.d.ts",
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment