gpt4 book ai didi

javascript - Grunt - 实时重新加载不适用于 grunt-contrib-watch

转载 作者:行者123 更新时间:2023-11-29 17:13:52 31 4
gpt4 key购买 nike

当我使用 grunt-contrib-watch 更改我的 js 文件时,我试图让 Grunt 重新加载它们。这是我的 Gruntfile:

module.exports = function(grunt) {

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({

connect: {
all: {
options:{
port: 9000,
hostname: "0.0.0.0",
base: 'app',
keepalive: true,
middleware: function(connect, options) {

return [

require('grunt-contrib-livereload/lib/utils').livereloadSnippet,

connect.static(options.base)
];
}
}
}
},
open: {
all: {
path: 'http://localhost:<%= connect.all.options.port%>'
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['app/js/**/*.js'],
tasks: ['jshint'],
}
}
});

// Creates the `server` task
grunt.registerTask('server',[
'open',
'livereload-start',
'connect',
'watch'
]);
};

当我更改 js 文件时,没有任何反应。任何帮助都会很棒。

最佳答案

我之前没有尝试在中间件中使用 livereloadSnippet,所以我不确定那里可能出了什么问题。但是如果你只是想要一个常规的 LiveReload 设置,你可以使用 grunt-contrib-connect 插件提供的 livereload 选项:

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({
connect: {
all: {
options:{
port: 9000,
hostname: '0.0.0.0',
base: 'app',
keepalive: true,
livereload: true,
open: true
}
}
},
watch: {
options: {
livereload: true
},
js: {
files: ['app/js/**/*.js'],
tasks: ['jshint']
}
}
});

grunt.registerTask('server',[
'connect',
'watch'
]);

关于javascript - Grunt - 实时重新加载不适用于 grunt-contrib-watch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19740827/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com