Asp.net mvc 混合cshtml和html的网页包配置(angular 2+;mvc)
对于我们的项目,我们正在开发MVC5应用程序,该应用程序服务于angular 2应用程序。对于捆绑,我们使用Webpack 现在的问题是,对于某些组件,必须使用呈现cshtml视图的mvc控制器来加载html。对于其他组件,我们使用静态html文件 我想配置Webpack,以便“静态”组件html在组件中作为内联html呈现,并且templateUrl保留用于需要动态呈现html的组件 这是我尝试过的许多事情之一,但我无法让include和exclude工作。应用程序组件需要服务器呈现的cshtmlAsp.net mvc 混合cshtml和html的网页包配置(angular 2+;mvc),asp.net-mvc,angular,webpack,Asp.net Mvc,Angular,Webpack,对于我们的项目,我们正在开发MVC5应用程序,该应用程序服务于angular 2应用程序。对于捆绑,我们使用Webpack 现在的问题是,对于某些组件,必须使用呈现cshtml视图的mvc控制器来加载html。对于其他组件,我们使用静态html文件 我想配置Webpack,以便“静态”组件html在组件中作为内联html呈现,并且templateUrl保留用于需要动态呈现html的组件 这是我尝试过的许多事情之一,但我无法让include和exclude工作。应用程序组件需要服务器呈现的csht
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader', 'angular2-template-loader'], // here i want to inline the html
exclude: ["/client/src/app/app.component.ts"]
},
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader'], // here i want to keep the templateUrl so that the cshtml can be rendered
include: ["/client/src/app/app.component.ts"]
},
我建议您不要使用
'angular2-template-loader'
,因为它只是将require()
添加到templateUrls
中,您可以自己完成
然后,您需要在为主要角度组件提供服务的*.cshtml
页面中添加
然后,对于需要从渲染的MVC视图中获取其模板的组件,设置以下内容:
@Component({
templateUrl: "MvcController/MvcActionName",
})
export class AppComponent {
对于需要静态模板的组件,请尝试以下操作:
@Component({
moduleId: module.id,
template: require("./app.some.component.html"),
styleUrls: [require("./app.some.component.css")],
})
export class SomeComponent {
静态模板将被捆绑,其他模板将从MVC action下载。您解决了这个问题吗?@jkyadav是的,我通过实现include和exclude expect regex解决了这个问题。所以我将其替换为exclude:/!?app\.component.ts$/谢谢,我会看一看