Files
morten-olsen.github.io/packages/markdown-loader/src/loader.ts
Morten Olsen 3f5e941446 feat: init
2022-12-07 00:08:14 +01:00

28 lines
511 B
TypeScript

import * as webpack from 'webpack';
import fm from 'front-matter';
function webpackLoader(
this: webpack.LoaderContext<{}>,
contents: string = ''
) {
const callback = this.async();
const run = async () => {
const { attributes, body } = fm(contents);
return {
attributes,
body,
};
};
run()
.then((content) => {
callback(null, `module.exports=${JSON.stringify(content)}`);
})
.catch((error) => {
callback(error);
});
}
export { webpackLoader };