问题标签 [grunt-contrib-watch]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
839 浏览

gruntjs - Grunt globbing 模式在 grunt-contrib-watch 中未按预期工作

grunt-contrib-watch中,我想观察两者的<%%= yeoman.app %>/*.html变化以及对任何 HTML 文件的更深一层文件夹的变化。

因此,我的监视任务如下所示:

当我将更改保存到<%%= yeoman.app %>/index.html时,监视任务按预期运行。但是,当我在其中创建一个目录<%%= yeoman.app %>然后newfile.html在该新目录中创建时,手表不会被触发。

我也尝试过files: ['<%%= yeoman.app %>/*.html', '<%%= yeoman.app %>/*/*.html'],甚至files: ['<%%= yeoman.app %>/**/*.html']匹配所有子目录,但是当编辑子目录中的 HTML 文件时,仍然不会触发。

我错过了什么?

0 投票
4 回答
3102 浏览

gruntjs - Grunt: `contrib-watch` Fire livereload event after `grunt-nodemon` has restarted when server-side `.coffee` files are compiled

I've been having an issue with Grunt.js and a few plugins, notably: grunt-contrib-watch, grunt-nodemon and grunt-contrib-coffee. I've been trying to figure this out for two days now but I don't think my knowledge of Grunt is sufficient to solve it at this point.

The problem I'm experiencing is simply that I want my server-side .coffee files to compile and then have nodemon restart the server and THEN only have livereload work. Right now, Livereload works as intended for everything but server-side coffee files. contrib-watch detects the change, runs coffee and fires off a livereload event, but then nodemon restarts.

Is there a way to get nodemon to restart before the page reloads so that what I see on the screen is up-to-date with what's going on in my server-side code?

I've been presented with the option of just running nodemon in a separate terminal tab, but I'm on Windows and would much prefer to keep one terminal running for this purpose and is the whole reason I'm using grunt-concurrent.

Here's my Gruntfile, it's quite early in it's stages (as I try to figure all this out). If you would prefer I compile it to JavaScript, then just leave a comment and request so, I will be happy to.

0 投票
1 回答
544 浏览

sass - grunt/compass 产生空的目标样式表

我正在弄清楚咕噜声和指南针。我正在使用'grunt-contrib-compass'。

当我运行“grunt”并编辑我的 sass 时,grunt 报告:

文件“css/site.sass”已更改。完成,没有错误。

但是,我的目标样式表是空的。

我想我缺少一个配置选项,它告诉 grunt 将 css 文件写入何处。但我一直无法弄清楚如何完成配置。

这就是我所拥有的:

0 投票
1 回答
2434 浏览

gruntjs - grunt-contrib-watch:{ tinylr:“欢迎”,版本:“0.0.4”}

我正在尝试使用 grunt-contrib-watch 和 grunt-contrib-compass 让 grunt 正常工作。

到目前为止,我的 Gruntfile 看起来像这样:

我正在使用 chromes live-reload 扩展。

如果我然后运行“grunt -v”,我可以看到 grunt 按预期监视我的 html 和我的 sass 文件。正如预期的那样,我的浏览器选项卡会自动重新加载。

在浏览器选项卡中,我转到此地址:

但是,在我的浏览器中,我只在加载和重新加载时看到:

我没有看到我的 index.html。只是对象。

我需要做什么才能看到我的网站?

0 投票
1 回答
318 浏览

node.js - 让手表不会因 grunt-express-server 引发的错误而崩溃

我使用 Yeoman 通过 grunt、livereload 等进行一些角度开发。

我还设置了一个基本的 node.js/express 应用程序,我在客户端(角度)和服务器(节点)之间共享一些 JS,并且grunt-contrib-copy使用grunt-express-serverwatch 在每个文件保存时触发。到目前为止,一切都很好!

问题是如果我在要与节点共享的代码中引入语法错误并点击保存。语法错误显示在日志中并中断/停止手表。然后我必须通过$ ctrl+c和重新启动控制台中的手表$ grunt server

grunt-express-server如果在 js 代码中发现语法错误,有没有办法不中断/停止正在运行的手表?

0 投票
2 回答
983 浏览

node.js - 手表不刷新文件更改页面(快递网站)

当我更改项目文件时,让浏览器自动重新加载页面会很好。我有这个 node-express 站点,服务器在“server.js”中定义

但是,我尝试了不同的 grunt 配置,但没有一个会导致浏览器在文件更改时重新加载,尽管“监视”任务会打印出文件已更改的消息!

下面是相关的 grunt 配置:

并运行我所做的任务

有人可以解释这个配置有什么问题吗?

谢谢

0 投票
3 回答
3831 浏览

php - Grunt - 运行 php 并观看 SCSS/CSS

我正在尝试使用 Grunt 视图运行一个 php Web 服务器,其中 SCSS/CSS 更改被监视并重新编译,因为它们被更改并实时重新加载到 Web 服务器中。目前它正在运行 Web 服务并显示请求,但是当我修改并保存 SCSS 文件时,它根本不会重新编译 CSS 文件。

我在下面包含了我的 Gruntfile.js:

如果这有助于调试,这是我运行“grunt phpwatch --verbose”时的输出:

0 投票
1 回答
2211 浏览

gruntjs - Grunt - 使用 grunt-newer 仅对修改过的文件进行 lint

我正在运行一个使用 Concurrent 来运行 Nodemon 和 Watch/Livereload 的 Grunt 任务。在默认加载时,我 lint 并启动 Concurrent。我还想设置一个 Watch 在更改时对单个文件进行 lint。目前,当任何一个文件被更改时,所有文件都会被 lint。

我在 StackOverflow 上检查了一个类似的问题,并决定使用 grunt-newer 作为潜在的解决方案。然而,在我下面的实现中,“较新”前缀似乎没有做任何事情。如何解决此问题,以便仅对更改的文件进行 linted?

0 投票
1 回答
1201 浏览

node.js - Grunt并发任务不输出任何内容

我希望我的基于 Grunt 的设置同时运行“测试”(即单元测试)和“服务器”(即 Web 服务器),这样我就可以grunt testAndServer同时运行两者(并在任何文件被更新时更新两者已更改)在同一终端中。

代码(大部分基于yo angular脚手架):

然后

这实际上有效,但我在终端(PowerShell)窗口中没有得到任何输出。我希望业力任务显示测试结果。我怎样才能做到这一点?

我在四核机器上的 Windows 7 上运行 Node.js v0.10.20。

0 投票
2 回答
4504 浏览

gruntjs - Grunt grunfile.js 和 grunt watch

** 我希望能够使用 Compass 但 Grunt watch 无法正常工作并给我一些奇怪的错误:**