Closed KevinSeghetti closed 6 years ago
It's not clear what is the issues. Is it:
Regarding the first case, Babel plugins are installed with npm
and it has nothing to do with static_precompiler
. The typical location of the plugins is the node_modules
folder in your working directory.
Regarding the second case, static_precompiler
locates the source files (almost) the same way is Django does. It first looks for the files in your STATIC_ROOT
folder, then it uses django.contrib.staticfiles.finders
to locate the files. If your files are located outside of the project tree, you might want to use STATICFILES_DIRS
setting, see https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-STATICFILES_DIRS
Yea, sorry I wrote a novel.
My problem only occurs when I try to deploy (when I do ./manage.py compilestatic)
I have a directory structure of:
Can I place the source file someplace not included in STATICFILES_DIRS and still get that to work? (that way the source files won't get copied by./manage.py collectstatic).
--ignore
option for collectstatic
might help.
But STATIC_ROOT doesn't have node_modules, so babel can't find it plugins.
You can install node package either globally, or locally. In the latter case, you'll have node_modules
under your current directory. If you run compilestatic
from the same directory, node should be able to find them. If you have node_modules
somewhere else, try setting NODE_PATH
directory, like env NODE_PATH=/directory/where/node_modules/is/located ./manage.py compilestatic
. Or you can just install them globally with npm -g
option.
On Wed, Aug 31, 2016 at 6:19 PM, Andrey Fedoseev notifications@github.com wrote:
Can I place the source file someplace not included in STATICFILES_DIRS and still get that to work? (that way the source files won't get copied by./manage.py collectstatic).
--ignore option for collectstatic might help.
That is what I ended up doing, but was hoping for a way to move the source files to not be in a directory that collectstatic would copy. I might dig into the static module and see if there is a way to specify a search path that is searched by
but not searched by manage.py collectstatic.
If not, maybe the cleanest solution would be to duplicate the functionality of the static tag in
in the precompiler, maybe something like
Unless I have missed something and there is already a way to do that ( I am still feeling my way through how a lot of these components work, so apologies if I did )
But STATIC_ROOT doesn't have node_modules, so babel can't find it plugins.
You can install node package either globally, or locally. In the latter case, you'll have node_modules under your current directory. If you run compilestatic from the same directory, node should be able to find them.
Interestingly, babel doesn't work that way (I discovered by digging into the code). When it goes looking for its modules, it starts with the path of the source file it has been asked to transpile, and works up from there, looking for the node_modules directory. (I have been told by someone who knows much more about node.js than I do that that is intentional, to insure the environment doesn't change between dev and release).
If you have node_modules somewhere else, try setting NODE_PATH directory,
like env NODE_PATH=/directory/where/node_modules/is/located ./manage.py compilestatic. Or you can just install them globally with npm -g option.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andreyfedoseev/django-static-precompiler/issues/89#issuecomment-243949479, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP9_DW6-1tU3x6PqPTs-lEujH58OV7qks5qligugaJpZM4JxCfL .
Thanks for the suggestions,
Kevin Seghetti: E-Mail: kts@tenetti.org, HTTP: www.tenetti.org GPG public key: http://wiki.tenetti.org/bin/view/KevinSeghetti/GPGKey Copyright is a temporary loan from the public domain, not property
Trying to add react to a babel6 static compile. Did that with a plugin directive. Got an error that it couldn't find that plugin. After some digging, it turns out the source path babel is being handed is in the public/static area (which in my project is not under the project tree). So babel was unable to locate its plugins (because it looks up the tree from the source file)
More digging: the reason the source path is pointing to the static output is because compilers/base.py:get_full_source_path looks there first, and there is a copy of my source file there (maybe it should like in the source tree first, unsure).
But really, the issue here is that my source file is getting copied to the static tree, when really it shouldn't. So I figured I would just move the source file so it wasn't under a static dir in the source tree. But if I do that, then this doesn't work <script src="{% static "path/to/script.coffee"|compile %}"> since the static plugin only searches inside of static directories, and ./manage.py compilestatic doesn't seem to find it either.
I have worked around this issue by putting all of my jsx files in a sub-dir of/static//jsx
and then done
./manage.py collectstatic --noinput -i jsx -v 0
so the jsx directory doesn't get copied.
So, my question is: is there a way to locate the source file outside of the source static directories, and still get it to work both for runserver based dev, and compilestatic based deployment?