title: Typescript compilation depends on order of files
body: <p>I'm developing typescript library and I want to use it in my web application. </p>
  
  <p>I would like to compile all library files into single library.js file.</p>
  
  <p>I tried to use ts compiler with tsconfig.json file as well as compiling with gulp task but I have issues with class order in output file in both cases.</p>
  
  <p>Also generated code has lots of IIFE </p>
  
  <pre><code>var MyLibrary;
  (function (MyLibrary) {
  .....
  })(MyLibrary || (MyLibrary = {}));
  </code></pre>
  
  <p>I guess it should be there just once, not for each class, right?</p>
  
  <p>My tsconfig.json:</p>
  
  <pre><code>{
    "compilerOptions": {
      "module": "amd",
      "noImplicitAny": false,
      "removeComments": true,
      "preserveConstEnums": true,
      "outFile": "dist/js/floor-map-designer.js",
      "sourceMap": true
    },
    "exclude": [
      "node_modules",
      "dist",
      "src/app.ts"
    ]
  }
  </code></pre>
  
  <p>and gulp tasks config:</p>
  
  <pre><code>var tsProject = ts.createProject({
      declarationFiles: true,
      noExternalResolve: false,
      module: 'AMD',
      removeComments: true,
      outFile: "my-library.js",
      exclude: ["app.ts", "config.ts"]
  });
  
  var paths = {
      npm: './node_modules/',
      lib: "./lib/vendor/",
      tsSource: ['./src/MyLibrary/**/*.ts', "./lib/typings/tsd.d.ts"],
      tsOutput: "./dist/js/",
      tsDef: "./lib/typings/"
  };
  
  gulp.task('ts-compile', function () {
      var tsResult = gulp.src(paths.tsSource)
                      .pipe(ts(tsProject));
  
      return merge([
          tsResult.dts.pipe(gulp.dest(paths.tsDef)),
          tsResult.js.pipe(gulp.dest(paths.tsOutput))
      ]);
  });
  </code></pre>
  
  <p>I remember last time I used TypeScript I used to create autogenerated reference file with lots of </p>
  
  <pre><code>/// &lt;reference path="...." 
  </code></pre>
  
  <p>and add 
  <code>/// &lt;ts:autoRef="referencesFile.ts"&gt;</code> to all .ts files.  </p>
  
  <p>But I have noticed TS compiler should not depend on file order anymore and my IDE doesn't require it anymore, so I would like to avoid it if possible.</p>
  
  <p>I also noticed using --out option is considered bad (at least according to this website: <a href="https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md" rel="nofollow">https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md</a>) but how to replace it? </p>
  
  <p>I'm using Typescript 1.7. </p>