Merge pull request #1109 from nonameShijian/PR-Branch

增加import css的支持(没有导出值)
This commit is contained in:
Spmario233 2024-03-20 21:40:50 +08:00 committed by GitHub
commit 5c95ad55e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 8 deletions

View File

@ -60,9 +60,9 @@ self.addEventListener('fetch', event => {
event.respondWith(rep);
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('.json')) {
if (request.url.endsWith('.json') || request.url.endsWith('css')) {
// @ts-ignore
if (!event.request.headers.get('origin')) return;
}
@ -164,6 +164,14 @@ self.addEventListener('fetch', event => {
}
js = codeList.join('\n');
// 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" }), {
status: 200,