{"id":16624256,"url":"https://github.com/dcramer/django-static-compiler","last_synced_at":"2025-03-16T22:30:45.663Z","repository":{"id":6657774,"uuid":"7902313","full_name":"dcramer/django-static-compiler","owner":"dcramer","description":null,"archived":false,"fork":false,"pushed_at":"2015-02-03T16:32:48.000Z","size":410,"stargazers_count":56,"open_issues_count":1,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-13T03:45:45.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcramer.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-29T22:07:11.000Z","updated_at":"2023-09-08T16:37:24.000Z","dependencies_parsed_at":"2022-09-06T14:21:49.756Z","dependency_job_id":null,"html_url":"https://github.com/dcramer/django-static-compiler","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-static-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-static-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-static-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-static-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcramer","download_url":"https://codeload.github.com/dcramer/django-static-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221668362,"owners_count":16860631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T03:45:41.616Z","updated_at":"2024-10-27T11:25:51.186Z","avatar_url":"https://github.com/dcramer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-static-compiler\n======================\n\n**This project is no longer maintained**\n\nA static files compiler (JavaScript, CSS, et all) which aims to solve two things:\n\n1. Distributed compressed and uncompresed files with third party applications.\n2. Simple compression of project-wide static files.\n\nMany projects solve the second item, but they're unfortunately not compatible (and/or very hard to make so) with\nsourcemap generation.\n\nCompiled Distributions\n----------------------\n\nStatic files are stored relative to their configuration root:\n\n::\n\n    [site-packages]/sentry/static/sentry/js/foo.js\n    [site-packages]/sentry/static/sentry/js/bar.js\n    [site-packages]/otherapp/static/otherapp/css/bar.css\n\nEach application would be compiled independently, based on its own configuration, and you'd end up with something\nlike the following:\n\n::\n\n    [site-packages]/sentry/static/sentry/dist/js/all.min.js\n    [site-packages]/otherapp/static/otherapp/dist/css/bar.min.css\n\nEventually these would be collected (using standard staticfiles) in your project static directory.\n\n\nApplication Configuration\n-------------------------\n\nYou'll need to add the library to both your ``INSTALLED_APPS`` and ``STATICFILES_FINDERS``:\n\n::\n\n  STATICFILES_FINDERS = (\n      \"django.contrib.staticfiles.finders.FileSystemFinder\",\n      \"django.contrib.staticfiles.finders.AppDirectoriesFinder\",\n      \"static_compiler.finders.StaticCompilerFinder\",\n  )\n\n  INSTALLED_APPS = (\n      # ...\n      \"static_compiler\",\n  )\n\nConfiguration is handled via the ``STATIC_BUNDLES`` setting, in ``settings.py``.\n\nAn example configuration might look like this:\n\n::\n\n    STATIC_BUNDLES = {\n        \"cache\": \"CACHE\",\n        \"packages\": {\n            \"sentry/scripts/global.min.js\": {\n                \"src\": [\n                    \"sentry/scripts/core.js\",\n                    \"sentry/scripts/models.js\",\n                    \"sentry/scripts/templates.js\",\n                    \"sentry/scripts/utils.js\",\n                    \"sentry/scripts/collections.js\",\n                    \"sentry/scripts/charts.js\",\n                    \"sentry/scripts/views.js\",\n                    \"sentry/scripts/app.js\",\n                ],\n            },\n            \"sentry/styles/global.min.css\": {\n                \"src\": {\n                    \"sentry/less/sentry.less\": \"sentry/styles/sentry.css\",\n                },\n            },\n        },\n        \"postcompilers\": {\n            \"*.js\": [\"node_modules/uglify-js/bin/uglifyjs {input} --source-map-root={relroot}/ --source-map-url={name}.map{ext} --source-map={relpath}/{name}.map{ext} -o {output}\"],\n        },\n        \"preprocessors\": {\n            \"*.less\": [\"node_modules/less/bin/lessc {input} {output}\"],\n        },\n    }\n\n\nThere are the following top level attributes:\n\ncache\n  The directory name to store the compiler's cached files in. This is relative to ``STATIC_ROOT``, and is only used\n  for compiling files.\npackages\n  A mapping of bunches to their options (options can include top level options as well)\nprecompilers\n  A mapping of input grep patterns to a list of (ordered) commands to execute on files\n  in all situations (including DEBUG use).\npostcompilers\n  A mapping of input grep patterns to a list of (ordered) commands to execute on files\n  which are designated for distribution (e.g. not DEBUG use).\n\nThe packages attribute accepts the following:\n\nsrc\n  A list or mapping of source files to include in this bunch. If the value is a mapping\n  the key is the input file, and the value is the output file.\n\nWe'd make several variables available to post- and precompilers:\n\ninput\n  absolute path to input file\noutput\n  absolute path to output file -- if not present will fetch from stdout\next\n  output extension (e.g. .js)\nname\n  extensionless filename from output (e.g. bundle)\nfilename\n  full output filename (e.g. bundle.js)\npath\n  full output dir path (e.g. foo/bar)\nrelroot\n  the relative path to the STATIC_ROOT. e.g. ../../..\nroot\n  the value of STATIC_ROOT\n\n\nStaticfiles Collection and Compiliation\n---------------------------------------\n\nThe process currently looks like this:\n\n- django-admin.py compilestatic\n- django-admin.py collectstatic\n\nPre-Processors\n~~~~~~~~~~~~~~\n\nA pre-processor will **always** be run. This is nearly always a requirement as things like LESS files have to be processed\nbefor they can be served in a browser.\n\nWhen pre-processing happens each input file is transformed to an output file (using the standard versioning scheme). For\nexample, if I had a bunch that included foo.less and bar.less, each would be compiled separately, and I'd end up with\ntwo output files: foo.css, and bar.css.\n\nThe first pre-processor will change the input filename to be the expected output filename, and the following processors\nwill be passed that to work with.\n\nPost-Compilers\n~~~~~~~~~~~~~~\n\nA post-compiler runs on pre-processed inputs and is expected to concatenate the results together into a unified file.\n\nFor example, if it runs against foo.js and bar.js, it will output bundle.js.\n\nEach post-compiler must be able to accept 1+ inputs, and he first post-compilers will be responsible for combining files\nand the resulting file will be passed to the additional compilers.\n\nIf no post-compilers happen, the result would be similar to the following: cat [input, input, input] \u003e output\n\n\nTemplate Usage\n--------------\n\nSpecify the relative path to the bunch name (relative to the static root):\n\n::\n\n    {% load static_compiler %}\n\n    {% staticbundle 'bundle.js' %}\n\nYou can also specify attributes, such as mimetype:\n\n::\n\n    {% staticbundle 'bundle.foo' mimetype='text/css' media='screen' %}\n\nIf we're in DEBUG / development mode and 'bundle.js' is defined in STATIC_BUNDLES:\n\n1. Determines if it needs to recompile any files (based on its last modified time)\n2. Serves the preprocessed but not compiled files (turning this into many html tags).\n\nOtherwise:\n\n1. Serve bundle.js (assumed to exist)\n\nIn general it simply acts as a proxy to the Django {% static %} templatetag with the inclusion of script/link/etc\nHTML tags.\n\nDistributing Staticfiles with your Library\n------------------------------------------\n\nThe flow would be just like in your project. You'd start by defining STATIC_BUNDLES (in a build_settings.py, or\nsomething along the lines), and then you'd simply do the following (pre-commit?):\n\n::\n\n  django-admin.py --settings=build_settings.py compilestatic\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-static-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcramer%2Fdjango-static-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-static-compiler/lists"}