动态构建过程与Grunt.js [英] Dynamic Build Processes with Grunt.js

查看:285
本文介绍了动态构建过程与Grunt.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能读取的儿童主题和相关的每一个变量JSON文件并通过grunt.js有一个动态生成的构建过程?

Is it possible to read a JSON file of child-themes and variables relevant to each one and have a dynamically generated build process via grunt.js?

具体来说,我有一个标准的 grunt.initConfig(),用于在外部 themes.json 文件,我想重复的整个生成过程中的主要 grunt.initConfig(),但我需要传递通过每个孩子相关的元变量(并不总是相同)主题构建过程。

Specifically, I have a standard grunt.initConfig(), for each JSON object in an external themes.json file, I want to repeat the entire build process of the main grunt.initConfig() but I need to pass variables (not always the same) via meta associated with each child theme to the build process.

我花了很多时间,通过它的工作,我开始觉得 grunt.js 只是不能容纳的构建过程中,我寻找。我认为,在这样一个自定义的meta值

I've spent alot of time working through it and I'm beginning to think grunt.js just can't accomodate the build process I'm looking for. I thought that by creating a mirrored hierarchy in a custom meta value like this

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: '<json:package.json>',
    _themes: '<json:themes.json>',
    recess : 'foo',
    concat : 'bar',
    mincss : 'baz
}

,然后在 themes.json 再次镜像的结构,而是呼唤这样的根配置文件

and then inside of themes.json mirroring that structure again but calling out to the root config file like this

   {
   "themFoo" : {
      "_meta_val_1" : "x",
      "_meta_val_2" : "y",
      "_meta_val_3" : "z",
      "recess" : "<%= recess %>",
      "concat" : "<%= concat %>",
      "mincss" : "<%= min %>"
    }

这是我能得到默认的配置,并只需填写与模板变量的空白,但它似乎并没有这样的。

That I could get the default config and just fill in the blanks with template variables, but it doesn't seem to work that way.

推荐答案

本Alman,Grunt.js的作者还跟在这里解释它的人希望做什么,我已经概述上面:

Ben Alman, author of Grunt.js was kind enough to explain it here for anyone looking to do what I've outlined above:

https://github.com/gruntjs/grunt/issues/568# issuecomment-11335941

从本质上讲,我要对此错误的,没有意识到JSON结构是在顶层不可转让。可以有可选的和/或多个文件,输出等嵌套顶级功能的下方,但那些顶​​层JSON数据项被保留用于本地函数和扩展。

Essentially, I was going about this incorrectly, not realizing that the JSON structure was non-negotiable at the top-level. You can have optional and/or multiple files, outputs, etc. nested beneath the top-level functions, but those top-level JSON data items are reserved for native functions and extensions.

下面就是我如何能够完成我上面列出一个要点:
https://gist.github.com/4294776

Here's a gist of how I was able to accomplish what I outlined above: https://gist.github.com/4294776

这篇关于动态构建过程与Grunt.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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