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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sanu
  • 529
  • 10
  • 30
  • 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 Apr 19 '16 at 09:03
  • You can use the gulp webpack module I suppose – bryan60 Oct 03 '20 at 20:00

3 Answers3

3

Replace

import {ActionsCollection} from "./actionsCollection";

with

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

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

Brant Olsen
  • 5,628
  • 5
  • 36
  • 53
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
basarat
  • 261,912
  • 58
  • 460
  • 511
  • 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 Apr 19 '16 at 07:25
-1

The tsconfig.json file may help you.

It has an "out" g.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 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 Apr 19 '16 at 07:23