2

I have downloaded a project that uses AMD. Everything works fine, but I wanted to test out how to concatenate all the compiled files into one output all.js file. I found something about --out parameter and followed the steps from here: https://stackoverflow.com/a/14302902/1252575

It didn't work for me, I'm getting an error:

The command "tsc --module AMD --out all.js "C:\TypeScriptWithRequireAMD_0.8.1\app\classes\Test.ts" "C:\TypeScriptWithRequireAMD_0.8.1\modules\require.d.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\classes\Greeter.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\AppConfig.ts" "C:\TypeScriptWithRequireAMD_0.8.1\app\AppMain.ts"" exited with code 1.

Here's how my file structure looks like:

Solution

Btw. I have a second question. Does --out parameter copy contents from lib catalog? If not, how to include them, too?

[edit 1.]

Oh, I forgot... It's a part of my .csproj file:

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptSourceMap>--module AMD</TypeScriptSourceMap>
</PropertyGroup>
<Target Name="BeforeBuild">
    <Message Text="Compiling TypeScript files" />
    <Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc $(TypeScriptSourceMap) --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

[edit 2.]

Here's my AppConfig.js:

require.config({
    baseUrl: '../',
    paths: {
        'jquery': 'lib/jquery-1.7.2',
        'underscore': 'lib/underscore',
        'backbone': 'lib/backbone',
        'console': 'lib/console',
        'greeter': 'app/classes/Greeter',
        'test': 'app/classes/Test'
    },
    shim: {
        jquery: {
            exports: '$'
        },
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: [
                "underscore", 
                "jquery"
            ],
            exports: "Backbone"
        },
        console: {
            exports: "console"
        },
        greeter: {
            deps: [
                "test"
            ]
        },
        test: {
            deps: [
                "greeter"
            ]
        }
    }
});
require([
    'jquery', 
    'underscore', 
    'backbone', 
    'console', 
    'app/AppMain', 
    'app/classes/Greeter', 
    'app/classes/Test'
], function ($, _, Backbone, console, main, greeter, test) {
    var appMain = new main.AppMain();
    appMain.run();
});
Community
  • 1
  • 1
Nickon
  • 9,652
  • 12
  • 64
  • 119
  • You don't need to pass all the files to the compiler when you use the `--out` flag. Pass it the top-level file and it will walk the dependencies and discover all of the other files. This isn't really compatible with AMD though - bundling is a different technique as all the scripts will be loaded because they are in one file. – Fenton Jan 24 '13 at 19:55
  • Related: [TypeScript Issue: Combine JavaScript Output into File Doesn't Appear to Work](https://typescript.codeplex.com/discussions/545710) – xmojmr Oct 26 '14 at 20:10

1 Answers1

4

By definition AMD scripts are loaded asynchronously by an AMD loader. In order to place them all in one file you'll need to run some analysis on the dependencies of each file so that they are inserted in the correct order. This is not something that --out does. You'll need to investigate something like the RequireJS optimizer instead.

ryan
  • 6,541
  • 5
  • 43
  • 68
  • According to the article, I installed `Node.Js` and tried to set up `Post-build event command line` like this `node r.js -o app/AppConfig.js`. I'm getting an error instantly `The command "node r.js -o app/AppConfig.js" exited with code 9009.` (no matter how I change `r.js`'s and `AppConfig.js`'s paths. I pasted `AppConfig.js`'s content in the main post). – Nickon Jan 25 '13 at 11:52
  • 1
    I suggest getting your build running from the a commandline script before you integrate it into your VS build step. However, see [What does “exited with code 9009” mean during this build?](http://stackoverflow.com/questions/1351830/what-does-exited-with-code-9009-mean-during-this-build) for potential solutions – ryan Jan 25 '13 at 13:18
  • This helped. From command line everything works fine. I did it in a batch file which is being run as `Post-build event...`. Thanks for help! Have a good day! – Nickon Jan 25 '13 at 13:28