Skip to main content

Asset generator for modern web app development

Project description

Assetgen is intended as a replacement for the various ad-hoc scripts that often get written to build/manage JavaScript/CSS files.


The default support includes:

  • Compiling CoffeeScript/TypeScript source files into JavaScript.

  • Minifying with UglifyJS/UglifyJS2 – including constant folding support.

  • Generating source maps for CoffeeScript, TypeScript and minified JavaScript sources.

  • Compiling and minifying CSS from Less, Roole, SASS, SCSS and Stylus source files.

  • Generating variants of the same stylesheet for internationalisation (flipping left to right).

  • Embedding image/font resources as data: URIs within CSS stylesheets to minimise latency.

  • Concatenating multiple source files into one file to minimise the number of HTTP requests.

  • Creating distinct files with the hash of the content embedded in the filename so as to work effectively with web caches.

  • Dynamically fetching source files and embedded resources from HTTP/HTTPS URLs.

  • Creating a JSON manifest file for use in your web app’s static handlers.

  • Generating files processed by a templating language (e.g. for inserting content from other files).

The tool is driven by the configuration you specify in an assetgen.yaml file, e.g.

# Example assetgen.yaml configuration


- js/base.js:
      - %(AMPIFY_ROOT)s/third_party/jslibs/json.js

- js/app.js:
      - static/js/
      - static/js/
      - DEBUG=false
        - DEBUG=true

- js/encoder.js:
      - encoder/detect.ts
      - encoder/format.ts
      - encoder/encode.ts
    sourcemaps: true

- js/content-inserter.js
       - static/html/content.html # plain html content
       - static/js/ # 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:
      - raw: |
          // Public Domain (-) 2013 The Ampify Authors.
          // See the Ampify UNLICENSE file for details.
      - static/css/site.sass
      - static/css/*.sass
      - static/gfx/*
    bidi: true
    embed.path.root: static
    embed.url.base: /.static/


- static/js/consts.js:
    source: static/js/
    compress: false

- static/js/consts-dev.js:
    source: static/js/
    compress: false

  NODE_PATH.prefix: static/js appengine/static
output.hashed: true
output.manifest: appengine/assets.json
  css.compress: false
  js.compress: false

To take advantage of the embedding within stylesheets just replace url() entries with embed() entries in your source stylesheet files – whether that is less, sass, scss, stylus or plain old CSS.

You can control which config options gets used by specifying the --profile parameter. This will override default values with the values specified for the given profile. So, in the above example, specifying --profile dev will use all the options.

And, whilst you are developing, you can use the --watch command-line parameter to tell assetgen to monitor file changes and rebuild all appropriate files. Watch also monitors changes to the assetgen.yaml file, so you can update the config without having to restart assetgen.

During development, one often runs --watch with a dev profile, e.g.

assetgen --profile dev --watch

Then, to create the release/production builds, just remove the built files and regenerate, i.e.

assetgen --clean && assetgen

The above commands assume that you’ve commited an assetgen.yaml file into a git repository. Assetgen will then use git to auto-detect the file from within the current repository. If you are not using git or haven’t committed the config file, you can of course specify it explicitly, e.g.

assetgen assetgen.yaml --profile dev --watch
assetgen assetgen.yaml --clean && assetgen assetgen.yaml

If you are using bash, you can take advantage of the tab-completion for command line parameters support within assetgen by adding the following to your ~/.bashrc or equivalent:

_assetgen_completion() {
    COMPREPLY=( $( \

complete -o default -F _assetgen_completion assetgen

And, finally, you can specify custom handlers for assetgen to call when generating a file of a given type. For example, to override the builtin js handler with one which just lower-cases all the source content, create your extension, e.g.

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)

Then run assetgen with the --extension path/to/ parameter specified.


Usage: assetgen [<path/to/assetgen.yaml> ...] [options]

    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

  -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


To contribute any patches simply fork the repository using GitHub and send a pull request to, thanks!


All of the code has been released into the Public Domain. Do with it as you please.

– Enjoy, tav <>

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions (26.9 kB view hashes)

Uploaded source

assetgen-0.3.10.tar.gz (18.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page