induct...@gmail.com
unread,May 27, 2013, 8:04:36 AM5/27/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-...@googlegroups.com
Hi,
I am trying to get django-require working to manage JS dependencies and minification. However, I am having difficulty with the requireJS baseUrl.
require.js is at project/static/require.js, and page JS is at project/static/pages/pageA.js and so on.
The following are the django-require settings.
REQUIRE_BASE_URL = os.path.join(PROJECT_DIR, 'static')
REQUIRE_BUILD_PROFILE = 'app.build.js'
REQUIRE_JS = "require.js"
REQUIRE_STANDALONE_MODULES = {}
REQUIRE_DEBUG = DEBUG
REQUIRE_EXCLUDE = ("build.txt",)
REQUIRE_ENVIRONMENT = "auto"
I can't get the base URL to be correct during static file collection/processing and when serving via the browser. If I set it like this:
REQUIRE_BASE_URL = os.path.join(PROJECT_DIR, 'static')
then the compilation process is successful (node finds r.js and so on). However, the template tags like {% require_module pages/pageA %} render like this:
<script data-main="/var/www/project/static/pages/pageA.js" src="/var/www/project/static/require.js"></script>
This fails from the browser side, as the path is the path on the machines actual file system, not in the website structure!
However, if I set the base URL like this:
REQUIRE_BASE_URL = 'static'
then the compilation step fails, since r.js is being called with a path that doesn't exist on the local file system (but would exist on the web site):
File "/usr/local/lib/python2.7/dist-packages/require/storage.py", line 50, in run_optimizer
raise OptimizationError("Error while running r.js optimizer.")
The rendered script tags are correct in this case.
Adding a setting to the app.build.js like "baseUrl: '/static'", doesn't seem to have any effect. I saw the note "'baseUrl' will be overidden by django-require during the build process," but I am unsure if that means the overwriting applies only during the build process or if it happens during the build process and persists.
What is the right way to feed r.js the local file paths during the build process, but output website-relevant paths in the template tag when the site is served?
Thanks,
Inductiveload