Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Integrate Webpack for Javascript builds #18

Closed
wants to merge 53 commits into from
Closed

Conversation

maltezacharias
Copy link
Contributor

@maltezacharias maltezacharias commented Jun 14, 2020

Fixes #17, builds on #21

General idea

Adds new Build process for Javascript
This PR implements a new way to handle Javascript resources in the application.
Javascript modules are written inside /frontend/src. A bundle is created for every module found directly in the src folder.

Django is enhanced with the webpack-loader, that provides a render bundle tag, which automatically loads the created bundles.

Production mode

During Docker build (docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --build) an intermediate frontend container is created, webpack is run, bundles are created and copied over to the final backend container. This way the finished container already has the bundles inside the image and no frontend container is needed.

Development mode

A frontend docker container is provided in the override file (used by docker-compose up --build) and continues to run a webpack instance, which watches for file-changes in the frontend/src folder. When changes are detected the JS bundles are rebuilt automatically

Make docker development great again
type=text/javascript has not been required in a long time already.
Time to stop using it
If really necessary could be done a lot more elegantly than this.
@maltezacharias maltezacharias requested a review from bjrne June 14, 2020 23:44
@maltezacharias maltezacharias marked this pull request as ready for review June 15, 2020 05:56
@maltezacharias maltezacharias requested a review from Baschdl June 15, 2020 05:56
@maltezacharias
Copy link
Contributor Author

@Baschdl this now based on easier-deploy branch

@maltezacharias maltezacharias added the blocked PRs or issues whose progress is blocked by other issues, PRs or people label Jun 27, 2020
@maltezacharias maltezacharias marked this pull request as draft June 27, 2020 18:12
@maltezacharias
Copy link
Contributor Author

Waiting for #21 to be merged

maltezacharias and others added 4 commits July 4, 2020 23:09
Frontend container is only necessary for development and once during build of the
production container. As we no longer have bind mounts in the production container
to the code outside we don't need to be able to recreate javascript bundle files
at runtime. These should be generated once when building the image and committed
to the docker image.

Moving the Dockerfile to the top-level allows for multi-stage
builds of the backend container enabling us to use a throwaway frontend container
to build a bundle and include this in the final backend container for a streamlined
production setup.

The separate frontend dockerfile is still included as this will
allow us to use it for local development and also possibly with a further override
file for bind mounting in a mixed development in production environment setup.
Removing the necessity for a frontend container for webpack.
Instead uses a multi-stage build and creates an intermediary
container in which the javascript bundles are built.

The created bundles are copied to the backend docker
during the build process and indexed. For production
frontend containers are no longer necessary and there
are no start-up-order issues anymore.

For development a frontend container is still used, as
webpack will watch and rebuild the bundle in development
mode as soon as a file is changed.

Co-authored-by: Kevin Yuan <[email protected]>
@maltezacharias maltezacharias marked this pull request as ready for review July 5, 2020 01:17
@maltezacharias maltezacharias changed the title 17 webpack js Integrate Webpack for Javascript builds Jul 5, 2020
@maltezacharias maltezacharias removed the blocked PRs or issues whose progress is blocked by other issues, PRs or people label Jul 8, 2020
@maltezacharias
Copy link
Contributor Author

Will recreate this on a new branch for improved reviewability

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JS] Implement webpack build process
5 participants