Skip to content

Commit

Permalink
Add make test & development documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rangelfinal committed Nov 24, 2023
1 parent f203814 commit 2da193e
Show file tree
Hide file tree
Showing 12 changed files with 9,907 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- run:
name: JS deps
command: cd tests && yarn
command: cd tests && npm ci
- save_cache:
paths:
- ./npm
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ requirements = -r requirements-dev.txt

all: install build

@activate_venv = . $(ENV)/bin/activate
@check_if_venv_active = $(shell python -c 'import sys; print ("1" if sys.prefix != sys.base_prefix else "0")')
@activate_venv_if_not_active = $(if $(filter 1,$(check_if_venv_active)),$(activate_venv),)

clean:
@echo "Cleaning..."
@find webpack_loader/ -name '*.pyc' -delete
@rm -rf ./build ./*egg* ./.coverage ./dist

build: clean
@$(activate_venv_if_not_active)
@echo "Building..."
@pip install -U setuptools
@python setup.py sdist bdist_wheel --universal
Expand All @@ -25,6 +30,12 @@ install:
@echo "Installing build dependencies"
@[ ! -d $(ENV)/ ] && python3 -m venv $(ENV)/ || :
@$(ENV)/bin/pip install $(requirements)
@cd tests; npm i

test:
@$(activate_venv_if_not_active)
@echo "Running tests..."
@cd tests; coverage run manage.py test

publish: build
@echo "Publishing to $(REPOSITORY)..."
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ The `STATS_FILE` parameter represents the output file produced by `webpack-bundl

- `LOADER_CLASS` is the fully qualified name of a python class as a string that holds the custom webpack loader. This is where behavior can be customized as to how the stats file is loaded. Examples include loading the stats file from a database, cache, external url, etc. For convenience, `webpack_loader.loaders.WebpackLoader` can be extended. The `load_assets` method is likely where custom behavior will be added. This should return the stats file as an object.

- `WEBPACK_CHUNK_URL_USE_PUBLIC_PATH` (Default: `True`) is a flag that enables using the webpack's [publicPath](https://webpack.js.org/guides/public-path/) config as the chunk URL. Setting this to false may be useful if you are using both publicPath and a S3Storage with a custom domain.

- `SKIP_COMMON_CHUNKS` is a flag which prevents already generated chunks from being included again in the same page. This should only happen if you use more than one entrypoint per Django template (multiple `render_bundle` calls). By enabling this, you can get the same default behavior of the [HtmlWebpackPlugin](https://webpack.js.org/plugins/html-webpack-plugin/). The same caveats apply as when using `skip_common_chunks` on `render_bundle`, see that section below for more details.

Here's a simple example of loading from an external url:
Expand Down Expand Up @@ -436,6 +438,26 @@ In order to use `django-webpack-loader>=1.0.0`, you must ensure that `webpack-bu

This is necessary because the formatting of `webpack-stats.json` that `webpack-bundle-tracker` outputs has changed starting at version `1.0.0-alpha.1`. Starting at `django-webpack-loader==1.0.0`, this is the only formatting accepted here, meaning that other versions of that package don't output compatible files anymore, thereby breaking compatibility with older `webpack-bundle-tracker` releases.

## Development

This project includes a Makefile that provides several useful commands for building, installing, and publishing the project.

### Available Commands

- `clean`: Removes generated files and directories.
- `build`: Cleans the project and builds the distribution packages.
- `test`: Run the tests.
- `install`: Installs the project's build dependencies. Will initialize a virtual environment if one does not exist.
- `publish`: Builds the distribution packages and publishes them to the specified repository.
- `register`: Registers the package on the specified repository.

To execute a command, run `make <command>` in the project's root directory.

### Virtual Environment Settings

- `ENV`: The name of the virtual environment. (Default: `venv`)
- `REPOSITORY`: The repository to publish the distribution packages to. (Default: `pypi`)

## Commercial Support

[![alt text](https://avatars2.githubusercontent.com/u/5529080?s=80&v=4 "Vinta Logo")](https://www.vinta.com.br/)
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage==5.5
twine==3.4.1
Django==3.2.23
django-jinja==2.10.2
Expand Down

0 comments on commit 2da193e

Please sign in to comment.