There's a quickstarter tutorial over at angular.io which uses typescript & systemjs. Now that I've got that miniapp running, how would I go about creating something deployable? I couldn't find any info about it whatsoever.
Do I need any extra tools, any additional settings in System.config?
(I know that I could use webpack & create a single bundle.js, but I'd like to use systemjs as it is used in the tutorial)
Could someone share their build process with this setup (Angular 2, TypeScript, systemjs)
You can use angular2-cli build command
https://github.com/angular/angular-cli/wiki/build#bundling
Update
This answer was submitted when angular2 was in rc4
I had tried it again on angular-cli beta21 and angular2 ^2.1.0 and it is working as expected
This answer requires initializing the app with angular-cli you can use
Or on an existing one
Update 08/06/2018
For angular 6 the syntax is different.
Check the documentation
You can build an Angular 2 (2.0.0-rc.1) project in Typescript using SystemJS with Gulp and SystemJS-Builder.
Below is a simplified version of how to build, bundle, and minify Tour of Heroes running 2.0.0-rc.1 (full source, live example).
gulpfile.js
system.config.js
The easiest way that I have found to bundle angular rc1 for systemJs is to use
gulp
andsystemjs-builder
:As pointed out in the comments, systemJs currently has issues when bundling components using
moduleId: module.id
https://github.com/angular/angular/issues/6131
The current recommendation (angular 2 rc1) seems to be to use explicit paths i.e.
moduleId: '/app/path/'
The key thing to understand at this level is that using the following configuration, you can't concat compiled JS files directly.
At the TypeScript compiler configuration:
In the HTML
As a matter of fact, these JS files will contain anonymous modules. An anonymous module is a JS file that uses
System.register
but without the module name as first parameter. This is what the typescript compiler generates by default when systemjs is configured as module manager.So to have all your modules into a single JS file, you need to leverage the
outFile
property within your TypeScript compiler configuration.You can use the following inside gulp to do that:
This could be combined with some other processing:
app.js
filevendor.js
file for third-party librariesboot.js
file to import the module that bootstrap the application. This file must be included at the end of the page (when all the page is loaded).index.html
to take into account these two filesThe following dependencies are used in the gulp tasks:
The following is a sample so it could be adapted.
Create
app.min.js
fileCreate
vendors.min.js
fileCreate
boot.min.js
fileThe
config.prod.js
simply contains the following:Update the
index.html
fileThe
index.html
looks like the following:Notice that the
System.import('boot');
must be done at the end of the body to wait for all your app components to be registered from theapp.min.js
file.I don't describe here the way to handle CSS and HTML minification.
Under Angular.io website, under Advanced/Deployment section, it is recommended that the simplest way to deploy is 'to copy the development environment to the server'.
go through the section under: Simplest deployment possible. The final project files are shown inside the code section. Note that it already sets up the code to load npm package files from the web (in stead of from the local npm_modules folder).
make sure it is running on your local computer (npm start). Then under the project folder, copy everything under '/src' sub-folder to the S3 bucket you've set up. You can use drag-and-drop to copy, during that process, you get the option to select the permission setting for the files, make sure to make them 'readable' to 'everyone'.
under bucket 'Properties' tab, look for 'Static website hosting' panel, check on 'Use this bucket to host website' option, and specify 'index.html' to both Index document and Error document.
click on the static website Endpoint, your project well be running!
Here's my MEA2N boilerplate for Angular 2: https://github.com/simonxca/mean2-boilerplate
It's a simple boilerplate that uses
tsc
to put things together. (Actually uses grunt-ts, which at its core is just thetsc
command.) No Wekpack, etc. necessary.Whether or not you use grunt, the idea is:
ts/
(example:public/ts/
)tsc
to mirror the directory structure of yourts/
folder into ajs/
folder and just reference files in thejs/
folder in yourindex.html
.To get grunt-ts to work (there should be an equivalent command for plain tsc, Gulp, etc.) , you have a property in your
tsconfig.json
called"outDir": "../js"
, and reference it in yourgruntfile.js
with:Then run
grunt ts
, which will take your app inpublic/ts/
and mirror it topublic/js/
.There. Super easy to understand. Not the best approach, but a good one to get started.