Static asset pipeline

This page documents additional information that may be useful when developing new features for Zulip that require front-end changes. For a more general overview, see the new-feature-tutorial. The code-style documentation also has relevant information about how Zulip's code is structured.

Primary build process

Most of the existing JS in Zulip is written in IIFE-wrapped modules, one per file in the static/js directory. When running Zulip in development mode, each file is loaded separately. In production mode (and when creating a release tarball using tools/build-release-tarball), JavaScript files are concatenated and minified.

If you add a new JavaScript file, it needs to be specified in the JS_SPECS dictionary defined in zproject/settings.py to be included in the concatenated file.

Webpack/CommonJS modules

New JS written for Zulip can be written as CommonJS modules (bundled using webpack, though this will be taken care of automatically whenever run-dev.py is running). (CommonJS is the same module format that Node uses, so see the Node documentation for more information on the syntax.)

Benefits of using CommonJS modules over the IIFE module approach:

The entry point file for the bundle generated by webpack is static/js/src/main.js. Any modules you add will need to be required from this file (or one of its dependencies) in order to be included in the script bundle.

Adding static files

To add a static file to the app (JavaScript, CSS, images, etc), first add it to the appropriate place under static/.

If you want to test minified files in development, look for the PIPELINE_ENABLED = line in zproject/settings.py and set it to True -- or just set DEBUG = False.

Note that static/html/{400,5xx}.html will only render properly if minification is enabled, since they hardcode the path static/min/portico.css.