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
Add Webpack support #3623
Add Webpack support #3623
Conversation
9211163
to
0a4a691
Compare
Implemented this pull request in an existing project and it works like a charm. |
I was lying in my previous comment, I had to change |
Thanks for the feedback! Keep sending it in! |
Hi, there. Thanks for putting this together--very cool. I have one problem and a couple of questions, which may be related. I am using the implementation with Docker.
Thanks for putting this together and for all the work on this great project generally! Steve |
Ok, looks like the setup isn't working very well with Docker... I've mainly get it working on a project where Docker isn't used and was intending to test the Docker part in the coming days. I probably missed a few things.
You should access the dev server at localhost:3000, which goes to the node server. It serve static content, proxies requests to the Django server running at 8000 and do a hot reload when the static files change. At least that's how it's supposed to work. It's similar to how it works with Gulp.
Shouldn't be needed, the webpack config should build a |
Tried again the production deployment and it seems to work fine on my end.
@steveputman what option have you selected for |
@browniebroke I'm |
I just checked with Also, I think I just understood your question earlier "is there ever a need to load the cdn version of bootstrap" - it's included in the output, but it should not (I thought you were asking whether it was missing). |
I think it doesn't work without Whitenoise, because we should set the bail: true,
+ output: {
+ publicPath: 'https://yourbucketname.s3.amazonaws.com/static/webpack_bundles/',
+ }
}) In the Django config, this value configured using environment variables, ideally this value would come from the same ones. |
It does work with your change to And, yes, sorry I wasn't clear about the CDN version of Bootstrap: like you said, I was suggesting that it be deleted from |
That's a correct statement I think, although I see it more the other way around: S3 isn't needed for static files when Whitenoise is used. Not anymore right or wrong, just a different perspective 😄 PS: Thanks for testing this out and providing feedback. |
Point taken! Will try out Whitenoise. Thanks for all the help! |
6daacc6
to
7525def
Compare
7525def
to
d566190
Compare
66da3ed
to
121d4d3
Compare
{%- if cookiecutter.use_whitenoise == 'n' and cookiecutter.cloud_provider == 'AWS' %} | ||
const s3BucketName = process.env.DJANGO_AWS_STORAGE_BUCKET_NAME; | ||
const awsS3Domain = process.env.DJANGO_AWS_S3_CUSTOM_DOMAIN ? | ||
process.env.DJANGO_AWS_S3_CUSTOM_DOMAIN | ||
: `${s3BucketName}.s3.amazonaws.com`; | ||
const staticUrl = `https://${awsS3Domain}/static/`; | ||
{%- elif cookiecutter.use_whitenoise == 'n' and cookiecutter.cloud_provider == 'GCP' %} | ||
const staticUrl = `https://storage.googleapis.com/${process.env.DJANGO_GCP_STORAGE_BUCKET_NAME}/static/`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work currently with Docker, because the environment variables aren't set when this is config file is read (at build time).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are looking for a modern frontend solution based on Webpack for Django, I recommend you to check https://github.com/AccordBox/python-webpack-boilerplate
Thx
# Conflicts: # {{cookiecutter.project_slug}}/gulpfile.js
40a06a3
to
fca8311
Compare
I noticed that live reload isn't working with html changes. I fixed it by adding the following lines:
|
# Conflicts: # {{cookiecutter.project_slug}}/requirements/base.txt
760dd07
to
31c1462
Compare
I've done more testing this week-end locally and deploying to prod, and all seems to work apart from a small limitation with Docker, Webpack and no Whitenoise which I've now documented. I feel like the only to solve this would be to move to a single |
Good work @browniebroke, thanks! |
How do you cope with |
Not sure what you mean... Probably best to open an issue with more details about the error:
Thanks |
Description
This PR builds on top of #3535 to add a basic Webpack as an option for building front-end assets.
It does NOT introduce any FE framework like React, Vue or the likes but rather provide a basic config that should replicate most of what is currently provided by Gulp.
I want to thank @michael-yin for his work in #3106 as well as his series of blog posts which helped this massively. I adapted it to make sure the whole code is in here and fits our setup more closely.
Checklist:
Rationale
Support for Webpack has been a requested feature for a long time:
While Gulp works for simple cases, it's getting less attention recently in the JS community, and the recent activity on the Gulp GitHub repo indicates that the development efforts are reduced to a minimum.