[英]Task not found using grunt
我正在嘗試在grunt中使用多個任務,其中一個是partialy工作,另一個是not found task
。
這個問題是基於這個 ,我使用相同的gruntfile.js
和相同的結構,這是:
├── Gruntfile.js
└── grunt
├── config
│ ├── conf_sass.js
│ └── conf_home.js
└── register
├── reg_sass.js
└── reg_home.js
使用這個相應的文件:
conf_sass.js
module.exports = function(grunt) {
grunt.config.set('sass', {
sass: {
options: {
style:'expanded',
compass: true
},
files: {
'src/css/app.css' : 'src/sass/app.scss'
}
},
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: {
'dist/css/app.min.css': 'src/css/app.css'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
};
reg_sass.js
module.exports = function(grunt) {
grunt.registerTask('compSass', ['sass']);
};
conf_home.js
module.exports = function(grunt) {
grunt.config.set('home', {
concat: {
dist : {
src: 'src/.../home/*.js',
dest: 'src/.../concat_home.js'
}
},
ngAnnotate: {
options: {
add: true
},
dist: {
files: {
'src/.../concat_home.js': 'src/.../concat_home.js'
}
}
},
uglify: {
dist: {
src: 'src/.../concat_home.js',
dest: 'app/.../home.min.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-ng-annotate');
};
reg_home.js
module.exports = function(grunt) {
grunt.registerTask('compHome', ['home']);
};
問題是:
sass進程在沒有錯誤的情況下運行所有內容,但是不執行css minify部分,即使沒有任何錯誤。
回家過程中,返回錯誤
警告:未找到任務“主頁”
它出什么問題了? 我安裝了所有模塊,因為在遷移到這個新結構之前它們都在工作。
有幾個問題:
- 文件名必須與任務名相同( 例如 : ngAnnotate.js
- > task: ngAnnotate
)
- 您的任務不是由grunt插件分組的
- 共享配置任務和注冊任務的名稱,然后您無法設置home
配置任務和home
注冊任務,因為當您使用grunt home
調用它時,grunt無法知道您正在引用的任務。
您必須遵守配置任務的此規則: 在一個文件中使用相同插件的組配置任務,不要在配置任務中混用grunt-plugins,注冊任務適用於此作業。
你當前的配置問題,要調用cssmin任務,你必須運行grunt sass:cssmin
,這沒有意義。 這就是為什么通過grunt插件對配置任務進行分組,用grunt cssmin
調用你的cssmin任務或用grunt cssmin
調用你的子任務grunt cssmin:<subtask_name>
這是一個例子:
module.exports = function(grunt) {
grunt.config.set('sass', {
website: {
options: {
style:'expanded',
compass: true
},
files: {
'src/css/app.css' : 'src/sass/app.scss'
}
},
admin: {
options: {
style:'expanded',
compass: true
},
files: {
'src/css/app.css' : 'src/sass/app.scss'
}
},
});
grunt.loadNpmTasks('grunt-contrib-sass');
};
這里我們注冊了sass配置任務,運行它,我們使用grunt sass
。 它將在其網站和管理子任務中運行所有子任務。 現在,如果我們只想運行網站任務,我們運行: grunt sass:website
那么在你的情況下,這是你的結構應該是什么樣子:
├── Gruntfile.js
└── grunt
├── config
│ ├── sass.js
│ ├── concat.js
│ ├── cssmin.js
│ ├── uglify.js
│ └── ngAnnotate.js
└── register
├── sassAndCssmin.js
└── home.js
你的sass.js
文件:
module.exports = function(grunt) {
grunt.config.set('sass', {
sass: {
options: {
style:'expanded',
compass: true
},
files: {
'src/css/app.css' : 'src/sass/app.scss'
}
},
});
grunt.loadNpmTasks('grunt-contrib-sass');
};
你的cssmin.js
文件:
module.exports = function(grunt) {
grunt.config.set('cssmin', {
cssmin: {
options: {
shorthandCompacting: false,
roundingPrecision: -1
},
target: {
files: {
'dist/css/app.min.css': 'src/css/app.css'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-cssmin');
};
你的concat.js
文件:
module.exports = function(grunt) {
grunt.config.set('concat', {
home: {
dist : {
src: 'src/.../home/*.js',
dest: 'src/.../concat_home.js'
}
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
};
你的ngAnnotate.js
文件:
module.exports = function(grunt) {
grunt.config.set('ngAnnotate', {
home: {
options: {
add: true
},
dist: {
files: {
'src/.../concat_home.js': 'src/.../concat_home.js'
}
}
},
});
grunt.loadNpmTasks('grunt-ng-annotate');
};
其他配置任務的進程相同。
以下是注冊任務的示例:
你的sassAndCssmin.js
文件:
module.exports = function(grunt) {
grunt.registerTask('sassAndCssmin', [
'sass',
'cssmin'
]);
};
你的home.js
文件:
module.exports = function(grunt) {
grunt.registerTask('home', [
'concat',
'ngAnnotate',
'uglify'
]);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.