当grunt.js文件发生变化时,是否可以重新启动grunt watch
用例:我现在正在构建我的grunt进程并不断更改grunt.js文件,我必须重新启动grunt.js以查看它是否有效.
Grunt正在工作.但是将我的网站文件移到一个目录后,坐在root上,grunt停止工作:
致命错误:端口35729已被其他进程使用.
在这种情况下,路径是否重要?看看35729端口,我发现Grunt是该端口上唯一运行的进程.我杀了那个进程,确认没有其他进程在35729上运行,然后再次运行grunt,但仍然像以前一样得到同样的致命错误.
虽然我的配置文件没有为grunt改变,因为它正在工作,我想我会尝试使用"npm init"方法创建一个新的package.json,然后再次运行"npm install"并确认它下载了"node_modules".我还能尝试什么?
我在Mac OS 10.10.5上运行Node v0.10.33
是否有可能在grunt中观看文件并自动重新加载ASP.net MVC Web应用程序.或者livereload仅适用于通过grunt提供的文件.我遇到过grunt插件'grunt-iisexpress',但不确定我是否可以使用它,结合任务在文件发生变化时重新加载ASP.net MVC webapp.
我没有任何index.html作为我的网络应用程序中的起始页面,但_ViewStart.cshtml启动了整个应用程序.
我想在我保存的单个文件上运行咖啡lint和咖啡编译.我的项目中有数百个CoffeeScript文件,编译所有这些文件需要花费太多时间.
这是我的Gruntfile:
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
coffee:
all:
expand: true
bare: true
cwd: 'src/coffeescript/'
src: '**/*.coffee'
dest: 'public/js/compiled'
ext: '.js'
coffeelint:
all: ['src/coffeescript/**/*.coffee']
watch:
coffeescript:
files: ['src/**/*.coffee']
tasks: ['coffeelint', 'coffee']
options:
spawn: false
grunt.event.on 'watch', (action, filepath) ->
grunt.config(['coffeelint', 'all'], filepath)
grunt.config(['coffee', 'all'], filepath)
grunt.loadNpmTasks 'grunt-coffeelint'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.registerTask 'default', ['coffeelint', 'coffee', 'watch']
Run Code Online (Sandbox Code Playgroud)
coffeelint任务仅在更改的文件上成功运行.
咖啡编译不会产生任何JS文件,即使grunt说它运行.
这是保存单个咖啡文件后的输出:
OK
>> File "src/coffeescript/app.coffee" changed.
Running "coffeelint:all" (coffeelint) task
>> 1 file lint free.
Running "coffee:all" (coffee) task …Run Code Online (Sandbox Code Playgroud) coffeescript gruntjs grunt-contrib-watch grunt-contrib-coffee
我正在努力让Grunt的"实时重新加载"能力(如实现grunt-contrib-watch)在我的应用程序中工作.我终于咬紧牙关,试着做一个最小的例子.希望有人可以很容易地注意到缺少的东西.
文件结构:
??? Gruntfile.js
??? package.json
??? index.html
Run Code Online (Sandbox Code Playgroud)
package.json
{
"name": "livereloadTest",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3"
}
}
Run Code Online (Sandbox Code Playgroud)
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
src: {
files: ['*.html'],
options: { livereload: true }
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
};
Run Code Online (Sandbox Code Playgroud)
index.html
<!doctype html>
<html>
<head><title>Test</title></head>
<body>
<p>....</p>
<script src="//localhost:35729/livereload.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后我跑了grunt watch,什么都没吹.但是,没有浏览器窗口自动打开(应该吗?).
当我在http://localhost:35729/我收到这个json 时打开chrome :
{"tinylr":"Welcome","version":"0.0.4"}
Run Code Online (Sandbox Code Playgroud)
并尝试在该端口上的任何其他路径给我
{"error":"not_found","reason":"no such route"}
Run Code Online (Sandbox Code Playgroud) 您可以在此处查看/克隆完整代码:https://github.com/mlewisTW/grunt-tests
我想观看的src目录(来缩小,CONCAT,少等),这使一切都入build目录.我也想观看的build目录,以livereload.这是手表配置代码段:
watch: {
options: {
livereload: false
},
build: {
files: ['<%= srcDir %>/**/*'],
tasks: 'build'
},
reload: {
files: ['<%= buildDir %>/**/*'],
options: {
livereload: true
}
}
},
Run Code Online (Sandbox Code Playgroud)
我在Windows 8上.Fatal error: watch EPERM当我更改文件时,我得到了一个,它开始了build任务的第一步(干净).我猜这与我正在尝试删除一个监视目录的事实有关.
有没有办法在我构建时关闭livereload watch任务,然后在完成后重新启动它?
还有其他/更好的方法吗?
我尝试在node.js中通过grunt运行监视任务,但它对我不起作用(这是我得到的):
$ grunt watch
warning: Maximum call stack size exceeded Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
这是Gruntfile.js中watch任务的一部分:
watch: {
less: {
files: 'src/less/*.less',
tasks: ['clean', 'recess', 'copy']
},
js: {
files: 'src/js/*.js',
tasks: ['clean', 'jshint', 'concat', 'uglify', 'copy']
},
theme: {
files: 'src/theme/**',
tasks: ['clean', 'recess', 'copy']
},
images: {
files: 'src/images/*',
tasks: ['clean', 'recess', 'copy']
}
}
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('watch', ['watch']);
Run Code Online (Sandbox Code Playgroud) 我正在运行两个运行时间<100毫秒的简单任务,但是当在watch命令下运行时,两个组合任务总共需要大约8秒(每个任务的开销似乎为3.5秒).我正在使用它进行实时重载以进行开发,我发现它非常令人沮丧.我尝试过设置spawn,false但这似乎打破了它,并没有运行任何相关的任务.
这是更改sass文件时的示例输出.
>> File "app/styles/main.scss" changed.
File "app/styles/main.css" created.
Done, without errors.
Elapsed time
loading tasks 4ms ????? 9%
sass 1ms ?? 2%
sass:dist 39ms ?????????????????????????????????????????? 89%
Total 44ms
Completed in 3.862s at Mon Nov 18 2013 17:05:57 GMT+0000 (GMT) - Waiting...
OK
>> File "app/styles/main.css" changed.
Running "copy:styles" (copy) task
Copied 1 files
Done, without errors.
Elapsed time
loading tasks 4ms ???????????? 24%
copy:styles 13ms ???????????????????????????????????? 76%
Total 17ms
Completed in 3.704s at Mon Nov …Run Code Online (Sandbox Code Playgroud) 我能够使用grunt-ssh为我的开发服务器设置一个Grunt任务到SFTP文件:
sftp: {
dev: {
files: {
'./': ['**','!{node_modules,artifacts,sql,logs}/**'],
},
options: {
path: '/path/to/project',
privateKey: grunt.file.read(process.env.HOME+'/.ssh/id_rsa'),
host: '111.111.111.111',
port: 22,
username: 'marksthebest',
}
}
},
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,这会上传所有内容.有数千个文件.每次修改文件时,我都没有时间等待他们逐个上传.
一旦我更改了文件,如何设置手表才能上传我已更改的文件?
(好奇的是,服务器是本地网络上的虚拟机.它运行在不同的操作系统上,设置与我的本地机器的设置更相似.如果我能正常工作,上传应该是快速的)
Grunt需要很长时间来编译css文件,我不确定这是否正常但是常规指南针需要大约5秒钟.
所以问题是如果有任何方法可以加快Grunt的编译时间,或者只是坚持使用罗盘手表?
Running "compass:dist" (compass) task
?unchanged images/sprite-sf580a96666.png
overwrite stylesheets/app.css (3.263s)
unchanged images/sprite-sf580a96666.png
overwrite stylesheets/app_fr.css (3.289s)
Compilation took 11.116s
Running "watch" task
Completed in 13.974s at Wed Dec 18 2013 13:53:05 GMT-0500 (Eastern Standard Time- Waiting...
OK
>> File "scss\_core.scss" changed.
Run Code Online (Sandbox Code Playgroud)
Gruntfile.js:
compass: {
dist: {
options: {
config: 'config.rb'
}
}
},
watch: {
sass: {
files: ['scss/*.scss'],
tasks: ['compass:dist'],
options: {
spawn: false,
}
},
scripts: {
files: ['js/*.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: false,
}
} …Run Code Online (Sandbox Code Playgroud) performance watch gruntjs grunt-contrib-watch grunt-contrib-compass
gruntjs ×9
node.js ×4
livereload ×2
asp.net-mvc ×1
coffeescript ×1
javascript ×1
performance ×1
ssh ×1
watch ×1
yeoman ×1