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
Can not get it running properly #51
Comments
In modern day application, JS and CSS (or even just JS) are the "entry points" of your frontend applications. They will internally load and use other things like images, videos, etc. Only case where Django would need direct access to images or other files is when you want to reference them directly in a django template and not inside JS/CSS. To address this, we have an undocumented template tag. It is undocumented because I'm not sure yet what to name it exactly and how it should work. You can check an example here: https://github.com/owais/django-webpack-loader/blob/b91c62b57c23784c8f2554437909da4cacd2df80/tests/app/templates/home.html#L12-L13 |
This is not really a problem specific to webpack-loader. It is directly related to webpack. I'd suggest to check webpack docs and ask this on webpack repo for better help (I'll check your example and try to help shortly) |
As long as |
Normally webpack will create a single bundle for JS and CSS. JS bundle will then automatically load the CSS into the page. You can use https://github.com/webpack/extract-text-webpack-plugin to split your bundles in JS and CSS. |
webpack-loader knows nothing about react or even webpack. It just reads a manifest file and render <script> and/or tags for URLs found in the file. It would work if you made browserify or even rails sprockets generate a valid manifest file. |
That is the simplest solution for most cases, yes but you are not limited to it. |
This looks like your |
Thanks for you helpful comments. I added publicPath: '/static' to webpack config and now it indeed starts with /static/main-etc in the index.html However my css is still not appearing in my pages..., so what else is wrong? So regarding question 4, you mention: "JS bundle will then automatically load the CSS into the page". How are CSS files included in the JS bundle? By importing them in index.js ? |
Yes, by importing them as if they were JS modules. This would be a better question to ask in the webpack community as you'd get better answers there. You should also read this: https://webpack.github.io/docs/stylesheets.html |
Ok, so the css is included in the bundle, but how is the bundle loaded into my Django html templates? |
|
Works now. Seems the "import '../star-rating';"; was causing problems somehow... Furthermore I left out the "publicPath: '/static' " to make it work. |
I spend a lot of time on setting it up (following amongst others your post here):
http://owaislone.org/blog/webpack-plus-reactjs-and-django/
, tackling several minor issues:
Update blog post with latest docs #22
Still it is not working 'as expected'. Part of the problem is I do not exactly know what to expect. The purposes of separating Django world from JS (webpack) world seems sensible to me. But the exact separation is not clear and not working for me. My background is mainly the Django world in which I could get JS and CSS working from a staticfolder. I am not -until recently- very familiar with the npm, webpack, js world of things and I do have a couple of questions that when answered might shed some light on the problems I'm having:
Here is my config:
//Webpack.config.js
//index.html
//assets/js/index.js
//head_css.html
//settings/common.py
The text was updated successfully, but these errors were encountered: