|
|
@@ -1,8 +1,9 @@
|
|
|
# django-webpack-loader
|
|
|
|
|
|
-[](https://gitter.im/owais/django-webpack-loader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
|
-[](https://travis-ci.org/owais/django-webpack-loader)
|
|
|
-[](https://coveralls.io/github/owais/django-webpack-loader?branch=master)
|
|
|
+[](https://circleci.com/gh/django-webpack/django-webpack-loader/tree/master)
|
|
|
+[](https://coveralls.io/github/django-webpack/django-webpack-loader?branch=master)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
<br>
|
|
|
|
|
|
@@ -16,18 +17,10 @@ Django webpack loader consumes the output generated by [webpack-bundle-tracker](
|
|
|
|
|
|
A [changelog](CHANGELOG.md) is also available.
|
|
|
|
|
|
-## Maintainers
|
|
|
-In order to overcome the lack of support for Markdown on PyPi, building this package can use [pandoc](http://pandoc.org/installing.html) along with [pypandoc](https://pypi.python.org/pypi/pypandoc) to convert the README.md into a Restructured Text format compatible with PyPI. This requires installing `pandoc` for your operating system (installation instructions on the pandoc site), and `pypandoc` which will be installed if you:
|
|
|
-
|
|
|
- pip install -r requirements-dev.txt
|
|
|
-
|
|
|
-before uploading to PyPI.
|
|
|
-
|
|
|
-If pandoc or pypandoc fails, the README.md file will be uploaded as it was before this enhancement.
|
|
|
|
|
|
## Compatibility
|
|
|
|
|
|
-Test cases cover Django>=1.6 on Python 2.7 and Python>=3.4. 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.
|
|
|
+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
|
|
|
@@ -98,7 +91,8 @@ WEBPACK_LOADER = {
|
|
|
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
|
|
|
'POLL_INTERVAL': 0.1,
|
|
|
'TIMEOUT': None,
|
|
|
- 'IGNORE': ['.+\.hot-update.js', '.+\.map']
|
|
|
+ 'IGNORE': [r'.+\.hot-update.js', r'.+\.map'],
|
|
|
+ 'LOADER_CLASS': 'webpack_loader.loader.WebpackLoader',
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
@@ -134,6 +128,8 @@ If the bundle generates a file called `main-cf4b5fab6e00a404e0c7.js` and your ST
|
|
|
<script type="text/javascript" src="/static/output/bundles/main-cf4b5fab6e00a404e0c7.js"/>
|
|
|
```
|
|
|
|
|
|
+**NOTE:** If your webpack config outputs the bundles at the root of your `staticfiles` dir, then `BUNDLE_DIR_NAME` should be an empty string `''`, not `'/'`.
|
|
|
+
|
|
|
<br>
|
|
|
|
|
|
#### STATS_FILE
|
|
|
@@ -162,7 +158,7 @@ and your webpack config is located at `/home/src/webpack.config.js`, then the va
|
|
|
|
|
|
#### POLL_INTERVAL
|
|
|
|
|
|
-`POLL_INTERVAL` is the number of seconds webpack_loader should wait between polling the stats file. The stats file is polled every 100 miliseconds by default and any requests to are blocked while webpack compiles the bundles. You can reduce this if your bundles take shorter to compile.
|
|
|
+`POLL_INTERVAL` is the number of seconds webpack_loader should wait between polling the stats file. The stats file is polled every 100 milliseconds by default and any requests to are blocked while webpack compiles the bundles. You can reduce this if your bundles take shorter to compile.
|
|
|
|
|
|
**NOTE:** Stats file is not polled when in production (DEBUG=False).
|
|
|
|
|
|
@@ -174,6 +170,40 @@ and your webpack config is located at `/home/src/webpack.config.js`, then the va
|
|
|
|
|
|
<br>
|
|
|
|
|
|
+#### LOADER_CLASS
|
|
|
+
|
|
|
+`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.loader.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.
|
|
|
+
|
|
|
+Here's a simple example of loading from an external url:
|
|
|
+
|
|
|
+```py
|
|
|
+# in app.module
|
|
|
+import requests
|
|
|
+from webpack_loader.loader import WebpackLoader
|
|
|
+
|
|
|
+class ExternalWebpackLoader(WebpackLoader):
|
|
|
+
|
|
|
+ def load_assets(self):
|
|
|
+ url = self.config['STATS_URL']
|
|
|
+ return requests.get(url).json()
|
|
|
+
|
|
|
+
|
|
|
+# in app.settings
|
|
|
+WEBPACK_LOADER = {
|
|
|
+ 'DEFAULT': {
|
|
|
+ 'CACHE': False,
|
|
|
+ 'BUNDLE_DIR_NAME': 'bundles/',
|
|
|
+ 'LOADER_CLASS': 'app.module.ExternalWebpackLoader',
|
|
|
+ # Custom config setting made available in WebpackLoader's self.config
|
|
|
+ 'STATS_URL': 'https://www.test.com/path/to/stats/',
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+<br>
|
|
|
|
|
|
## Usage
|
|
|
<br>
|
|
|
@@ -258,7 +288,7 @@ WEBPACK_LOADER = {
|
|
|
{% render_bundle 'main' config='DASHBOARD' extension='css' %}
|
|
|
|
|
|
<!-- add some extra attributes to the tag -->
|
|
|
- {% render_bundle 'main' 'js' 'DEFAULT' attrs='async chatset="UTF-8"'%}
|
|
|
+ {% render_bundle 'main' 'js' 'DEFAULT' attrs='async charset="UTF-8"'%}
|
|
|
</body>
|
|
|
</head>
|
|
|
```
|
|
|
@@ -384,3 +414,14 @@ Then in your base jinja template:
|
|
|
|
|
|
|
|
|
Enjoy your webpack with django :)
|
|
|
+
|
|
|
+# Alternatives to Django-Webpack-Loader
|
|
|
+
|
|
|
+_Below are known projects that attempt to solve the same problem:_
|
|
|
+
|
|
|
+Note that these projects have not been vetted or reviewed in any way by me.
|
|
|
+These are not recommendation.
|
|
|
+Anyone can add their project to this by sending a PR.
|
|
|
+
|
|
|
+* [Django Manifest Loader](https://github.com/shonin/django-manifest-loader)
|
|
|
+* [Python Webpack Boilerplate](https://github.com/AccordBox/python-webpack-boilerplate)
|