Asset packager for Django.
Project description
DPack
DPack is a static asset packager, written primarily for Django applications.
Installation
pip install dpack
DPack has a number of optional processors for things like minification and compilation:
pip install dpack[cssmin]pip install dpack[jsmin]pip install dpack[sass]
Or get everything with pip install dpack[all].
Configuration
DPack can be configured either via a dpack.yaml file, or via a DPACK setting if using Django. The following options
are available:
assets- a dictionary whose keys are paths of files to be created (relative tooutput), and whose values are lists of files to process and concatenate into said file. Each input file in the list may be prefixed by one or more processors by specifying the processor name followed by a colon. For instance,cssmin:sass:somefile.scsstells DPack to first compilesomefile.scss(found by searching insearchdirectories) using SASS, then minify it using thecssminprocessor.defaults- a dictionary whose keys are file extensions (without the.), and whose values are lists of processors to use by default for input files of that type.output- the path to store packed assets under. If not specified, this will be a temporary directory created usingtempfile.mkdtemp(prefix="dpack-").prefix- the URL prefix compiled assets will ultimately be served from, used when rewritingurland@importdeclarations in CSS files via therewriteprocessor. If usingDPackFinder, this defaults toSTATIC_URL.register- a dictionary whose keys are processor names you wish to register (or override), and whose values are dotted-path strings that resolve to a callable. See processors below.search- a list of directories to search for input files in. If usingDPackFinder, input files will be searched by using anySTATICFILES_FINDERSthat are notDPackFinderitself.
Example dpack.yaml
assets:
compiled/site.css:
- app1/first.css
- app2/second.css
- cssmin:sass:app3/third.scss
compiled/site.js:
- app1/first.js
- app2/second.js
defaults:
css:
- rewrite
- cssmin
js:
- jsmin
output: ./build
prefix: /static/
register:
custom: myapp.processors.custom
search:
- ./app1/static
- ./app2/static
Example DPACK Setting
DPACK = {
"assets": {
"compiled/site.css": [
"app1/first.css",
"app2/second.css",
"cssmin:sass:app3/third.scss",
],
"compiled/site.js": [
"app1/first.js",
"app2/second.js",
],
},
"defaults": {
"css": ["rewrite", "cssmin"],
"js": ["jsmin"]
},
"output": "./build",
"register": {
"custom": "myapp.processors.custom"
},
}
Using DPackFinder With Django
Simply add dpack.finders.DPackFinder to your STATICFILES_FINDERS setting, and DPack will search for inputs using
Django's staticfiles app, output compiled assets when collectstatic is called, and generate assets on-the-fly when
serving with runserver (DEBUG=True) or via the django.contrib.staticfiles.views.serve view.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"dpack.finders.DPackFinder",
)
If you compile an asset to compiled/css/site.css, you can reference it as you would any other static asset, with
{% static "compiled/css/site.css" %} in your templates. These assets are also then post-processed by your
STATICFILES_STORAGE, so you can use things like Whitenoise's CompressedManifestStaticFilesStorage with no extra configuration.
Command Line Interface
DPack comes with a command-line utility, unsurprisingly named dpack. Run by itself, it will look for a dpack.yaml
config file and pack any assets it finds according to the config. You can specify a config file (-c) or Django
settings module (-s), and dump out the loaded config using dpack -y. Run dpack -h for a full list of options.
Processors
Processors are simply Python callables that take three arguments: text (the processed text so far), input (the
dpack.base.Input object containing things like relative name and absolute path), and packer (an instance of
dpack.DPack containing things like prefix). For example, the cssmin processor is implemented as:
def process(text, input, packer):
return rcssmin.cssmin(text)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dpack-0.6.0.tar.gz.
File metadata
- Download URL: dpack-0.6.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea0ab7e542a2b4948293fb55f4054b9c9f81f89602bad72f51019b9b4ac54770
|
|
| MD5 |
e771d7b6e1df56e7bd502ea75fccdf4f
|
|
| BLAKE2b-256 |
b5babbda6cad85eeba6c6e9c1b99d9edc80440a24a91a618bd97a48f69230563
|
File details
Details for the file dpack-0.6.0-py3-none-any.whl.
File metadata
- Download URL: dpack-0.6.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
300640f431f2b6690fc5062911c2670bba08107c78d7b37b8a45d9fecfa3acdf
|
|
| MD5 |
1bbe9dd59c352b6d7e5a9cc02c78ef9e
|
|
| BLAKE2b-256 |
49d5f67f2ccf3971b6617992a8dfc282cf386ae21509fe784103579fbec33e0c
|