增加import css的支持(没有导出值)

This commit is contained in:
nonameShijian 2024-03-19 20:48:12 +08:00
parent 608b1e700d
commit 43e1e49eb0
1 changed files with 16 additions and 8 deletions

View File

@ -60,9 +60,9 @@ self.addEventListener('fetch', event => {
event.respondWith(rep); event.respondWith(rep);
return; return;
} }
if (!['.ts', '.json', '.vue'].some(ext => request.url.endsWith(ext))) return; if (!['.ts', '.json', '.vue', 'css'].some(ext => request.url.endsWith(ext))) return;
if (request.url.endsWith('.d.ts')) return; if (request.url.endsWith('.d.ts')) return;
if (request.url.endsWith('.json')) { if (request.url.endsWith('.json') || request.url.endsWith('css')) {
// @ts-ignore // @ts-ignore
if (!event.request.headers.get('origin')) return; if (!event.request.headers.get('origin')) return;
} }
@ -164,6 +164,14 @@ self.addEventListener('fetch', event => {
} }
js = codeList.join('\n'); js = codeList.join('\n');
// console.log(js); // console.log(js);
} else if (request.url.endsWith('css')) {
const id = Date.now().toString();
const scopeId = `data-v-${ id }`;
js = `const style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.setAttribute('data-vue-dev-id', \`${ scopeId }\`);
style.textContent = ${ JSON.stringify(text) };
document.head.appendChild(style);`;
} }
const rep = new Response(new Blob([js], { type: "text/javascript" }), { const rep = new Response(new Blob([js], { type: "text/javascript" }), {
status: 200, status: 200,