TypeScript Loader for SystemJS

8.0.0 · abandoned · verified Sun Apr 19

plugin-typescript (current stable version 8.0.0) is a loader plugin for SystemJS that enables the direct `System.import` of TypeScript files. It transpiles `.ts` and `.tsx` files on the fly within the browser or Node.js environment when loaded by SystemJS. This package was the officially supported mechanism for transpiling TypeScript within JSPM 0.17.0 and later, providing immediate compilation and error reporting to the console. It supports TypeScript versions 2.0.0 and higher, with specific older versions (4.0.16 for TS 1.8.1, 2.x.x for TS 1.7.5 and below) required for compatibility. The package's release cadence was tied to the evolution of SystemJS and JSPM, focusing on browser-side transpilation and integration with SystemJS's module loading capabilities.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure SystemJS to use `plugin-typescript` for on-the-fly TypeScript transpilation, including mapping paths, setting it as the default transpiler, and applying `typescriptOptions` before importing a TypeScript file.

/*
  Ensure 'typescript' is installed as a peer dependency:
  npm install typescript@^2.4.0
  
  If using JSPM:
  jspm install ts

  Otherwise, configure SystemJS manually:
*/

SystemJS.config({
  packages: {
    "ts": {
      "main": "lib/plugin.js"
    },
    "typescript": {
      "main": "lib/typescript.js",
      "meta": {
        "lib/typescript.js": {
          "exports": "ts"
        }
      }
    },
    "app": {
      "defaultExtension": "ts"
    }
  },
  map: {
    // Adjust these paths to your installation location
    "ts": "./node_modules/plugin-typescript",
    "typescript": "./node_modules/typescript"
  },
  transpiler: 'ts',
  typescriptOptions: {
    module: "system",
    target: "es5",
    emitDecoratorMetadata: true,
    experimentalDecorators: true,
    noImplicitAny: false
  }
});

// Example app.ts content (assuming this file exists):
// export class MyClass { constructor(public name: string) {} }
// console.log(new MyClass('Hello from TypeScript!'));

System.import('app/main.ts') // Assuming main.ts is the entry point within the 'app' package
  .then(module => {
    console.log('Successfully loaded and transpiled main.ts', module);
    // You can now interact with exports from main.ts
  })
  .catch(err => console.error('Error loading TypeScript module:', err));

view raw JSON →