在grunt中是否可以监视文件并自动重新加载ASP.net MVC Web应用程序。或者livereload只能与通过grunt提供的文件一起使用。我发现了grunt插件“grunt-iisexpress”,但不确定是否可以将其与任务一起使用以在文件更改时重新加载ASP.net MVC Web应用程序。
我的Web应用程序中没有任何index.html作为起始页面,而是_ViewStart.cshtml,它启动整个应用程序。
在grunt中是否可以监视文件并自动重新加载ASP.net MVC Web应用程序。或者livereload只能与通过grunt提供的文件一起使用。我发现了grunt插件“grunt-iisexpress”,但不确定是否可以将其与任务一起使用以在文件更改时重新加载ASP.net MVC Web应用程序。
我的Web应用程序中没有任何index.html作为起始页面,而是_ViewStart.cshtml,它启动整个应用程序。
如果您还没有package.json文件并想将依赖项保存在其中:
npm init
然后将Grunt和grunt-contrib-watch添加到您的项目中:
npm install --save-dev grunt grunt-contrib-watch
接下来在同一文件夹中创建一个名为 Gruntfile.js
的文件。以下是我的示例:
'use strict';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
watch: {
views: {
files: [
'Views/**/*.cshtml',
'Scripts/**/*.js',
'Content/**/*.css',
'Content/images/**/*',
'bin/**/*.dll'
],
options: {
livereload: true,
}
}
}
});
}
在你的ASP.NET应用程序旁边运行实时重新加载服务器:
grunt watch
最后,为了使其在您的ASP.NET应用程序中可用,只需将实时重新加载的片段添加到您的布局和/或视图中:
<script src="http://localhost:35729/livereload.js"></script>
livereload: {
options: {livereload: 32684},
files: [
'<%%= yeoman.app %>/Content/**/*.css',
'<%%= yeoman.app %>/Scripts/**/*',
'<%%= yeoman.app %>/Content/images/**/*',
'<%%= yeoman.app %>/Views/**/*.cshtml',
'<%%= yeoman.app %>/bin/**/*.dll'
]
}