我正在尝试使用 Angular2 设置 webpack(使用 TypeScript)。根据Youtube 上的视频教程,这应该是轻而易举的事。这家伙以这个 Github repo为例。因此,我首先克隆了那个 github 存储库,并且基本上完成了这个人在视频教程中所做的一切。
但是当我加载我的页面时,它只会显示“正在加载...”。它从来没有真正加载角度分量。控制台中也没有错误。根据 Chrome 中的“网络”选项卡,它似乎可以bundle.js
正常加载我的文件。
捆绑webpack
也完全没有错误。
我不知道为什么这对我不起作用。这就是我所拥有的:
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<my-app>Loading...</my-app>
<script src="bundle.js"></script>
</body>
</html>
Typescript 文件与 angular.io app.component.ts 上的完全相同
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
引导.ts
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
bootstrap(AppComponent);
还有我的 webpack 配置文件:
module.exports = {
entry: {
app: "./src/boot",
// load addintional libs (disabled for now)
vendors: [
//__dirname + "/node_modules/angular2/bundles/angular2-polyfills.js"
]
},
output: {
path: __dirname,
filename: "./dist/bundle.js"
},
resolve: {
extensions: ['', '.js', '.ts']
},
module: {
loaders: [{
test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
}]
}
};
其他所有内容,例如tsconfig.js
直接来自 github repo。
有人知道为什么我的组件没有加载吗?
更新
有点设法让它工作。问题是我定义entry
为一个对象。但是当我将它分配为字符串时它会起作用:
...
entry: './src/boot',
...
现在,当我加载我index.html
的组件时,加载正常。但是当我使用 webpack 触发构建时,控制台中仍然会出现很多错误。
...
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(283,5): error TS2300: Duplicate identifier 'MAX_SAFE_INTEGER'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(290,5): error TS2300: Duplicate identifier 'MIN_SAFE_INTEGER'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(346,5): error TS2300: Duplicate identifier 'flags'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(498,5): error TS2300: Duplicate identifier 'prototype'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(561,5): error TS2300: Duplicate identifier 'size'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(570,5): error TS2300: Duplicate identifier 'prototype'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(581,5): error TS2300: Duplicate identifier 'size'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(590,5): error TS2300: Duplicate identifier 'prototype'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(605,5): error TS2300: Duplicate identifier 'prototype'.
ERROR in C:\xampp\htdocs\repo\node_modules\angular2\bundles\typings\es6-shim\es6-shim.d.ts
(619,5): error TS2300: Duplicate identifier 'prototype'.
...