You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-4Lines changed: 65 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,11 +83,15 @@ WEBPACK_LOADER = {
83
83
}
84
84
```
85
85
86
-
For that setup, we're using the `DEBUG` variable provided by Django when bootstraping a new project. Since in a production environment (`DEBUG = False`) the files won't constantly change, we can safely cache the results and optimize our flow by only fetching the files once.
86
+
For that setup, we're using the `DEBUG` variable provided by Django when bootstraping a new project. 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 pnwards, 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.
87
+
> If `CACHE=True`, any changes made in the assets files will only be read when the web workers are restarted.
87
88
88
-
During development, when files change a lot, we want to always poll for the updated files (in our case, we'll fetch the files every 0.1s, as defined on `POLL_INTERVAL`).
89
+
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`).
90
+
> In production (`DEBUG=False`), we'll only fetch the stats file once, so `POLL_INTERVAL` is ignored.
89
91
90
-
`django-webpack-loader` will look for the output file produced by `webpack-bundle-tracker`. Since on Webpack we've named it `webpack-stats.json` and stored it on the project root, we must replicate that setting on the back-end side.
92
+
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.
93
+
94
+
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.
91
95
92
96
`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.
93
97
@@ -229,8 +233,65 @@ qwe
229
233
</html>
230
234
```
231
235
236
+
### Multiple Webpack projects
237
+
Version 1.0 and up of `django-webpack-loader` also supports multiple Webpack configurations. The following configuration defines 2 Webpack stats files in settings and uses the `config` argument in the template tags to influence which stats file to load the bundles from.
If you need the URL to an asset without the HTML tags, the `get_files` template tag can be used. A common use case is specifying the URL to a custom css file for a Javascript plugin.
278
+
279
+
`get_files` works exactly like `render_bundle` except it returns a list of matching files and lets you assign the list to a custom template variable. For example:
280
+
281
+
```HTML+Django
282
+
{% get_files 'editor' 'css' as editor_css_files %}
0 commit comments