8

I have two classes in different files:

export class ActionsCollection{
    constructor(greeting :string){
        this.greet(greeting);
    }

    public greet(greeting :string) {
        return "<h1>"+greeting+"</h1>";
    }
}

And

import {ActionsCollection} from "./actionsCollection";

class Greeter extends ActionsCollection{
    constructor(public greeting: string) {
        super(greeting);
    }
}

alert(new Greeter("Hello, world!"));

Greeter is generated in such a file in which there is require line ("./ actionsCollection"). But I want to make sure that all the files (*.ts) generates in only one file main.js, it does not need require. Can I do that? And if so, how?

PS: At the same time, for the assembly, you can use standard WebStorm tools and Gulp. And nothing more, besides modules for Gulp.

2
  • If you use "files" in tsconfig and you write all files in the correct order it will compile everything in a single file (of course having the "out" directive in your tsconfig.json). The problem with this approach is that you cannot forget any file in the list. Using ES6 imports should be enough if you indicate your entry point though
    – iberbeu
    Commented Apr 19, 2016 at 9:03
  • You can use the gulp webpack module I suppose
    – bryan60
    Commented Oct 3, 2020 at 20:00

3 Answers 3

4

Replace

import {ActionsCollection} from "./actionsCollection";

with

/// <reference path="./actionsCollection.ts" />.

See Triple Slashes for more info on using the triple slash imports.

0

But I want to make sure that all the files (*.ts) generates in only one file main.js, it does not need require. Can I do that? And if so, how

You can use it quite easily with Webpack: https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

This has the additional advantage that you can use all the wonderful libraries on npm seamlessly.

1
  • 2
    Yes, you are right, but I can only use the Gulp, due restrictions in the draft. I said about this in my question
    – sanu
    Commented Apr 19, 2016 at 7:25
-1

The tsconfig.json file may help you.

It has an "out" g.

1
  • I do this: "files": [ "core.ts", "sys.ts", "types.ts", "scanner.ts", "parser.ts", "utilities.ts", "binder.ts", "checker.ts", "emitter.ts", "program.ts", "commandLineParser.ts", "tsc.ts", "diagnosticInformationMap.generated.ts" ] And this not work
    – sanu
    Commented Apr 19, 2016 at 7:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.