目前,每次更改服务器文件时,我都会使用browser-refresh重新启动节点服务器。我想更进一步,每次更改HTML文件时都要刷新/重新加载我的浏览器。我正在为客户端使用工具栏,所以我在我的.hbs目录中有views文件。我原以为browser-refresh也能刷新浏览器,但它对我不起作用。
对于grunt,我安装了以下任务:
grunt.loadNpmTasks('grunt-express-server');
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-express-runner');我不认为我需要所有这些,但我想找到有用的东西。我可以用grunt-exec重新启动我的服务器,但是我已经有了browser-refresh的别名,所以我并不需要这个别名。
我还应该注意,在我的app.js服务器文件中,我使用的是app.use('/', routes); where var routes = require('./routes/index');。因此,当我的应用程序加载(使用node app.js)时,它直接进入http://localhost:3000/users/login。
提前谢谢。
发布于 2017-03-27 17:58:24
使用咕噜-表并将活重装选项设置为true,将启用活动重新加载和自动重建。
例如,在您的gruntfile.js中:
watch: {
css: {
files: '**/*.sass',
tasks: ['sass'],
options: {
livereload: true,
},
},
},对于站点的重建,(使用咕噜-表插件),只需键入
grunt watch
若要在更改时自动重新构建网站,请查看下面grunt watch命令的示例用法:
gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
exec: {
server: 'node server'
},
// Other JS tasks here
// ...
watch: {
css: {
files: ['scss/**/*.scss'],
tasks: ['sass'],
options: {
spawn: false
}
},
javascript: {
files: ['js/*.js'],
tasks: ['uglify']
},
options: {
livereload: true,
},
},
});
grunt.registerTask('server', ['exec:server']);
// Minify JS and create CSS files
grunt.registerTask('build', ['uglify', 'sass']);
// Do what you expect the default task to do
grunt.registerTask('default', ['build', 'exec:server']);
};https://stackoverflow.com/questions/43038438
复制相似问题