我是Node.js和Grunt的新手......我正在尝试在Windows服务器上使用Node.js和Grunt来观看我的main.less文件并进行标准的编译和连接。我可以在命令提示符打开的情况下执行此操作,但是我需要将其作为守护程序运行,而不是登录到服务器,因为.less文件是从位于云中的CMS部署的。
我在Grunt-Forever中找到了有前途的文档,但它要求你指向一个应用程序,而我只是想执行grunt watch任务。
其他人在9个月前问了一个类似的问题,但没有人回答: Grunt.js Watch Forever
我是从命令行尝试过的:
FWIW,你可以永远做/ usr / local / bin / grunt --base。注意永远使用grunt watch atm。
但是,我遇到了错误。
这是我的gruntfile:
module.exports = function(grunt) {
grunt.registerTask('watch', [ 'watch' ]);
grunt.initConfig({
concat: {
js: {
src: [
'js/global.js','js/googlemap.js'
],
dest: 'js/main.min.js'
},
},
uglify: {
options: {
mangle: false
},
js: {
files: {
'js/main.min.js': ['js/main.min.js']
}
}
},
less: {
style: {
files: {
"css/style.css": "less/main.less"
}
}
},
watch: {
js: {
files: ['js/global.js','js/googlemap.js'],
tasks: ['concat:js', 'uglify:js']
},
css: {
files: ['less/*.less'],
tasks: ['less:style']
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
};
非常感谢任何帮助!
答案 0 :(得分:1)
使用node调用grunt,使用PM2运行和管理节点。
答案 1 :(得分:0)
尝试使用grunt watch
运行nohup
任务。由于您提到了“Windows服务器”,因此您可以查看有关nohup equivalent in Windows的答案。然后,即使您退出服务器,也会运行grunt任务。