From 8920862d5897eb5d87fff9e7008f8201b2260c09 Mon Sep 17 00:00:00 2001 From: wclimb <875246904@qq.com> Date: Wed, 12 Oct 2022 16:45:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20import=E5=86=85=E8=81=94=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=8E=9F=E5=A7=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/san/asset.ts | 9 +++++---- src/plugin/san/deps.ts | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugin/san/asset.ts b/src/plugin/san/asset.ts index 127282e..9a2a27e 100644 --- a/src/plugin/san/asset.ts +++ b/src/plugin/san/asset.ts @@ -1,7 +1,7 @@ import { readFileSync } from "fs"; import { extname } from "path"; -export function makeAsset(name: string, file: string, assetPath: string, loadType: 'img' | 'script' | 'style') { +export function makeAsset(name: string, file: string, assetPath: string, loadType: 'img' | 'script' | 'style' | 'scriptLink' | 'styleLink', inlineCode = true) { const conf = JSON.parse(readFileSync(`${assetPath}.md5`).toString()); const buf = readFileSync(assetPath); let content: string = ''; @@ -9,12 +9,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); From 434ae3457e0dca93d71832d5236694a95290895e Mon Sep 17 00:00:00 2001 From: wclimb <875246904@qq.com> Date: Wed, 12 Oct 2022 16:48:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20import=E5=86=85=E8=81=94=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=8E=9F=E5=A7=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8F=AF=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/san/asset.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugin/san/asset.ts b/src/plugin/san/asset.ts index 9a2a27e..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' | 'scriptLink' | 'styleLink', inlineCode = true) { +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 = '';