Преглед изворни кода

Fix for codepen not able to load plugins.

master
Palash Bansal пре 2 година
родитељ
комит
9d9d1310bd
No account linked to committer's email address
1 измењених фајлова са 2 додато и 0 уклоњено
  1. 2
    0
      examples/examples-utils/simple-code-preview.mjs

+ 2
- 0
examples/examples-utils/simple-code-preview.mjs Прегледај датотеку

const css = exampleStyle ? exampleStyle.textContent : '' const css = exampleStyle ? exampleStyle.textContent : ''
const importMap = document.querySelector('script[type="importmap"]') const importMap = document.querySelector('script[type="importmap"]')
const imports = importMap ? JSON.parse(importMap.textContent||'{}').imports||{} : {} 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 Object.entries(imports).forEach(([k,v])=>imports[k] = v.replace(/^\.\/\.\.\/\.\.\//, rootPath)) // ./../../ -> rootPath

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

Loading…
Откажи
Сачувај