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
答案 0 :(得分:9)
您可以使用JSPM构建器执行此操作。 您可以将所有打字稿文件和bundlesfx捆绑到一个文件中,配置jspm.conf.js,如:
System.config({
defaultJSExtensions: true,
transpiler: "typescript",
typescriptOptions: {
"module": "amd",
"experimentalDecorators": true
},
...
packages: {
"app": {
"main": "index",
"defaultExtension": "ts",
"meta": {
"*.ts": {
"loader": "ts"
}
}
}
});
然后运行:
jspm bundle-sfx src/index dist/app.js
您可以在此处查看完整的workign示例:https://github.com/b091/ts-skeleton/
答案 1 :(得分:1)
我认为这个问题已经过时了。我刚刚使用JSPM 0.17.0-beta.31和plugin-typescript(https://github.com/frankwallis/plugin-typescript)尝试了这个,而“jspm bundle”确实为我预翻译了TypeScript。
“jspm bundle-sfx”现在是“jspm build”。因为最初接受的答案建议切换到现在不需要的bundle-sfx(build),我想澄清是否使用bundle或build的决定。我发现bundle对于加速开发更有用,而build可以生成一个带有更多优化的较小文件,因此你可能希望在开发期间使用bundle并在发布时使用bundle。请注意,如果在库上使用构建,则导入库的代码将无法共享其依赖项。