Skip to content

Atrue/ts-browser-eval

Repository files navigation

ts-browser-eval

npm version install size license dependency status

Overview

Typescript compiler in the browser generating output chunks using rollup

Installation

$ npm install ts-browser-eval

Quick example:

// lazy import for code splitting (package size ~2.5 MB)
const compile = await import('ts-browser-eval');

const project = {
  'main.ts': 'import {ABC} from "./inner.ts";\nconsole.log(ABC.a)',
  'inner.ts': 'export enum ABC {a, b, c}',
};

const result = await compile(project, 'root/main.ts', {
  target: 'ES2017',
}, {
  format: 'iife',
  name: 'bundle',
});

console.log(result[0].code);
/*
(function () {
    'use strict';

    var ABC;
    (function (ABC) {
        ABC[ABC["a"] = 0] = "a";
        ABC[ABC["b"] = 1] = "b";
        ABC[ABC["c"] = 2] = "c";
    })(ABC || (ABC = {}));

    console.log(ABC.a);

}());
*/

Arguments

Return

Current issues

  • There're no type checks ☹