用于现代web应用开发的资产生成器
assetgen的Python项目详细描述
assetgen的目的是替代各种特殊脚本 编写以构建/管理javascript/css文件。
功能
默认支持包括:
- 将coffeescript/typescript源文件编译为javascript。
- 使用丑陋JS/丑陋JS2缩小-包括固定折叠支架。
- 为coffeescript、typescript和minified javascript生成源映射 消息来源。
- 从less、roole、sass、scss和stylus源代码编译和缩小css 文件夹。
- 为国际化生成相同样式表的变体 (从左向右翻转)。
- 将图像/字体资源作为data:uri嵌入到css样式表中 最小化延迟。
- 将多个源文件连接到一个文件中以最小化 http请求。
- 使用文件名中嵌入的内容哈希创建不同的文件 以便有效地使用web缓存。
- 从http/https url动态获取源文件和嵌入资源。
- 正在创建JSON清单文件,以便在Web应用的静态处理程序中使用。
- 生成由模板语言处理的文件(例如,用于从其他文件插入内容)。
工具由您在^{tt2}中指定的配置驱动$ 文件,例如
# Example assetgen.yaml configuration generate: - js/base.js: source: - %(AMPIFY_ROOT)s/third_party/jslibs/json.js - js/app.js: source: - https://raw.github.com/tav/jsutil/master/define.coffee - static/js/models.coffee - static/js/views.coffee uglify.define: - DEBUG=false profile.dev: uglify.define: - DEBUG=true - js/encoder.js: source: - encoder/detect.ts - encoder/format.ts - encoder/encode.ts sourcemaps: true - js/content-inserter.js source: - static/html/content.html # plain html content - static/js/Content.coffee # content handling logic - raw: "})();" template: | (function(){var htmlContent = ${source|trim,jsliteral}; # the source parameter gets processesed for each static source # file (i.e. not raw strings) which is not processed in any way # i.e. not CoffeeScript/TypeScript files. # Also, templates only works when source maps are disabled sourcemaps: false - gfx/*: source: static/gfx/* type: binary - css/site.css: source: - raw: | // Public Domain (-) 2013 The Ampify Authors. // See the Ampify UNLICENSE file for details. - static/css/site.sass depends: - static/css/*.sass - static/gfx/* bidi: true embed.path.root: static embed.url.base: /.static/ prereqs: - static/js/consts.js: source: static/js/consts.coffee compress: false - static/js/consts-dev.js: source: static/js/consts-dev.coffee compress: false env: NODE_PATH.prefix: static/js output.directory: appengine/static output.hashed: true output.manifest: appengine/assets.json profile.dev: css.compress: false js.compress: false
要利用样式表中的嵌入,只需替换url() 在源样式表文件中具有embed()条目的条目-是否 也就是说,sass、scss、手写笔或普通的旧css。
通过指定^{tt5},可以控制使用哪些配置选项$ 参数。这将使用为 给定的配置文件。因此,在上面的示例中,指定--profile dev将使用 所有的profile.dev选项。
而且,在开发时,可以使用--watch命令行 告诉assetgen监视文件更改并全部重新生成的参数 适当的文件。watch还监视对assetgen.yaml文件的更改, 所以您可以更新配置,而不必重新启动assetgen。
在开发过程中,经常使用dev配置文件运行--watch,例如
assetgen --profile dev --watch
然后,要创建发布/生产版本,只需删除生成的文件并 重新生成,即
assetgen --clean && assetgen
上面的命令假设您已经将assetgen.yaml文件提交到 一个git存储库。assetgen将使用git自动检测来自 在当前存储库中。如果您没有使用git或没有提交 当然,您可以显式地指定配置文件,例如
assetgen assetgen.yaml --profile dev --watch assetgen assetgen.yaml --clean && assetgen assetgen.yaml
如果使用bash,则可以利用 通过将以下内容添加到 您的~/.bashrc或等价物:
_assetgen_completion() { COMPREPLY=( $( \ COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT \ COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD \ OPTPARSE_AUTO_COMPLETE=1 $1 ) ) } complete -o default -F _assetgen_completion assetgen
最后,您可以为assetgen指定自定义处理程序,以便在 正在生成给定type的文件。例如,要重写内置 js处理程序,其中一个只对所有源内容小写,创建 您的分机,例如kickass-extension.py:
class KickassAsset(Asset): def generate(self): content = ''.join(read(source).lower() for source in self.sources) self.emit(self.path, content) register_handler('js', KickassAsset)
然后用^{tt23}运行assetgen。$ 指定的参数。
用法
Usage: assetgen [<path/to/assetgen.yaml> ...] [options] Note: If you don't specify assetgen.yaml file paths, then `git ls-files *assetgen.yaml` will be used to detect all config files in the current repository. So you need to be inside a git repository's working tree. And if you specify a URL as a `source`, then it will be downloaded to ~/.assetgen -- you can override this by setting the env variable $ASSETGEN_DOWNLOADS Options: -h, --help show this help message and exit -v, --version show program's version number and exit --clean remove all generated files --debug set debug mode --extension=PATH specify a python extension file (may be repeated) --force force rebuild of all files --nuke remove all generated and downloaded files --profile=NAME specify a profile to use --watch keep running assetgen on a loop
贡献
要贡献任何补丁,只需使用github分叉存储库并发送 把请求拉到https://github.com/tav,谢谢!
许可证
所有代码都已发布到Public Domain。照你说的做 拜托。
- 享受吧,tav<;tav@espians.com>;