diff --git a/src/plugin/san/asset.ts b/src/plugin/san/asset.ts index 127282e..6d310f6 100644 --- a/src/plugin/san/asset.ts +++ b/src/plugin/san/asset.ts @@ -1,7 +1,8 @@ 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 = ''; @@ -9,12 +10,13 @@ export function makeAsset(name: string, file: string, assetPath: string, loadTyp 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('/'); diff --git a/src/plugin/san/deps.ts b/src/plugin/san/deps.ts index 5ef704d..ad33622 100644 --- a/src/plugin/san/deps.ts +++ b/src/plugin/san/deps.ts @@ -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);