This commit is contained in:
熊潇 2025-07-25 23:27:58 +08:00
parent 0bfa055056
commit 1d0df822ce
3 changed files with 18 additions and 6 deletions

View File

@ -1,7 +1,7 @@
// 生成缓存键基于当前模块的URL
const getCacheKey = () => { const getCacheKey = () => {
const url = new URL(import.meta.url); // 基于import map文件的路径而不是当前模块的URL
const basePath = url.pathname.replace('/import-map.js', ''); const url = new URL('./imports.json', window.location.href);
const basePath = url.pathname.replace('/imports.json', '');
return `importMap_${btoa(basePath).replace(/[+/=]/g, '_')}`; return `importMap_${btoa(basePath).replace(/[+/=]/g, '_')}`;
}; };
const getCurrentScriptData = () => { const getCurrentScriptData = () => {
@ -121,8 +121,17 @@ export const updateCacheInBackground = async () => {
}; };
const runMain = async () => { const runMain = async () => {
const { render } = await import('main'); const sourceCode = `
render(); import { render } from 'main';
render();`;
try {
const script = document.createElement('script');
script.type = 'module';
script.textContent = sourceCode;
document.body.appendChild(script);
} catch (error) {
console.error('Error executing source code:', error);
}
}; };
const main = async () => { const main = async () => {

View File

@ -1,6 +1,6 @@
{ {
"name": "@kevisual/native", "name": "@kevisual/native",
"version": "0.0.1", "version": "0.0.4",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"files": [ "files": [

3
readme.md Normal file
View File

@ -0,0 +1,3 @@
# native
esm 很有用原生package.js 可以更好的支持。