-
Notifications
You must be signed in to change notification settings - Fork 3
/
asset-loader.ts
35 lines (29 loc) · 894 Bytes
/
asset-loader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { PluginBuild } from "./deps.ts";
import { Buffer } from "https://deno.land/[email protected]/node/buffer.ts";
export interface LoaderOptions {
extension?: RegExp;
minify?: boolean;
transform?: (input: string, filename?: string) => string;
}
export abstract class AssetLoader {
abstract extension: RegExp;
minify = false;
sourcemap = false;
transform = (input: string, _filename?: string) => input;
constructor(
public build: PluginBuild,
public options: LoaderOptions,
public specifier = "lit",
public minifier?: unknown,
) {}
sanitize(input: string): string {
return input.replace(/(\$\{|`)/g, "\\$1");
}
toSourceMapURL(map: string) {
return "\n" +
`//# sourceMappingURL=data:application/json;base64,${
Buffer.from(map).toString("base64")
}`;
}
abstract load(input: string, file: string): Promise<string>;
}