使用grunt插件的Gruntfile任务而不是执行Gruntfile中的任务

时间:2014-02-17 18:24:47

标签: gruntjs

我有一个grunt插件,我们称之为grunt-my-plugin,在插件的Gruntfile中我有一个需要运行的特定cssmin任务。在测试grunt插件时,一切都按预期工作,但是,当我在另一个项目上安装它时,它会给我以下错误:

Warning: Task "cssmin" not found. Use --force to continue.

起初,我只是从插件的任务文件中调用grunt.task.run('cssmin');,但是在看到错误后我意识到使用此插件的Gruntfile需要指向相应的任务配置,所以我添加了:

grunt.task.loadTasks('./Gruntfile.js');

那还有我的错误,所以我试过了:

grunt.task.loadTasks('./node_modules/grunt-my-plugin/Gruntfile.js');

仍然收到错误。那么,我该如何解决这个问题呢?该插件不需要使用它的Gruntfile的特定配置。 cssmin任务用于创建tmp副本并针对它运行指标。关于如何实现这一点的任何想法?谢谢!

1 个答案:

答案 0 :(得分:0)

确保以下内容:

  • 您的插件将grunt-contrib-cssmin插件列为package.json
  • 中的依赖项
  • 您在其他项目中有npm install - ed(请与npm ls grunt-contrib-cssmin联系)
  • 在致电cssmin之前使用grunt.config()grunt.task.run('cssmin')任务提供配置(请参阅this GitHub comment了解相关信息)
相关问题