[英]custom grunt task naming convention
Is there any convention regarding naming custom grunt tasks that include more than one word? 是否有关于命名包含多个单词的自定义grunt任务的约定? For example: grunt-json-schema grunt plugin has
json_schema
task . 例如: grunt-json-schema grunt插件具有
json_schema
task 。 One name includes dashes ( -
), the other includes underscores ( _
). 一个名称包括破折号(
-
),另一个名称包括下划线( _
)。
Obviously, dashed-name can't be used as a JavaScript object key: 显然,虚线名称不能用作JavaScript对象键:
grunt.initConfig({
json-schema: { // WON'T work
they have to be enclosed in quotes: 它们必须用引号引起来:
grunt.initConfig({
'json-schema': { // will work
I checked all official plugins ( grunt-contrib-*
), but they all consist of only one word. 我检查了所有官方插件(
grunt-contrib-*
),但它们都只包含一个字。 The motivation foor this question is simple: I just want to follow conventions. 这个问题的动机很简单:我只想遵循约定。
我认为一般约定是将camelCase
用于包含多个单词的任务。
Short answer: Plugin/custom task names do not have to correlate to a specific config object name. 简短答案:插件/自定义任务名称不必与特定的配置对象名称相关。
The Grunt.js api allows access to the config object using the method grunt.config
. Grunt.js api允许使用
grunt.config
方法访问config对象。 Tasks & Plugins have access to the entire object, not just the sub object correlating to the name. 任务和插件可以访问整个对象,而不仅仅是与名称相关的子对象。
For example, I could create a task called foo
that accesses the config from bar
: 例如,我可以创建一个名为
foo
的任务,该任务可以从bar
访问配置:
grunt.initConfig({
bar: {
baz: true
}
});
grunt.registerTask('foo', 'example custom task', function () {
var config = grunt.config('bar');
grunt.log.ok(config);
});
Best practice: Plugin developers should name the key for their config object similar to the plugin name itself. 最佳实践:插件开发人员应为他们的配置对象命名密钥,类似于插件名称本身。 This helps mitigate conflicts with other plugins who could reference similar.
这有助于减轻与其他可能引用类似插件的插件的冲突。
grunt.initConfig({
foo: {
baz: true
}
});
grunt.registerTask('foo', 'example custom task', function () {
var config = grunt.config('foo');
grunt.log.ok(config);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.