DEV Community

Zppqr
Zppqr

Posted on Edited on

๐Ÿง  Write JSX/TSX in HTML Instantly with MLPL: No Build Tools Needed!

MLPL (Multi-Language Parsing Layer) lets you write React components using <script type="text/jsx"> and <script type="text/tsx"> directly in plain HTMLโ€”no bundlers, no setup, no build step.

Whether you're prototyping, teaching React, or enhancing legacy apps with modern components, MLPL lets you write and run modern React code instantly in the browser.


โšก Why MLPL?

๐Ÿ’ก MLPL is a drop-in JavaScript library that:

  • Transforms and renders JSX/TSX at runtime
  • Provides full support for TypeScript
  • Enables state, hooks, and modern React APIs
  • Comes with dev tools, inspection panel, and error boundaries

๐Ÿ›  Installation

NPM (for frameworks or bundlers):

npm install mlpl
Enter fullscreen mode Exit fullscreen mode

Or load via CDN:

<script src="https://unpkg.com/mlpl@latest/dist/index.js"></script>
Enter fullscreen mode Exit fullscreen mode

โš™๏ธ Basic Usage

<!DOCTYPE html>
<html>
  <head>
    <title>MLPL Demo</title>
  </head>
  <body>
    <div id="root"></div>

    <!-- Load React -->
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>

    <!-- Load MLPL -->
    <script src="https://unpkg.com/mlpl@latest/dist/index.js"></script>

    <!-- JSX Component -->
    <script type="text/jsx" data-target="#root">
      function HelloWorld({ name = "World" }) {
        const [count, setCount] = useState(0);
        return (
          <div>
            <h1>Hello, {name}!</h1>
            <p>Count: {count}</p>
            <button onClick={() => setCount(count + 1)}>Increment</button>
          </div>
        );
      }
      const Component = HelloWorld;
    </script>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

Thatโ€™s it. React component rendered into #rootโ€”with full interactivity.


โœจ TypeScript Example (TSX)

<script type="text/tsx" data-target="#app">
  interface User {
    id: number;
    name: string;
    email: string;
  }

  function Profile({ user }: { user: User }) {
    const [editing, setEditing] = useState(false);
    return (
      <div>
        <h2>{user.name}</h2>
        <p>{user.email}</p>
        <button onClick={() => setEditing(!editing)}>
          {editing ? 'Save' : 'Edit'}
        </button>
      </div>
    );
  }

  const Component = () => (
    <Profile user={{ id: 1, name: "Jane Doe", email: "jane@example.com" }} />
  );
</script>
Enter fullscreen mode Exit fullscreen mode

MLPL fully supports TypeScript types, inference, and errors at runtime.


๐Ÿงช Power Features

๐Ÿ”„ Runtime Execution

You can even inject and run JSX/TSX on the fly:

import { MLPL } from 'mlpl';

const mlpl = new MLPL({
  autoRender: true,
  enableDevMode: true
});

await mlpl.execute(`
  function Dynamic() {
    return <div>Hello from dynamic code!</div>;
  }
  const Component = Dynamic;
`);
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Component Registration

mlpl.registerComponent('MyButton', ({ children }) => (
  <button>{children}</button>
));
Enter fullscreen mode Exit fullscreen mode

๐Ÿ–ฅ Dev Tools

Press Ctrl + Shift + M to open the dev panel with:

  • Component tree viewer
  • Error logs
  • Render performance
  • Registered components

Or access it in the console:

window.__MLPL_DEV__.getComponents();
window.__MLPL_DEV__.toggleDevPanel();
Enter fullscreen mode Exit fullscreen mode

๐Ÿ›ก Error Handling

MLPL wraps all components in error boundaries and logs:

  • JSX/TSX compile errors
  • TypeScript type issues
  • Runtime crashes

๐Ÿ“Š Use Cases

โœ… Prototyping: Spin up a quick React idea with no build config
๐Ÿ“š Education: Embed live React examples in articles or docs
โš™๏ธ Legacy sites: Enhance HTML pages with React interactivity
๐Ÿงช Testing: Try new patterns without scaffolding a project


๐Ÿงฏ Security Notice

MLPL executes code in the browser. Use only trusted sources and avoid running unverified user input.


๐Ÿ‘จโ€๐Ÿ’ป Contribute

MLPL is open source and MIT licensed. Contributions are welcome!


๐Ÿงต Final Thoughts

MLPL bridges the gap between raw HTML and modern JSX/TSX. Whether you're teaching, demoing, or hacking together an idea, this library gives you the power of React with the simplicity of script tags.


๐Ÿ”— npm: mlpl
๐Ÿ”— GitHub: mlpl


โœจ If you enjoyed this article, consider giving MLPL a โญ on GitHub and dropping your thoughts below!

Top comments (0)