diff --git a/import-map.js b/importmap.js similarity index 87% rename from import-map.js rename to importmap.js index ceeca2a..457dd32 100644 --- a/import-map.js +++ b/importmap.js @@ -1,7 +1,7 @@ -// 生成缓存键,基于当前模块的URL const getCacheKey = () => { - const url = new URL(import.meta.url); - const basePath = url.pathname.replace('/import-map.js', ''); + // 基于import map文件的路径,而不是当前模块的URL + const url = new URL('./imports.json', window.location.href); + const basePath = url.pathname.replace('/imports.json', ''); return `importMap_${btoa(basePath).replace(/[+/=]/g, '_')}`; }; const getCurrentScriptData = () => { @@ -121,8 +121,17 @@ export const updateCacheInBackground = async () => { }; const runMain = async () => { - const { render } = await import('main'); - render(); + const sourceCode = ` + 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 () => { diff --git a/package.json b/package.json index 28613de..2f87463 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/native", - "version": "0.0.1", + "version": "0.0.4", "description": "", "main": "index.js", "files": [ diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..ae4ed4d --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# native + +esm 很有用,原生package.js 可以更好的支持。 \ No newline at end of file