1

我有一个目录,想像 Ant 一样排除一些文件,这可以通过网络资产实现吗?

或者如果 bundle 可以采用列表或元组,这似乎不是这样?

4

1 回答 1

2

构造Bundle函数签名看起来像这样(来自github 的源代码):

def __init__(self, *contents, **options):

这意味着可以将内容指定为一系列位置参数,如文档中的示例所示

Bundle('common/inheritance.js', 'portal/js/common.js',
   'portal/js/plot.js', 'portal/js/ticker.js',
   filters='jsmin',
   output='gen/packed.js')

但这也意味着您可以使用 Python 的能力unpack argument lists。从该页面:

当参数已经在列表或元组中但需要为需要单独位置参数的函数调用解包时,会发生相反的情况。例如,内置 range() 函数需要单独的开始和停止参数。如果它们不能单独使用,请使用 *-operator 编写函数调用以将参数从列表或元组中解包出来

因此,您可以轻松地将上面的示例编写为:

files = ['common/inheritance.js', 'portal/js/common.js', 
         'portal/js/plot.js', 'portal/js/ticker.js']
Bundle(*files, filters='jsmin', output='gen/packed.js')

当然,您可以在捆绑之前将列表过滤/切片/切块以符合您的心意。

于 2012-11-16T05:34:35.510 回答