我为我的应用程序创建了一个最小的 webpack 示例,并尝试使用带有“./file.name.html”的 templateUrl 来编译。但我的应用程序显示的唯一内容是我的索引页面上的 templateUrl "./file.name.html" 的名称。这些应用程序似乎可以工作,因为控制台中没有错误,并且
<app>... Loading </app>
不再显示。在我尝试使用 webpack 之前,我使用过 systemJs 并且我的应用程序运行良好。所以我不认为这是一个应用程序问题。
我的起始文件名是 boot.ts
/// <reference path="../typings/index.d.ts" />
import 'core-js/es6';
import 'core-js/es7/reflect';
import "zone.js/dist/zone";
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
app.component 定义看起来像
.... Imports
@Component({
selector: 'sxp-app',
templateUrl: "./app.component.html"
})
export class AppComponent { ... }
我的 webpack.config.js
var path = require('path');
module.exports = {
entry: "./App/boot.ts",
output: {
path: path.join(__dirname, './Scripts/dist'),
filename: "bundle.js"
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loader: ['awesome-typescript-loader', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'raw-loader'
}
]
}
};
package.json
{
"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080",
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
},
"dependencies": {
"@angular/common": "~2.2.0",
"@angular/compiler": "~2.2.0",
"@angular/core": "~2.2.0",
"@angular/forms": "~2.2.0",
"@angular/http": "~2.2.0",
"@angular/platform-browser": "~2.2.0",
"@angular/platform-browser-dynamic": "~2.2.0",
"@angularclass/hmr": "~1.2.2",
"@angularclass/hmr-loader": "~3.0.2",
"@angular/router": "~3.2.0",
"@angular/upgrade": "~2.2.0",
"core-js": "^2.4.1",
"rxjs": "5.0.0-beta.12",
"zone.js": "^0.6.26",
"ui-router-ng2": "1.0.0-beta.3"
},
"devDependencies": {
"@types/node": "^6.0.51",
"@types/requirejs": "2.3.1",
"angular2-router-loader": "^0.3.4",
"angular2-template-loader": "^0.6.0",
"css-loader": "0.26.0",
"file-loader": "0.9.0",
"html-loader": "0.4.4",
"html-webpack-plugin": "2.24.1",
"raw-loader": "0.5.1",
"rimraf": "~2.5.4",
"style-loader": "0.13.1",
"typescript": "^2.0.10",
"typings": "2.0.0",
"webpack": "2.1.0-beta.27",
"webpack-dev-server": "2.1.0-beta.12",
"webpack-merge": "0.17.0",
"webpack-notifier": "^1.4.1"
}
}
和 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"types": [
"node"
]
},
"awesomeTypescriptLoaderOptions": {
"useWebpackText": true
},
"exclude": [
"node_modules",
"dist",
"typings/main",
"typings/index.d.ts"
],
"compileOnSave": true
}
我正在使用 Ui-router,我看到正确的 url 已加载,但它只显示模板文件名,如“./appHeader.component.html”,但没有模板。