【发布时间】:2015-08-05 12:56:51
【问题描述】:
我仅将 Grunt 用于 livereload。它工作正常,但我注意到它的 CPU 很高,当我使用“--verbose”运行它时,我发现它正在监视整个“node_modules”文件夹。
所以,我做了一些研究,并试图忽略这一点。不幸的是,没有成功。
我对“gruntfile.js”的关注部分是:
// the watch stuff ..
watch: {
all: {
files: ['!**/node_modules/**', 'js/**/*.js', 'css/**/*.css', 'index.html'],
options: {
interval: 5007,
livereload: true
}
}
},
基本上我是说我想让 grunt 观看所有的 js、css 和 index.html 文件。显式添加了忽略“node_modules”的代码,但它仍然说它正在监视它并且 CPU 运行大约 30%。 (Mac OSx)
===================
我注意到了一件事:
当我在“gruntfile.js”中进行更改时——例如向“watch”任务的“files”属性中添加一个文件——然后它会重新启动 grunt,并且在控制台中我看到它开始观看只有我想要的文件,然后 CPU 低于 1%。 (我猜应该是原来的样子。)
我做错了什么?
=====================
编辑:不幸的是,当我更改 gruntfile 时,我只看到我想要的文件正在被观看 - 然后 livereload 的东西不再工作。
=====================
这是我开始的文章: http://thecrumb.com/2014/03/15/using-grunt-for-live-reload/
这是我的 package.json 文件:
{
"name": "grunt-reload",
"version": "1.0.0",
"devDependencies": {
"grunt": "~0.4.3",
"matchdep": "~0.3.0",
"grunt-express": "~1.2.1",
"grunt-contrib-watch": "~0.6.0",
"grunt-open": "~0.2.3"
}
}
这是我的 Gruntfile.js:
module.exports = function(grunt) {
require('matchdep')
.filterDev('grunt-*')
.forEach(grunt.loadNpmTasks);
grunt.initConfig({
// the web server ..
express: {
all: {
options: {
bases: [__dirname],
port: 8888,
hostname: 'localhost',
livereload: true
}
}
},
// the watch stuff ..
watch: {
all: {
files: ['js/**/*.js', 'css/**/*.css', 'index.html'],
options: {
livereload: true
}
}
},
// the automatic opening stuff ..
open: {
all: {
path: 'http://localhost:8888/index.html'
}
}
});
// create the server task ..
grunt.registerTask(
'server',
['express', 'open', 'watch']
);
}; // end of "module.exports" ..
我从“grunt server”开始。
【问题讨论】:
标签: gruntjs livereload node-modules