I have a module that calls require
on a Javascript library. I am trying to compress my .js files with Django-Pipeline but after collectstatic
the web-page gives the error:
UncaughtReferenceError: require is not Defined
Normal testing/deployment works fine with collect-static if I don't use Django-Pipeline to compress the files. What is the correct setup for minifying my .js files without breaking dependencies - the documentation is kind of sparse. Is django-pipeline the right choice?
Edit: I've tried to make sure the 'required' models are compressed first in pipeline, but I can't seem to compress the module that require
is called from at all without it returning an error.
In my experience, it's difficult to combine both require.js and django-pipeline (even though they are both great projects).
I've worked on one project which used require.js for all its javascript. I tried to use django-pipeline but couldn't get it to work properly with require.js. We ended up working with https://github.com/etianen/django-require for the javascript, and django-pipeline for the css minification.
I would recommend either trying to remove require.js and manually including the library that it is importing using pipeline, or using require.js to build and minify all your javascript assets. You could do add a new step that builds all your javascript files, and link to those either directly in the templates or using pipeline.
Sorry, this may not be an actual 'solution' to your answer, but you did ask "Is django-pipeline the right choice?" :)
This is because your JS compressor (YUGLIFY for example) is also minifying javascript variable names, so require
might have been named to something like x
or y
.
To overcome this set proper options in your JS compressor, to not minify the variable names.
http://django-pipeline.readthedocs.org/en/latest/compressors.html#pipeline-yui-js-arguments
For Yuglify, this argument would be mangle:False
, which would stop mangling the names.
Maybe it's PIPELINE_DISABLE_WRAPPER
. Try setting it to True
.
See https://django-pipeline.readthedocs.org/en/latest/configuration.html#wrapped-javascript-output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With