Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/plugin/san/asset.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { readFileSync } from "fs";
import { extname } from "path";

export function makeAsset(name: string, file: string, assetPath: string, loadType: 'img' | 'script' | 'style') {
type LoaderType = 'img' | 'script' | 'style' | 'scriptLink' | 'styleLink';
export function makeAsset(name: string, file: string, assetPath: string, loadType: LoaderType, inlineCode = true) {
const conf = JSON.parse(readFileSync(`${assetPath}.md5`).toString());
const buf = readFileSync(assetPath);
let content: string = '';
if (loadType === 'img') {
const prefix = 'data:image/' + extname(assetPath).substring(1) + ';base64,';
content = `url(${prefix}${buf.toString('base64')})`;
} else {
content = JSON.stringify(buf.toString());
content = inlineCode ? JSON.stringify(buf.toString()) : '\'\'';
}
let type = 'img';
if (loadType === 'script') {
if (loadType === 'script' || loadType === 'scriptLink') {
type = 'js';
} else if (loadType === 'style') {
}
else if (loadType === 'style' || loadType === 'styleLink') {
type = 'css';
}
const tmpPath = assetPath.split('/');
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/san/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ async function analyzeTsFile(
case 'script':
await make(depPath);
return makeAsset(key, filePath, depPath, loaderType);
case 'styleLink':
await make(depPath);
return makeAsset(key, filePath, depPath, loaderType, false);
case 'scriptLink':
await make(depPath);
return makeAsset(key, filePath, depPath, loaderType, false);
case 'img':
await make(depPath);
return makeAsset(key, filePath, depPath, loaderType);
Expand Down