Angular 2 Web Pack 404 Html模板URL

Rob*_*dia 4 webpack-dev-server angular

我正在使用Angular2 RC4版本和webpack dev服务器.我无法成功加载我的应用程序.在浏览器控制台上,它会抛出404并且无法使用webpack加载AppComponent模板文件.如果我使用lite-server,这是有效的

app.component.ts片段

@Component({
    moduleId:module.id,
    selector: 'body',
    templateUrl: 'app.component.html',
})
Run Code Online (Sandbox Code Playgroud)

webpack.config.js片段

 module:{
       loaders:[
            {test:/\.ts$/, loader:'ts',   exclude: /node_modules/},
            {test:/\.html$/, loader:'html' },
       ],

    },
Run Code Online (Sandbox Code Playgroud)

错误 browser_adapter.js?0526:84 错误:未捕获(在承诺中):无法加载/app.component.html

Mar*_*.io 7

另一个选择是使用awesome-typescript-loader和angular2-template-loader为你内联你的所有样式,你不需要require.

https://github.com/TheLarkInn/angular2-template-loader

  module: {
    loaders: [
      {
        test: /\.ts$/,
        loaders: ['awesome-typescript-loader', 'angular2-template-loader'],
        exclude: [/\.(spec|e2e)\.ts$/]
      }
    ]
  },
Run Code Online (Sandbox Code Playgroud)