From 26b1968ed67dd90da7ef8823fdb3559e9b8b79b4 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Mon, 10 Apr 2023 14:04:06 +0000 Subject: automatic import of python-django-webpack-loader --- .gitignore | 1 + python-django-webpack-loader.spec | 1407 +++++++++++++++++++++++++++++++++++++ sources | 1 + 3 files changed, 1409 insertions(+) create mode 100644 python-django-webpack-loader.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..4479978 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/django-webpack-loader-1.8.1.tar.gz diff --git a/python-django-webpack-loader.spec b/python-django-webpack-loader.spec new file mode 100644 index 0000000..691d1ee --- /dev/null +++ b/python-django-webpack-loader.spec @@ -0,0 +1,1407 @@ +%global _empty_manifest_terminate_build 0 +Name: python-django-webpack-loader +Version: 1.8.1 +Release: 1 +Summary: Transparently use webpack with django +License: MIT License +URL: https://github.com/django-webpack/django-webpack-loader +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/aa/8d/3a7d689e56ad739a3234af47d2dd2bc22172d263233712e3b39c8246615d/django-webpack-loader-1.8.1.tar.gz +BuildArch: noarch + + +%description +# django-webpack-loader + +[![Build Status](https://circleci.com/gh/django-webpack/django-webpack-loader/tree/master.svg?style=svg)](https://circleci.com/gh/django-webpack/django-webpack-loader/tree/master) +[![Coverage Status](https://coveralls.io/repos/github/django-webpack/django-webpack-loader/badge.svg?branch=master)](https://coveralls.io/github/django-webpack/django-webpack-loader?branch=master) +![pyversions](https://img.shields.io/pypi/pyversions/django-webpack-loader) +![djversions](https://img.shields.io/pypi/djversions/django-webpack-loader) + + +Use webpack to generate your static bundles without django's staticfiles or opaque wrappers. + + +Django webpack loader consumes the output generated by [webpack-bundle-tracker](https://github.com/owais/webpack-bundle-tracker) and lets you use the generated bundles in django. + +A [changelog](CHANGELOG.md) is also available. + + +## Compatibility + +Test cases cover Django>=2.0 on Python>=3.5. 100% code coverage is the target so we can be sure everything works anytime. It should probably work on older version of django as well but the package does not ship any test cases for them. + + +## Install + +```bash +npm install --save-dev webpack-bundle-tracker + +pip install django-webpack-loader +``` + +## Configuration + +### Configuring `webpack-bundle-tracker` +Before configuring `django-webpack-loader`, let's first configure what's necessary on `webpack-bundle-tracker` side. Update your Webpack configuration file (it's usually on `webpack.config.js` in the project root). Make sure your file looks like this (adapt to your needs): + +```javascript +const path = require('path'); +const webpack = require('webpack'); +const BundleTracker = require('webpack-bundle-tracker'); + +module.exports = { + context: __dirname, + entry: './assets/js/index', + output: { + path: path.resolve('./assets/webpack_bundles/'), + filename: "[name]-[hash].js" + }, + plugins: [ + new BundleTracker({filename: './webpack-stats.json'}) + ], +} +``` + +The configuration above expects the `index.js` (the app entrypoint file) to live inside the `/assets/js/` directory (this guide going forward will assume that all front-end related files are placed inside the `/assets/` directory, with the different kinds of files arranged within its subdirectories). + +The generated compiled files will be placed inside the `/assets/webpack_bundles/` directory and the file with the information regarding the bundles and assets (`webpack-stats.json`) will be stored in the project root. + +### Compiling the front-end assets + +You must generate the front-end bundle using `webpack-bundle-tracker` before using `django-webpack-loader`. You can compile the assets and generate the bundles by running: + +```bash +npx webpack --config webpack.config.js --watch +``` + +This will also generate the stats file. You can also refer to how `django-react-boilerplate` configure the [package.json](https://github.com/vintasoftware/django-react-boilerplate/blob/master/package.json) scripts for different situations. + +> ⚠️ Hot reload is available through a specific config. Check [this section](#hot-reload). + +> ⚠️ This is the recommended usage for the development environment. For **usage in production**, please refer to [this section](#usage-in-production) + +### Configuring the settings file +First of all, add `webpack_loader` to `INSTALLED_APPS`. +```python +INSTALLED_APPS = ( + ... + 'webpack_loader', + ... +) +``` + +Below is the recommended setup for the Django settings file when using `django-webpack-loader`. + +```python +WEBPACK_LOADER = { + 'DEFAULT': { + 'CACHE': not DEBUG, + 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'), + 'POLL_INTERVAL': 0.1, + 'IGNORE': [r'.+\.hot-update.js', r'.+\.map'], + } +} +``` + +For that setup, we're using the `DEBUG` variable provided by Django. Since in a production environment (`DEBUG = False`) the assets files won't constantly change, we can safely cache the results (`CACHE=True`) and optimize our flow, as `django-webpack-loader` will read the stats file only once and store the assets files paths in memory. From that point onwards, it will use these stored paths as the source of truth. If `CACHE=False`, we'll always read the stats file to get the assets paths. +> ⚠️ If `CACHE=True`, any changes made in the assets files will only be read when the web workers are restarted. + +During development, when the stats file changes a lot, we want to always poll for its updated version (in our case, we'll fetch it every 0.1s, as defined on `POLL_INTERVAL`). +> ⚠️ In production (`DEBUG=False`), we'll only fetch the stats file once, so `POLL_INTERVAL` is ignored. + +While `CACHE` isn't directly related to `POLL_INTERVAL`, it's interesting to keep `CACHE` binded to the `DEBUG` logic value (in this case, the negation of the logic value) in order to only cache the assets in production, as we'd not continuously poll the stats file in that environment. + +The `STATS_FILE` parameter represents the output file produced by `webpack-bundle-tracker`. Since in the Webpack configuration file we've named it `webpack-stats.json` and stored it on the project root, we must replicate that setting on the back-end side. + +`IGNORE` is a list of regular expressions. If a file generated by Webpack matches one of the expressions, the file will not be included in the template. + +### Extra settings + +- `TIMEOUT` is the number of seconds webpack_loader should wait for webpack to finish compiling before raising an exception. `0`, `None` or leaving the value out of settings disables timeouts + +- `INTEGRITY` is flag enabling [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) on rendered `