ngc之后汇总的commonjs

时间:2016-11-07 06:41:04

标签: angular rollupjs angular2-aot

我正在尝试以AoT方式编译我的角度2项目。但是我遇到了以下问题。

以下是源代码:

/// <reference path="../../typings/index.d.ts" />
import { Injectable, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { AppConfig, APP_CONFIG } from '../app.config';
import 'rxjs/add/operator/toPromise';
import * as bluebird from 'bluebird';

@Injectable()
export class EventsAPIService {
    private ECI_END_POINT: string;

    constructor(private http: Http, @Inject(APP_CONFIG) config: AppConfig) {
        this.ECI_END_POINT = config.ECI_END_POINT;
    }

    getEvents() {
        console.log(typeof bluebird, bluebird);
        return new bluebird((resolve: any, reject: any) => {
            this.http.get(`${this.ECI_END_POINT}/events/all`).toPromise().then((res: any) => {
                resolve(res.json().data);
            }).catch((err: Error) => {
                console.error(err);
                reject(err);
            });
        });
    }
}

rollup.config.js

import rollup      from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs    from 'rollup-plugin-commonjs';
import uglify      from 'rollup-plugin-uglify'
//paths are relative to the execution path
export default {
  entry: 'dist/src/main.js',
  dest: 'www/scripts/main.js', // output a single application bundle
  sourceMap: true,
  sourceMapFile: 'www/scripts/app.min.js.map',
  format: 'umd',
  moduleName: 'ECIAPP',
  plugins: [
    nodeResolve({jsnext: true, main: true, module: true}),
    commonjs({
      include: ['node_modules/rxjs/**']
    }),
    // uglify()
  ]
}

我能够通过ngc然后汇总编译项目,但是,汇总将bluebird模块转换为{...,默认:&#39;实际的bluebird&#39;},这样当调用getEvents时,它会抛出错误

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

allowSyntheticDefaultImports:在tsconfig.json中修复了它