How can I concatenate TypeScript files with Angular2 as Rails assets: precompile?

How can I put multiple TypeScript with Angular2 files into one JS file, for example Rails: precompile?

For example, in the tutorial on the official Angular2 page, you see four .ts files:

  • app.component.ts
  • boot.ts
  • hero.ts
  • hero-detail.component.ts

and when you look at the file app.component.ts, you will see the following part:

import {Hero} from './hero';
import {HeroDetailComponent} from './hero-detail.component';

It works great when you compile all .ts files separately, but I would like to concat () them into a single .js file so that there are fewer HTTP requests. I use gulp and tried gulp-concat, which did not work. browserify.

Would anyone help? Thanks in advance.

+4
3

, - Webpack. Webpack ts js, , <script>. , , Angular 2 ( ).

Angular 2 Webpack, Angular 2: https://github.com/pkozlowski-opensource/ng2-webpack-play

+4

, typescript ( ) 1.8 (1.7.5 - ). webpack, , .

+2

JSPM angular2. , JSPM, webpack browserfy. , JSPM, , angular2. selfExecutingBundle true JSPM js (, myApp.bundled.js), (myApp.bundled.min.js), script index.html.

<html>

<head>
    <title>Hello Angular World</title>
</head>
<body>
<div>
    <my-app>Loading...</my-app>
</div>
    <script src="/js/myApp.bundle.min.js"></script>
</body>

</html>
Hide result

, !

, HTTP/2 , , , .

0

Source: https://habr.com/ru/post/1621282/


All Articles