现在将非beta Angular 2打包为@angular时,angular2-polyfills在哪里? [英] Where is angular2-polyfills now that non-beta Angular 2 is packaged as @angular?
问题描述
现在Angular2已超出beta版(2.0.0-RC.0和RC.1于昨天/2016年5月3日发布),所有Angular 2都打包为可在新的@angular名称空间下与NPM一起使用.您已经在
Now that Angular2 is out of beta (2.0.0-RC.0 and RC.1 came out yesterday/May 3, 2016), all of Angular 2 is packaged for use with NPM under the new @angular namespace. A lot of packages have been moved and must be individually installed now, as you can see in the Angular2 CHANGELOG.
但是CHANGELOG无法解决的一件事是如何找到以前可用的angular2-polyfills
捆绑包.
But one thing that the CHANGELOG doesn't address is how to find the angular2-polyfills
bundle that was available previously.
我的beta代码在其TypeScript文件之一中称其为
My beta code called this in one of its TypeScript files:
import 'angular2/bundles/angular2-polyfills';
我现在需要怎么做才能在新的程序包布局中获得相同的功能?
What do I need to do now to get that same functionality with the new package layout?
这是ventdor.ts
文件,用于导入polyfill,以便Webpack可以包含它:
Here is the ventdor.ts
file that used to import the polyfills so that it could be included by webpack:
require('./css/bootstrap.css');
require('./css/main.css');
import 'angular2/bundles/angular2-polyfills'; // THIS NO LONGER WORKS
require('./lib/bootstrap/bootstrap.js');
当我使用webpack构建应用程序时,缺少polyfills会导致类似以下的错误:
The lack of the polyfills causes errors like the following when I build my application with webpack:
ERROR in /Users/mfo/Projects/PennMutual/angular2-oauth2/node_modules/@angular/core/src/facade/async.d.ts
(28,45): error TS2304: Cannot find name 'Promise'.
ERROR in /Users/mfo/Projects/PennMutual/angular2-oauth2/node_modules/@angular/core/src/facade/lang.d.ts
(4,17): error TS2304: Cannot find name 'Map'.
ERROR in /Users/mfo/Projects/PennMutual/angular2-oauth2/node_modules/@angular/core/src/facade/lang.d.ts
(5,17): error TS2304: Cannot find name 'Set'.
推荐答案
正如Thierry Templier在回答中说的那样,问题在于,由于angular2-polyfills.js
软件包不存在,必须引入zone.js
和reflect-metadata
.不再可用.
As Thierry Templier said in his answer, the issue is that zone.js
and reflect-metadata
have to be brought in now that the angular2-polyfills.js
bundle is no longer available.
要恢复功能,您需要直接导入它们,而不要依赖旧的polyfills代码.
To get the functionality back, you need to import them directly instead of relying on the old polyfills code.
//import 'angular2/bundles/angular2-polyfills'; // no longer available
import 'reflect-metadata';
require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone'); // for development only - not needed for prod deployment
reflect-metadata
软件包已经具有TypeScript的内置类型,因此您可以使用import
.但是,Zone.js并非如此,因此您需要依靠require()
来使Webpack拾取它并将其包含在您的捆绑软件中.
The reflect-metadata
package already has built-in typings for TypeScript, so you can use import
. Zone.js does not, however, so you need to rely on require()
to get webpack to pick it up and include it in your bundles.
当然,您还需要在package.json
依赖项部分中添加反射和区域(下面的末尾列出了我的内容):
Of course you also need to have reflect and zone in your package.json
dependencies section (mine are listed at the end, below):
{
"name": "angular2-bootstrap4-oauth2-ohmy",
"version": "1.0.8",
"description": "A skeleton Angular2, Bootstrap 4, OAuth2 application using webpack (oh my!)",
"repository": "https://github.com/michaeloryl/angular2-bootstrap4-oauth2-webpack.git",
"dependencies": {
"@angular/common": "^2.0.0-rc.1",
"@angular/compiler": "^2.0.0-rc.1",
"@angular/core": "^2.0.0-rc.1",
"@angular/http": "^2.0.0-rc.1",
"@angular/platform-browser": "^2.0.0-rc.1",
"@angular/platform-browser-dynamic": "^2.0.0-rc.1",
"@angular/router": "^2.0.0-rc.1",
"@angular/router-deprecated": "^2.0.0-rc.1",
"bootstrap": "4.0.0-alpha.2",
"es6-promise": "^3.0.2",
"es6-shim": "^0.35.0",
"jquery": "^2.1.4",
"js-cookie": "^2.1.0",
"lodash": "^4.11.2",
"phantomjs-prebuilt": "^2.1.7",
"require": "^2.4.20",
"rxjs": "^5.0.0-beta.6",
"traceur": "0.0.93",
"reflect-metadata": "^0.1.2",
"zone.js": "^0.6.12"
},
}
完成后,您应该再次有一个可运行的应用程序(假设您已处理了从Angular2 beta到RC(候选发布)代码的迁移所涉及的其他问题.
Once that is done, you should have a working application again (assuming you took care of the other issues involved in moving from Angular2 beta to the RC (release candidate) code.
此代码是我在Github上的 angular2-bootstrap4-oauth2-webpack 项目中的示例.
This code is a sample from my angular2-bootstrap4-oauth2-webpack project on Github.
这篇关于现在将非beta Angular 2打包为@angular时,angular2-polyfills在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!