我正试图以角度2打造你好世界。我正在使用this architecture: angular2-seed。
我做了以下事情。
使用package.json
创建npm init
文件,然后安装npm包。这是我的package.json文件:
{
"name": "testwell",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"ts-loader": "^0.7.2",
"typescript": "^1.7.3",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"angular2": "2.0.0-beta.0",
"es6-promise": "3.0.2",
"es6-shim": "0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
}
}
然后我制作了一个tsconfig.json
文件:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node"
},
"exclude": [
"node_modules"
]
}
然后我创建了一个webpack.config.js
文件,我实际上复制了this angular2-seed file from this。
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: {
'app': './src/app.ts',
'vendor': './src/vendor.ts'
},
output: {
path: "./dist",
filename: "bundle.js"
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
],
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' },
],
noParse: [ path.join(__dirname, 'node_modules', 'angular2', 'bundles') ]
},
devServer: {
historyApiFallback: true
}
};
然后我创建了一个app
目录,并在其中创建了app.ts
:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }
在main.ts
:
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app';
bootstrap(AppComponent)
.catch(err => console.error(err));
在vendor.ts
:
import 'angular2/bundles/angular2-polyfills';
import 'angular2/platform/browser';
import 'angular2/core';
import 'angular2/http';
import 'angular2/router';
在index.html
:
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<title>Angular2 Seed</title>
<base href="/">
</head>
<body>
<my-app>loading...</my-app>
<script src="vendor.bundle.js"></script>
<script src="bundle.js"></script>
</body>
</html>
这是我的代码: https://dl.dropbox.com/s/d1xiqdinbxle5eq/testwell.zip?dl=0
我收到此错误:
找不到vendor.bundle.js 和 bundle.js 文件
这是目录的屏幕截图:
如何删除此错误