简体   繁体   English

如何以编程方式使用grunt插件?

[英]How do I use grunt plugins programmatically?

I'd like to use the grunt-contrib-watch plugin as well as others in one of my own Node.js projects. 我想在自己的Node.js项目之一中使用grunt-contrib-watch插件以及其他插件。 The only problem is I can't figure out how to interact with them programmatically. 唯一的问题是我不知道如何以编程方式与他们互动。 Here's an example: 这是一个例子:

grunt.config.init({
  jshint: {
    all: ['asourcefile.js']
  }
});

grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.task.run('jshint');

Grunt loads the jshint plugin ok and it seems like it can find my task (using a made up name throws an error), it just doesn't seem to actually execute it. Grunt很好地加载了jshint插件,似乎可以找到我的任务(使用jshint名称会引发错误),但似乎并没有真正执行它。

Where am I going wrong and is this even the best way to interact with a grunt plugin programmatically? 我在哪里错了,这甚至是通过编程与Grunt插件交互的最佳方法吗?

A lot of gruntplugins are just wrappers around existing Node.js libraries. 许多gruntplugins只是现有Node.js库的包装。 JSHint's, for example . 例如,JSHint If you're writing a Node.js app, don't use the grunt wrappers: 如果您正在编写Node.js应用程序,请不要使用笨拙的包装器:

var jshint = require('jshint');
// ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM