rykener / django-manifest-loader

Simplifies webpack configuration with Django
https://django-manifest-loader.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
104 stars 12 forks source link

Cannot interpret URL paths in manifest #15

Closed ilikerobots closed 3 years ago

ilikerobots commented 3 years ago

I'm trying to run a Vue app in dev mode (i.e. vue serve from the CLI. My manifest correctly records URLs to the dev server, e.g.

{
  "chunk-vendors.js": "http://localhost:8080/chunk-vendors.js",
  "vue_app_01.js": "http://localhost:8080/vue_app_01.js",
  "vue_app_02.js": "http://localhost:8080/vue_app_02.js",
  "favicon.ico": "http://localhost:8080/favicon.ico",
  "img/logo.png": "http://localhost:8080/img/logo.png",
  "index.html": "http://localhost:8080/index.html"
}

However, it seems that django-manifest-loader is presuming all resources in the manifest are paths to Django staticfiles. My template renders:

<!-- manifest -->
 <script src="/static/http%3A/localhost%3A8080/vue_app_01.js"></script>  

<!-- manifest_match -->
<script src="/static/http%3A/localhost%3A8080/vue_app_01.js"/>

I'd like to be able to use django-manifest-loader to easily switch between dev mode and static build mode on my Vue app without altering any code. Is this possible?

rykener commented 3 years ago

Hi @ilikerobots, sorry for the delay in looking at this. This app was designed to assume all paths are Django staticfiles.

I could add a setting that would allow you to turn that off, and to just use the exact string that the manifest file is passing in. Would that solve your problem? You'd be able to use it something like this:

# settings.py

MANIFEST_LOADER = {
    'map_to_staticfiles': not DEBUG
}

Where in this example if you were running in DEBUG mode it would just pass the exact string the manifest files is pointing to, and when you're not running in DEBUG mode it would work as normal. You could, of course, implement your own logic as to when to flip this setting to meet your own needs.

Alternatively, there could be a setting

# settings.py

MANIFEST_LOADER = {
    'map_urls': False
}

This would inspect strings that are to be mapped to in order to see if they are a URL or not, and if they are it would skip the mapping.

Thoughts?

ilikerobots commented 3 years ago

Sorry for the delay. I looked at the PR and I think you've picked the perfect way to handle it. The settings option above could be clunky because a difference in the rebuild of the JS project (e.g. vue serve vs vue build) would require also a change in the django settings.

Your implemented solution however solves the issue effectively and unambiguously I believe. Thanks.