如何节俭地使用 Angular 2 和 webpack?
How to make thrift to work with Angular 2 and webpack?
从一个简单的 Angular 2 + Webpack 工作项目,我试图通过实施 Thrift 的教程来集成 Apache Thrift。我达到了除了浏览器找不到 Thrift 模块之外一切正常的地步:
Uncaught ReferenceError: Thrift is not defined
thrift 生成的文件 tutorial_types.js
在尝试访问 thrift 模块时引发错误:
InvalidOperation = function(args) {
this.whatOp = null;
this.why = null;
if (args) {
if (args.whatOp !== undefined && args.whatOp !== null) {
this.whatOp = args.whatOp;
}
if (args.why !== undefined && args.why !== null) {
this.why = args.why;
}
}
};
Thrift.inherits(InvalidOperation, Thrift.TException);
Angular 加载应用程序,加载尝试加载 Thrift 并失败的生成文件。
项目可在此处获得:https://github.com/osechet/angular-thrift
测试,运行:
git clone https://github.com/osechet/angular-thrift
cd angular-thrift
npm install
npm gen.thrift
npm start
然后在浏览器中打开http://localhost:8080/。
我检查了Webpack创建的文件,并捆绑了thrift模块。我错过了什么?
感谢@JoeClay 的评论,我找到了问题所在。 Thrift 提供的 Javascript 库不导出任何模块,因此没有被 Webpack 正确捆绑。
我更改了我的项目以使用 Thrift (thrift/lib/nodejs/lib/thrift/browser.js
) 提供的 nodejs 库的浏览器模块。这样做,我已经能够使整个应用程序正常工作。
从一个简单的 Angular 2 + Webpack 工作项目,我试图通过实施 Thrift 的教程来集成 Apache Thrift。我达到了除了浏览器找不到 Thrift 模块之外一切正常的地步:
Uncaught ReferenceError: Thrift is not defined
thrift 生成的文件 tutorial_types.js
在尝试访问 thrift 模块时引发错误:
InvalidOperation = function(args) {
this.whatOp = null;
this.why = null;
if (args) {
if (args.whatOp !== undefined && args.whatOp !== null) {
this.whatOp = args.whatOp;
}
if (args.why !== undefined && args.why !== null) {
this.why = args.why;
}
}
};
Thrift.inherits(InvalidOperation, Thrift.TException);
Angular 加载应用程序,加载尝试加载 Thrift 并失败的生成文件。
项目可在此处获得:https://github.com/osechet/angular-thrift
测试,运行:
git clone https://github.com/osechet/angular-thrift
cd angular-thrift
npm install
npm gen.thrift
npm start
然后在浏览器中打开http://localhost:8080/。
我检查了Webpack创建的文件,并捆绑了thrift模块。我错过了什么?
感谢@JoeClay 的评论,我找到了问题所在。 Thrift 提供的 Javascript 库不导出任何模块,因此没有被 Webpack 正确捆绑。
我更改了我的项目以使用 Thrift (thrift/lib/nodejs/lib/thrift/browser.js
) 提供的 nodejs 库的浏览器模块。这样做,我已经能够使整个应用程序正常工作。