Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSPM Bundle with TypeScript transpiler

I'm getting more into System.js and JSPM, where I've come to the point where I want to bundle my TypeScript source code into a JavaScript bundle.

Now I can bundle my generated JavaScript code with something like: jspm bundle some/source/path someDestFile.js

but then I need to pre-build all my TypeScript first into JavaScript and then bundle, finding myself left with all the compiled (and seperated) JS files. This is far from ideal!

I walked through the jspm docs here, but did not find a solution.

Just to be clear, I do not want to compile TypeScript in my browser, rather a precompiled bundle of solid JavaScript.

How do I do this?

P.S. I used the TypeScript transpiler installation as seen here

like image 905
Nicky Avatar asked Jul 28 '15 22:07

Nicky


1 Answers

You can do it with JSPM builder. You can bundle all typescript files and bundlesfx to one single file, configurating jspm.conf.js like that:

System.config({
    defaultJSExtensions: true,
    transpiler: "typescript",
    typescriptOptions: {
        "module": "amd",
        "experimentalDecorators": true
    },
    ...
    packages: {
        "app": {
            "main": "index",
            "defaultExtension": "ts",
            "meta": {
                "*.ts": {
                    "loader": "ts"
                }
            }
        }
});

and then run :

jspm bundle-sfx src/index dist/app.js

You can see full workign example in here: https://github.com/b091/ts-skeleton/

like image 143
b091 Avatar answered Oct 26 '22 23:10

b091