mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-08 01:46:28 +01:00
28 lines
511 B
TypeScript
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 };
|