分割Gruntfile [英] Split up Gruntfile

查看:98
本文介绍了分割Gruntfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Gruntfile现在变得相当大,我想把它分成多个文件。我已经谷歌和试验了很多,但我无法得到它的工作。



我想要这样的事情:



Gruntfile.js

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

functions.js

  function getConcatConfiguration(){
//做一些事情来生成并返回配置
}

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

解决方案

< )!

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

此外,我将 concat.js 移至名为 grunt



Gruntfile.js

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

grunt / concat.js

  module.exports = function getConcatConfiguration(grunt){
//做一些东西来生成并返回配置
};






您应该如何操作:



已经有人创建了一个名为 load-grunt-config 。这正是你想要的。



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



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

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

//在这里定义一些别名任务
};


My Gruntfile is becoming pretty big right now and I want to split it up into multiple files. I've Googled and experimented a lot but I can't get it to work.

I want something like this:

Gruntfile.js

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

functions.js

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

How can I load functions.js into my Gruntfile.js?

解决方案

How you can do it:

you need to export your concat configuration, and require it in your Gruntfile (basic node.js stuff)!

i would recommend putting all every taskspecific configuration into one file named after the configuration (in this case i named it concat.js).

Moreover i moved concat.js into a folder named grunt

Gruntfile.js

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

grunt/concat.js

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


How you SHOULD do it:

there was already someone there who created a module named load-grunt-config. this does exactly what you want.

go ahead and put everything (as mentioned above) into separate files into a location of your choice (default folder ist grunt).

then your standard gruntfile should probably look like this:

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

  // define some alias tasks here
};

这篇关于分割Gruntfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆