django-postcss-modules
Bring postcss-modules to your django project, transpiling static .cssm files on the fly, without NodeJS require!
Install
pip install django-postcss-modules
Static files transpiling config
- Add
postcss_modulesto your djangoINSTALLED_APPS - Add
postcss_modules.middlewares.PostCSSModulesMiddlewareto your djangoMIDDLEWAREnote the order
[ ... 'postcss_modules.middlewares.PostCSSModulesMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', ... ] - Config django
STATICFILES_STORAGE = 'postcss_modules.storage.PostCSSModulesStorage'
Global Options
Default options is:
{
'polyfill': 'postcss-modules-v8-polyfill.js',
'transpiler': 'npm/postcss-modules-standalone@1.0.1/index.bundle.min.js',
'setup': 'postcss-modules-setup.js',
'extensions': ['.cssm'],
'mimetypes': {
'.cssm': 'text/css'
},
'max_time': 3 # transpiling max wait time, in second
}
You can customize by provide POSTCSS_MODULES in your django settings, for example, custom max time:
POSTCSS_MODULES = {
'max_time': 30
}
Template Support
Sometimes transpiling in your template file is more make sense than static file,
you can use postcssmodules tag to do that.
{% load static postcss_modules %}
...
<style id="indexStyles">
{% postcssmodules %}
:global .page {
padding: 20px;
}
@value hi from '{% static "myapp/css/consts.cssm" %}';
.title {
composes: title from "{% static "myapp/css/mixins.cssm" %}";
color: green;
}
.article {
font-size: 16px;
color: hi;
}
{% endpostcssmodules %}
</style>
...
<script>
const _styles = document.querySelector('#indexStyles').sheet
const styles = JSON.parse(_styles.cssRules[_styles.cssRules.length - 1].style.getPropertyValue('--json'));
element.innerHTML = '<div class="' + styles.title + '">';
</script>
...
Template tag also support use custom transpiling option, for example:
{% postcssmodules max_time=30 %}
.title {
composes: title from "{% static "myapp/css/mixins.cssm" %}";
color: green;
}
{% endpostcssmodules %}
FAQ
-
Static file not get transpiled
if you use django
runservercommand to run server and the settingDEBUG=True, please add--nostaticoption to command -
I want use other storage
you should write your own storage to inherit
PostCSSModulesStorage
Release files for django-postcss-modules 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-postcss-modules-0.1.2.tar.gz | 339.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_postcss_modules-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 682.5 kB
Release files / django-postcss-modules-0.1.2.tar.gz
| Download URL | django-postcss-modules-0.1.2.tar.gz |
|---|---|
| Size | 339.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f5c7de462a62124632d7a1f6d1d15260f65587208983a59a3682c268886ef7a
|
|
BLAKE2b-256 checksum How to use checksums |
6dcf64f425afa09f65949fb6b9d04c2289965262f85a458b2a9e83b8cd0fa167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.9
|
Release files / django_postcss_modules-0.1.2-py3-none-any.whl
| Download URL | django_postcss_modules-0.1.2-py3-none-any.whl |
|---|---|
| Size | 342.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9cd2f7da8e997decc00ec2646bf0bba24b366d2eaee6a67faeeb13d4ea8c104f
|
|
BLAKE2b-256 checksum How to use checksums |
ebe86d22c15faaff4b050708b6cb2e6b4a5402dac77bfffc71aef1da643ab51b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.6.9
|