Skip to content

Conversation

MrP01
Copy link

@MrP01 MrP01 commented Apr 6, 2021

In my fork of django-webpack-loader, there is a bit of added functionality, cleaned up code, etc. Primarily, the new webpack versions are supported and the concept of entrypoint-based resource management.

I maintain the PyPi package django-webpack5-loader.

Purpose of this Fork

This package aims not only to support webpack 4 and 5, introduce additional loading of entrypoints in templates,
but also adds a framework for structuring django projects into pages using webpack_loader.contrib.pages.
See below.

The initial webpack 4 port was made possible thanks to

  • Svetoslav Dekov
  • Ali Farouk
  • Nikolaus Piccolotto

apart from the original package author Owais Lone.

owais and others added 30 commits August 6, 2016 07:38
…sts-to-webpack4

Chore/update tests to webpack4
# Conflicts:
#	README.md
#	webpack_loader/config.py
#	webpack_loader/utils.py
@MrP01
Copy link
Author

MrP01 commented Apr 17, 2021

Webpack 5 works quite differently than webpack 3, indeed. The 'constant' assets are much more focused around the entrypoints. It makes a lot of sense, as a Django dev trying to shield themselves from JS complications, to include the full entrypoint in their page. Since including chunks can have dependencies on other chunks. Webpack changes, but that's great isn't it? :)

With entrypoints, one simply defines an entrypoint for a page and include it automatically, by just referencing e.g. the "index" entrypoint once. That can of course also include CSS.

You can however, still include the chunks manually. When using the common SplitChunks optimization, this can be painful.

So I think in order to only include webpack chunks, the npm package webpack-bundle-tracker requires no change.
For this merge request, anyone can use webpack4-bundle-tracker, which already has this functionality (also works for webpack 5). A respective pull request and update would be a great idea I think.

@fjsj
Copy link
Member

fjsj commented Apr 22, 2021

@owais I like the idea of shielding Django and facilitating the integration with JS build systems. IMO that definitely that can be a long term goal for the project.

I'm studying how entrypoints work and I'll give a feedback here.

@andersk
Copy link

andersk commented Apr 30, 2021

My view is that there is no need for a separate render_entrypoint directive. We should instead modify the existing render_bundle to take an entry point and load every chunk in that entry point’s chunk group. It is entry points that are the user-facing concept, and chunks that are the webpack implementation detail, not the other way around. It makes no sense to load a specific chunk from a chunk group that has multiple chunks (unless you have a trivial non-optimizing webpack configuration where each entry point has a chunk group with exactly one chunk of the same name, in which case it makes no difference).

The main webpack-bundle-tracker already works with Webpack 5 and exposes the necessary information about entry points/chunk groups. This was added in django-webpack/webpack-bundle-tracker#53 and released in webpack-bundle-tracker 1.0.0-alpha.1. All that’s missing is support in django-webpack-loader (#232).

@fjsj
Copy link
Member

fjsj commented Apr 30, 2021

@andersk yes, thanks for this input, that's what I'm thinking as well. We're checking this PR and the related open ones and we'll merge soon.

@MrP01
Copy link
Author

MrP01 commented May 1, 2021

I think so too, the whole point of keeping the bundle functionality was not breaking existing implementations. Therefore, I kept it entirely separated. I don't use it and with webpack 4 or 5 I wouldn't know loads of applications to that for Django devs, even though they are still possible.

@rvlb
Copy link
Contributor

rvlb commented May 3, 2021

Hi @MrP01 and @owais, we (me and @fjsj) have opted for proceeding with the merging of #232. We'll do it tomorrow and we'll release a new version to ensure compatibility with webpack-bundle-tracker@1.0.0-alpha.1.

As it was mentioned above, #232 changes the render_bundle implementation instead of creating a separate render_entrypoint for a similar purpose. We think that's the best approach, because it means supporting webpack-bundle-tracker, instead of changing to webpack4-bundle-tracker.

We see there are additional changes like tests in this PR that can be useful, but it would be best to address them in another PR.
We'll let you know here once we release the compatibility with webpack-bundle-tracker@1.0.0-alpha.1. Once the compatibility is there, could you please open a new PR with the additional changes this PR has?

If you can't do it, please let us know too and we'll try to prepare a new PR with those commits.

# Conflicts:
#	.circleci/config.yml
#	.gitignore
#	README.md
#	examples/hot-reload/templates/home.html
#	examples/hot-reload/webpack.config.js
#	examples/simple/webpack.config.js
#	requirements-dev.txt
#	setup.py
#	tests/app/tests/test_webpack.py
#	tests/assets/js/index2.jsx
#	tests/db.sqlite3
#	tests/package.json
#	tests/requirements/common.txt
#	tests/requirements/django18.txt
#	tests/requirements/django31.txt
#	tests/requirements/django32.txt
#	tests/tox.ini
#	tests/webpack.config.app2.js
#	tests/webpack.config.error.js
#	tests/webpack.config.gzipTest.js
#	tests/webpack.config.simple.js
#	tests/webpack.config.split.js
#	webpack_loader/__init__.py
#	webpack_loader/loader.py
@fjsj fjsj removed their assignment Jul 15, 2021
@MrP01
Copy link
Author

MrP01 commented May 14, 2022

Since multiple entrypoints seem supported in the new version, I'm closing this - thank you for the initial support.

For the webpack_loader.contrib.pages functionality, take a look at django-webpack-pages.

@MrP01 MrP01 closed this May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants