Getting Started
Follow the instructions below to install TemplateDX in your app.
Install TemplateDX
Install with npm:
npm install @puzzlet/templatedx
or yarn:
yarn add @puzzlet/templatedx
Use TemplateDX
Loader (Recommended):
Use our webpack loader. Then import pre-parsed Template files directly.
import { transform } from '@puzzlet/templatedx';
import MyTemplate from './my-template.mdx';
...
const props = { name: 'Jim' };
const result = stringify(await transform(MyTemplate, props));
Node
import { parse, transform, stringify } from '@puzzlet/templatedx';
import type { ContentLoader } from '@puzzlet/templatedx';
import fs from 'fs';
// Define how to load imports.
const getFile: ContentLoader = (path: string) => {
const input = fs.readFileSync(path, 'utf-8');
return input;
}
const run = async (path: string) => {
const mdx = await getFile(path);
const parsed = await parse(mdx, `${basePathToMdxFile}`, getFile);
const props = { name: 'Jim' };
const result = stringify(await transform(parsed, myProps));
}