npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-module-browser

v1.4.0

Published

Run typescript in browser with script[type="ts-module-browser"]

Downloads

9

Readme

Run examples

You can see the source code of the examples, or see it in action.

Also you can run the examples locally using the command:

$ yarn examples

Features

  • Transpiling typescript code from script[type="ts-module-browser"] through Service Worker
  • Ability to resolve packages through CDN
  • Loading local typescript files

Usage

The code in the browser is transpiled using a Service Worker. Due to Service Worker does not work in another origin (another domain, protocol or CDN), you need to install it locally:

/sw.js

// Load typescript (you can use any version you want)
self.importScripts("https://cdn.jsdelivr.net/npm/[email protected]/lib/typescriptServices.js");

// Load sw code from CDN
self.importScripts("https://cdn.jsdelivr.net/npm/ts-module-browser@latest/dist/sw.js");

/index.html:

<div id="container"></div>

<!-- Configure ts-module-browser instance -->
<script type="ts-module-browser-config">
  {
    "serviceWorkerPath": "/sw.js",
    "resolver": "skypack"
  }
</script>

<!-- Load ts-module-browser -->
<script src="https://cdn.jsdelivr.net/npm/ts-module-browser@latest"></script>

<!-- Write your code -->
<script type="ts-module-browser">
  import * as lodash from "lodash";
  import * as React from "react";
  import * as ReactDOM from "react-dom";
  import { Button } from "./some-local-component";

  function App() {
    return <Button>Hello world</Button>
  }

  ReactDOM.render(<App />, document.getElementById('container'));
</script>

Local usage

Not implemented yet.

yarn install ts-module-browser -D

/index.html:

<!-- Provide path to ts-module-browser location -->
<script src="node_modules/ts-module-browser/dist/module.js" data-tsmb-sw="node_modules/ts-module-browser/dist/sw.js" data-tsmb-resolver="local"></script>

Configuration

Service worker

serviceWorkerPath (default: undefined) Path to local sw.js (see usage)

Package resolvers

resolver (default: local)

All packages can be resolved using the following providers:

Work In Progress

Please don't use ts-module-browser in production.

  • [x] Compile typescript in browser
  • [x] Load packages from CDN
  • [x] Compile local files
  • [x] Compile from script[src]
  • [x] Load packages from local files
  • [ ] Load packages from /node_modules
  • [ ] Parse versions from package.json and lock
    • [x] package-lock.json
    • [x] yarn.lock v1
    • [x] yarn.lock v2
    • [ ] parse protocols

License

ts-module-browser is MIT licensed.