@@ -2,8 +2,13 @@ import {LICENSE_BANNER} from '../constants';
22
33// There are no type definitions available for these imports.
44const rollup = require ( 'rollup' ) ;
5+ const rollupNodeResolutionPlugin = require ( 'rollup-plugin-node-resolve' ) ;
56
67const ROLLUP_GLOBALS = {
8+ // Import tslib rather than having TypeScript output its helpers multiple times.
9+ // See https://github.com/Microsoft/tslib
10+ 'tslib' : 'tslib' ,
11+
712 // Angular dependencies
813 '@angular/animations' : 'ng.animations' ,
914 '@angular/core' : 'ng.core' ,
@@ -50,10 +55,10 @@ export type BundleConfig = {
5055
5156/** Creates a rollup bundle of a specified JavaScript file.*/
5257export function createRollupBundle ( config : BundleConfig ) : Promise < any > {
53- const bundleOptions = {
58+ const bundleOptions : any = {
5459 context : 'this' ,
5560 external : Object . keys ( ROLLUP_GLOBALS ) ,
56- entry : config . entry
61+ entry : config . entry ,
5762 } ;
5863
5964 const writeOptions = {
@@ -67,5 +72,19 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
6772 sourceMap : true
6873 } ;
6974
75+ // When creating a UMD, we want to exclude tslib from the `external` and `globals` bundle options
76+ // so that it is inlined into the bundle.
77+ if ( config . format === 'umd' ) {
78+ bundleOptions . plugins = [ rollupNodeResolutionPlugin ( ) ] ;
79+
80+ // Clone ROLLUP_GLOBALS so we don't accidentally modify it.
81+ bundleOptions . globals = Object . assign ( { } , ROLLUP_GLOBALS ) ;
82+ delete bundleOptions . globals . tslib ;
83+
84+ const external = Object . keys ( ROLLUP_GLOBALS ) ;
85+ external . splice ( external . indexOf ( 'tslib' ) , 1 ) ;
86+ bundleOptions . external = external ;
87+ }
88+
7089 return rollup . rollup ( bundleOptions ) . then ( ( bundle : any ) => bundle . write ( writeOptions ) ) ;
7190}
0 commit comments