django-libsass icon indicating copy to clipboard operation
django-libsass copied to clipboard

Importing scss files with custom path prefixes not working

Open eagle-r opened this issue 8 years ago • 2 comments

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.

eagle-r avatar Aug 09 '16 05:08 eagle-r

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...

gasman avatar Aug 09 '16 10:08 gasman

Thanks for the quick response. You were absolutely correct about the prefixes

eagle-r avatar Aug 09 '16 12:08 eagle-r