Production Build System#
Asok provides a powerful, zero-dependency build pipeline designed to generate lean, optimized, and secure distributions for production environments. The asok build command handles everything from asset minification to bytecode compilation.
The asok build Command#
To generate a production-ready distribution of your project, run:
asok build
This command creates a new directory (default: dist/) containing a self-contained, optimized version of your project.
What happens during the build?#
- Cloning: The project structure is replicated into the output directory, excluding development artifacts like
venv,.git, or.asok. - Asset Minification: All JS and CSS files within
src/partialsare recursively minified usingesbuild. - HTML Optimization: Templates are minified to remove unnecessary whitespace and comments, significantly reducing TTFB.
- Bytecode Compilation: All Python source files are compiled into
.pycfiles. By default, the original.pyfiles are removed to create a "locked" distribution. - Image Optimization: If
IMAGE_OPTIMIZATION=trueis set, all project images are converted to WebP and originals are removed. - Production Config: A
.env.productionfile is generated withDEBUG=falseand security defaults.
Command Options#
| Option | Description | Default |
|---|---|---|
--output, -o | Specify the output directory name. | dist |
--keep-source | Keep original .py files alongside .pyc files. | False |
Deployment Workflow#
Once the build is complete, your dist/ folder is ready for deployment. You can preview it locally using:
cd dist
asok preview
[!IMPORTANT] The
asok previewcommand in the build folder correctly identifieswsgi.pycas the entry point. In production environments (Gunicorn/Uvicorn), you should point your WSGI server towsgi:app.
Performance Benefits#
By using asok build, you gain several performance advantages:
- Zero Runtime Minification: In production mode (
DEBUG=false), Asok detects that templates are already optimized and skips on-the-fly minification, saving CPU cycles. - Fast Startup: Bytecode compilation (
.pyc) allows the Python interpreter to load modules faster. - Optimized Assets: Small JS/CSS bundles and WebP images ensure faster page loads and lower bandwidth usage.
- Security: Shipping bytecode instead of source code adds a layer of obfuscation and prevents accidental source leaks.
Requirements#
The build system requires esbuild for asset minification. If not present, run:
asok assets --install
Was this page helpful?