ngc 之后的 rollup 中的 commonjs
commonjs in rollup after ngc
我正在尝试以 AoT 方式编译我的 angular 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 然后 rollup 编译项目,但是,rollup 将 bluebird 模块转换为 {...,默认值:'actual bluebird'},因此在调用 getEvents 时会抛出错误。
有人可以帮忙吗?
allowSyntheticDefaultImports:tsconfig.json 中的 true 修复了它
我正在尝试以 AoT 方式编译我的 angular 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 然后 rollup 编译项目,但是,rollup 将 bluebird 模块转换为 {...,默认值:'actual bluebird'},因此在调用 getEvents 时会抛出错误。
有人可以帮忙吗?
allowSyntheticDefaultImports:tsconfig.json 中的 true 修复了它