django-libsass
                                
                                
                                
                                    django-libsass copied to clipboard
                            
                            
                            
                        Importing scss files with custom path prefixes not working
From my reading of the docs, I thought I could add the following to my settings,
STATICFILES_DIRS = (
    ('css/bootstrap', _Path(BASE_DIR, 'node_modules/bootstrap-sass/assets/stylesheets/bootstrap')),
    ('scss', _Path(BASE_DIR, 'django-site/django_app/static/scss')),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)
Then, in my main scss file (django-site/django_app/static/scss/main.scss), use
// @import "../../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/variables";
@import "css/bootstrap/variables";
However, if I do, I get a CompileError: File to import not found or unreadable: css/bootstrap/variables even though the commented out relative path works fine.
Hi @eagle-r - I think this is due to the use of prefixes in your STATICFILES_DIRS setting. Currently, django-libsass just passes a plain list of include paths to the libsass compiler, so while we can add node_modules/bootstrap-sass/assets/stylesheets/bootstrap to the search path, we can't tell it "when you see the path css/bootstrap, map that to node_modules/bootstrap-sass/assets/stylesheets/bootstrap instead". The easiest workaround is probably to write
STATICFILES_DIRS = [
    _Path(BASE_DIR, 'node_modules/bootstrap-sass/assets/stylesheets'),
    _Path(BASE_DIR, 'django-site/django_app/static'),
]
and use @import "bootstrap/variables".
However, I've just seen that libsass-python now supports import callbacks as of version 0.10, which would allow us to support these kinds of mappings. So that's something for the wish list...
Thanks for the quick response. You were absolutely correct about the prefixes