【发布时间】:2014-07-23 16:12:01
【问题描述】:
我目前正在尝试将 grunt-sync 配置为在手表内运行,但遇到了问题。我已将问题报告到模块的 github 页面,但决定在此处发布以利用一般开发人员,而不是等待单个贡献者看到我的问题报告。
所以,我认为这可能只是我对如何通过手表驱动繁重的任务的理解上的差距。我已经为几项任务启动并运行了手表,并且我正在将 grunt-sync 添加到我的工作流程中,以自动将我的更改发布到网络目录中,等等等等……不重要;我的手表适用于某些东西,但不适用于此。我将连同我的“并发”、“业力”和“sass”任务一起放入相关配置部分,为您提供我的整体 grunt 配置的要点。
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
project: {
app: 'app',
},
sync:{
main: {
files:
[
{
cwd: 'app/',
src: [
'**/*.js',
'**/*.html',
'**/*.css',
'!app/node_modules/**'
],
dest: ['publish/']
}
],
verbose: true
}
},
karma: {
unit: {
configFile: 'test/karma.conf.js'
},
continuous:{
configFile: 'test/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
}
},
sass:{
dev: {
options:{
style: 'expanded',
compass: false
},
files:{
'app/css/app.css':'app/css/app.scss'
}
},
dist: {
options: {
style: 'compressed',
compass: false
},
files:{
'app/css/app.css':'app/css/app.scss'
}
}
},
watch: {
sass: {
files: 'app/css/**/{,*/}*.{scss,sass}',
tasks: ['sass:dev']
},
styles: {
files: ['app/css/app.css'],
tasks: ['autoprefixer']
},
// karma: {
// files: ['test/*.js',
// 'test/**/*.js'
// ],
// tasks: ['karma:unit:run']
// },
livereload:{
options: {livereload: true},
files: ['app/**/*'],
},
sync:{
files: ['app/**'],
tasks: ['sync:main']
}
},
concurrent:
{
target: {
tasks: [
'karma:unit',
'watch'
],
options: {
logConcurrentOutput: true
}
}
}
});
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('default', [
'sass:dev',
'concurrent:target'
]
);
};
当我发出咕噜声时,当前收到以下警告
Warning: Task "sync:main" not found. Use --force to continue.
Aborted due to warnings.
由于只有主子任务,我认为也许将手表从执行 ['sync:main'] 更改为执行 ['sync'] 可能会起作用。警告消失了,但 poof 什么也没发生...所以我不确定问题出在我的配置还是模块实现上。
有什么想法吗?
编辑添加:
从模块的 github 站点,我在 sync.json 中看到以下内容
{
"main": {
"files": [{
"src": ["**"],
"dest": "bin/to",
"cwd": "bin/from"
}]
}
}
所以这会让我相信“main”是我应该用于同步子任务的名称。我真的很困惑为什么 grunt 没有在我的配置中识别它,但是我对剖析 grunt 模块的代码并不是非常熟悉。
【问题讨论】:
-
你能从终端运行
grunt sync:main而不出现警告吗? -
嗯...我没有检查。我会检查的!
-
Wait....查看模块的 gruntfile,已经定义了一个 watch 部分。这是否意味着该任务本质上是在监视下运行的?
-
如果您收到与
grunt sync:main相同的警告,则表示该任务未加载。确保grunt-sync列在您的devDependencies或package.json中,以便require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks)可以接听。 -
yeaaaaahhh.......是的。不能说那曾经发生在我身上。在我安装 npm 之前,我在我的 gruntfile 中引用了一个 grunt 模块,并决定与 stackoverflow 共享证据。
标签: gruntjs grunt-contrib-watch