forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoaderFactory.ts
More file actions
21 lines (17 loc) · 812 Bytes
/
LoaderFactory.ts
File metadata and controls
21 lines (17 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { loader } from 'webpack';
import * as loaderUtils from 'loader-utils';
export interface IBaseLoaderOptions { }
export interface ILoaderResult {
[stringName: string]: string
}
export function loaderFactory<TOptions extends IBaseLoaderOptions>(
innerLoader: (locFilePath: string, content: string, options: TOptions) => ILoaderResult
): loader.Loader {
return function (this: loader.LoaderContext, content: string): string {
const options: TOptions = loaderUtils.getOptions(this) as TOptions;
const resultObject: ILoaderResult = innerLoader.call(this, this.resourcePath, content, options);
return JSON.stringify(resultObject);
}
}