typescriptgulp-typescript

TypeScript compile import's into a single file


Inside my TypeScript application I use different import's for my own modules and node modules.

Every time i use "import" i want it to really import the module and compile it into a single js-file. Currently it looks like this:

main.ts:

import * as $ from "jquery";
$('body').css({'color': 'red'});

main.js (output)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var $ = require("jquery");
$('body').css({ 'color': 'red' });

But what i want is that instead of var $ = require("jquery"); it really imports jQuery into this file (but only if it wasn't imported earlier).


Solution

  • TypeScript compile import's into a single file

    You need a module bundler. e.g. Webpack or browserify.

    More

    Browser quickstart : https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html