javascript - 拆分 Gruntfile

标签 javascript gruntjs

我的 Gruntfile 现在变得非常大,我想将它分成多个文件。我用 Google 搜索并进行了很多试验,但无法让它发挥作用。

我想要这样的东西:

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    concat: getConcatConfiguration()
  });
}

函数.js

function getConcatConfiguration() {
  // Do some stuff to generate and return configuration
}

如何将 functions.js 加载到我的 Gruntfile.js 中?

最佳答案

如何做到:

你需要导出你的 concat 配置,并在你的 Gruntfile 中要求它(基本的 node.js 东西)!

我建议将所有特定于任务的配置放入一个以配置命名的文件中(在这种情况下,我将其命名为 concat.js)。

此外,我将 concat.js 移到了名为 grunt 的文件夹中

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    concat: require('grunt/concat')(grunt);
  });
};

咕噜声/concat.js

module.exports = function getConcatConfiguration(grunt) {
  // Do some stuff to generate and return configuration
};

你应该怎么做:

那里已经有人创建了一个名为 load-grunt-config 的模块.这正是您想要的。

继续将所有内容(如上所述)放入单独的文件中,放入您选择的位置(默认文件夹 ist grunt)。

那么你的标准 gruntfile 应该看起来像这样:

module.exports = function(grunt) {
  require('load-grunt-config')(grunt);

  // define some alias tasks here
};

关于javascript - 拆分 Gruntfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356538/

相关文章:

javascript - jQuery 微调器使用问题

javascript - jQuery 更改了 html 页面的内容,但 "View Source"不反射(reflect)更改

javascript - 如何在 javascript 中编写参数大小的泛型函数?

javascript - 如何使 gruntserve 因警告而停止执行

javascript - 添加 typescript 导入可防止编译为单个 js 文件

node.js - sails.js 使用不同的布局和不同的 js 库

javascript - ng-repeat 上的 Angularjs 样式

javascript - 检查某些 div 之间的碰撞

css - Devtools 不等待 less 重新编译 css

javascript - 我的 grunt 任务如何查看 --verbose 标志是否打开?