我正在尝试使用汇总来捆绑使用 UMD 的 ng2 模块,但未按我的预期排除 ng2 依赖项:
汇总选项:
{
format: "umd",
moduleName: "mymodule",
dest: "dist/app.bundle.umd.js",
sourceMap: true
}
节点解析插件(rollup-plugin-node-resolve)
nodeResolve({
jsnext: true,
module: true,
skip: [
"@angular/common",
"@angular/compiler",
"@angular/compiler-cli",
"@angular/core",
"@angular/forms",
"@angular/http",
"@angular/platform-browser",
"@angular/platform-browser-dynamic",
"@angular/platform-server",
'rxjs'
]
}),
这个的输出是:
exports.AppModule = __decorate([
_angular_core.NgModule({
imports: [
_angular_platformBrowser.BrowserModule,
_angular_http.HttpModule
],
declarations: [AppComponent],
providers: [],
bootstrap: [AppComponent],
exports: [AppComponent]
})], exports.AppModule);
通过跳过 ng2 依赖项,Rollup 似乎创建了全局依赖项,其中_angular_core
和_angular_http
需要_angular_platformBrowser
全局定义。
我希望保留依赖项,但不希望保留全局依赖项。例如,这是tsc
在定位时产生的umd
:
"use strict";
var core_1 = require("@angular/core");
var app_component_1 = require("./app.component");
var platform_browser_1 = require("@angular/platform-browser");
var http_1 = require("@angular/http");
var AppModule = (function () {
function AppModule() {
}
return AppModule;
}());
AppModule = __decorate([
core_1.NgModule({
imports: [
platform_browser_1.BrowserModule,
http_1.HttpModule
],
declarations: [app_component_1.AppComponent],
providers: [],
bootstrap: [app_component_1.AppComponent],
exports: [app_component_1.AppComponent]
})
], AppModule);
exports.AppModule = AppModule;
您可以看到require
语句嵌入在 UMD 模块中(这是我想要实现的),而不是定义全局依赖项。
我可能没有正确使用汇总。我究竟做错了什么?
也许汇总是错误的工具,有人可以推荐更好的工具吗?我正在使用 gulp 进行构建。