Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Can you suggest a way to @import less code form a different app #749

Open
camilotorresf opened this issue Aug 17, 2021 · 1 comment

Comments

@camilotorresf
Copy link

Hi,

I'm migrating a project from Django 1.11 to 3.2, and also migrating django-pipeline from 1.6.9 to 2.0.6.
Now, we have many django apps and in one app I'm importing less (CSS compiler) code from another app:

in admin_main/static/admin_main/less/common.less, which is located inside the admin_main app I have

@import "../../common/third_party/bootstrap/less/variables";
@import "../../common/less/styles/flexbox.less";
@import "../../common/less/lib/spacing.less";
@import "../../common/less/lib/ng-animate.less"

All these 4 less files are located in the common app:
common/static/common/third_party/bootstrap/less/variables.less
common/static/common/less/styles/flexbox.less
common/static/common/less/lib/spacing.less
common/static/common/less/lib/ng-animate.less

The problem is when collecting statics and compiling admin_main/static/admin_main/less/common.less, lessc cannot find the imported files, because these files are in a complete different directory, and the relative paths cannot be found.

With django-pipeline 1.6.9 these files were found, because the file to process was not the project file, but the collected file inside my collectedstatic directory: deploy/admin/collectedstatic/admin_main/less/common.less, and of course the 4 imported files are also inside the collectedstatic directory, and all works, because lessc can find them in the same collectedstatic directory.

I have found that the problem was introduced by this commit:
63d1182
When I revert the commit it works as before. For now, I'm going to fork and use a customized version of django-pipeline.

I kindly ask: is it possible, and how do you suggest to solve these relative imports from a different Django application with the official django-pipeline package?

Is it OK to create a Pull Request to modify that commit and only use the project_infile when PIPELINE_COLLECTOR_ENABLED == False ?

Thank you for the time you can spend on this.

camilotorresf added a commit to camilotorresf/django-pipeline that referenced this issue Aug 17, 2021
If the collector is enabled (PIPELINE_COLLECTOR_ENABLED is True), use
the collected file. If the disabled (False), use the original project
source file to check if it is outdated and pick up the changes.

This will allow for static files (in particular less CSS compiler) files
to do relative imports from different apps.

See: jazzband#749
@camilotorresf
Copy link
Author

I created this PR:
#750

struan added a commit to mysociety/caps that referenced this issue Oct 19, 2021
Importing other apps styles is handled differently in live and dev
environments as the dev environment processes the non collected file and
live processes the collected file.

There is an existing ticket for this: jazzband/django-pipeline#749
which has a PR. To fix this we've forked the fixed version and are using
that directly from github rather than pulling in an official package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant