Просмотр исходного кода

Fix for codepen not able to load plugins.

master
Palash Bansal 2 лет назад
Родитель
Сommit
9d9d1310bd
Аккаунт пользователя с таким Email не найден
1 измененных файлов: 2 добавлений и 0 удалений
  1. 2
    0
      examples/examples-utils/simple-code-preview.mjs

+ 2
- 0
examples/examples-utils/simple-code-preview.mjs Просмотреть файл

@@ -11,7 +11,9 @@ const exampleStyle = document.querySelector('#example-style')
const css = exampleStyle ? exampleStyle.textContent : ''
const importMap = document.querySelector('script[type="importmap"]')
const imports = importMap ? JSON.parse(importMap.textContent||'{}').imports||{} : {}
Object.keys(imports).forEach((k)=>(k === 'threepipe' || k.startsWith('@threepipe/')) ? (imports[k] = 'https://esm.sh/'+k) : '') // required for codepen to work. this is done because plugins refer to threepipe as esm
Object.entries(imports).forEach(([k,v])=>imports[k] = v.replace(/^\.\/\.\.\/\.\.\//, rootPath)) // ./../../ -> rootPath

function replaceImports(code) {
for (const [name, link] of Object.entries(imports)) code = code.replaceAll(` from '${name}'`, ` from '${link}'`)
return code

Загрузка…
Отмена
Сохранить