gruntjs - 使用一项任务的输出作为另一项任务的输入

标签 gruntjs

我有一个 html 文件,其中包含对 js 文件的引用。我想解析它,提取引用的 js 文件列表,并提供 contrib-concat 或任何其他任务。 有没有一种方便的方法可以使用一个 grunt 任务的输出作为另一个任务的输入?

最佳答案

使用grunt.config 。这是一个例子:

grunt.initConfig({
  concat: {
    js: {
      src: ['default/concat/files/*'],
      dest: ['dist/javascript.js'],
    },
  },
});
grunt.registerTask('extractjs', function() {
  /* Do the js extraction */
  // Overwrite the concat.js.src with your extracted files.
  grunt.config(['concat', 'js', 'src'], extractedFiles);
});

现在,当您运行 grunt extractjs concat 时,它将提取 js,然后连接提取的 js 文件。查看此任务:https://github.com/cgross/grunt-dom-munger因为他正在努力实现类似的目标。这是一个带有更多示例的 grunt 问题:https://github.com/gruntjs/grunt/issues/747

关于gruntjs - 使用一项任务的输出作为另一项任务的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15757275/

相关文章:

node.js - 在 Azure 中使用 grunt 发出 ENOTUP 警告

angularjs - 使用 Grunt 预处理和替换环境变量

angularjs - Grunt Wiredep 没有在 Yeoman Angular 教程中注入(inject) Bootstrap css 文件

gruntjs - 使用 assemble 转义部分

javascript - 如何将 --harmony Node 标志添加到 grunt-express

javascript - 在 "module"全局变量上运行 grunt-typescript 时,angular-mock 和 node.js 发生冲突

javascript - IdleProvider.windowInterrupt 不是函数

javascript - Grunt - 无法缩小js文件

eclipse - 我不断得到 "env: node: No such file or directory"在 Eclipse 上运行 Grunt 作为 MacOS Yosemite 下的外部工具

javascript - 带有 react.js 的编译文件太大