8000 GitHub - huozhi/devjar at v0.2.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

huozhi/devjar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

devjar

bundless runtime for your ESM JavaScript project in browser

image

Install

yarn add devjar

Usage

import { useLiveCode } from 'devjar'

function Playground() {
  const { ref, error, load } = useLiveCode({
    getModulePath(modPath) {
      return `https://cdn.skypack.dev/${modPath}`
    }
  })

  // logging failures
  if (error) {
    console.error(error)
  }

  // load code files and execute them as live code
  function run() {
    load({
      'index.js': `export default function Main() { return 'hello world' }`,
      './mod': `...` // other relative modules
    })
  }

  // Attach the ref to an iframe element for runtime of code execution
  return (
    <div>
      <button onClick={run}>run</h3>
      <iframe ref={ref} />
    </div>
  )
}

License

The MIT License (MIT).

0