refactor: migrate lqip-loader to TS, fix typing for Webpack Loaders (#5779)

This commit is contained in:
Joshua Chen 2021-10-27 22:38:11 +08:00 committed by GitHub
parent ca5d70d7fb
commit 68c970175a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 254 additions and 265 deletions

View file

@ -8,18 +8,16 @@
import {truncate, linkify} from './blogUtils';
import {parseQuery} from 'loader-utils';
import {BlogMarkdownLoaderOptions} from './types';
import type {LoaderContext} from 'webpack';
// TODO temporary until Webpack5 export this type
// see https://github.com/webpack/webpack/issues/11630
interface Loader extends Function {
(this: any, source: string): string | Buffer | void | undefined;
}
const markdownLoader: Loader = function (source) {
export default function markdownLoader(
this: LoaderContext<BlogMarkdownLoaderOptions>,
source: string,
): void {
const filePath = this.resourcePath;
const fileString = source as string;
const fileString = source;
const callback = this.async();
const markdownLoaderOptions = this.getOptions() as BlogMarkdownLoaderOptions;
const markdownLoaderOptions = this.getOptions();
// Linkify blog posts
let finalContent = linkify({
@ -38,6 +36,4 @@ const markdownLoader: Loader = function (source) {
}
return callback && callback(null, finalContent);
};
export default markdownLoader;
}