Package: dpack
DPackDPack is a static asset packager, written primarily for Django applications.Installationpip install dpackDPack 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 withpip install dpack[all].ConfigurationDPack can be configured either via adpack.yamlfile, or via aDPACKsetting 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 searches
by using anySTATICFILES_FINDERSthat are notDPackFinderitself.Exampledpack.yamlassets:compiled/site.css:-app1/first.css-app2/second.css-cssmin:sass:app3/third.scsscompiled/site.js:-app1/first.js-app2/second.jsdefaults:css:-rewrite-cssminjs:-jsminoutput:./buildprefix:/static/register:custom:myapp.processors.customsearch:-./app1/static-./app2/staticExampleDPACKSettingDPACK={"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 DjangoSimply adddpack.finders.DPackFinderto yourSTATICFILES_FINDERSsetting, and DPack will search for inputs using
Django'sstaticfilesapp, output compiled assets whencollectstaticis called, and generate assets on-the-fly when
serving withrunserver(DEBUG=True) or via thedjango.contrib.staticfiles.views.serveview.STATICFILES_FINDERS=("django.contrib.staticfiles.finders.FileSystemFinder","django.contrib.staticfiles.finders.AppDirectoriesFinder","dpack.finders.DPackFinder",)If you compile an asset tocompiled/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 yourSTATICFILES_STORAGE, so you can use things likeWhitenoise'sCompressedManifestStaticFilesStoragewith no extra configuration.Command Line InterfaceDPack comes with a command-line utility, unsurprisingly nameddpack. Run by itself, it will look for adpack.yamlconfig 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 usingdpack -y. Rundpack -hfor a full list of options.ProcessorsProcessors are simply Python callables that take three arguments:text(the processed text so far),input(thedpack.base.Inputobject containing things like relativenameand absolutepath), andpacker(an instance ofdpack.DPackcontaining things likeprefix). For example, thecssminprocessor is implemented as:defprocess(text,input,packer):returnrcssmin.cssmin(text)