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
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.
98
+
Note that you must set the path where you're keeping your static assets and Webpack bundles in `STATICFILES_DIRS`.
99
+
100
+
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 paths in memory. If `CACHE=False`, we'll always read the stats file to get the assets paths.
94
101
95
102
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 backend side.
The recommended apporach is to have a production pipeline that generates the frontend bundle along with the stats file during the **deployment phase**. We recommend keeping the generated bundles and the stats file outside the version control. In other words, add `webpack-stats.json` and `assets/bundles/` to your `.gitignore`.
169
+
The recommended apporach is to have a production pipeline that generates the frontend bundle along with the stats file during the **deployment phase**. We recommend keeping the generated bundles and the stats file outside the version control. In other words, add `webpack-stats.json` and `assets/webpack_bundles/` to your `.gitignore`.
163
170
164
-
A simple production deployment can use Django's own `collectstatic`. If Django is serving your static files, remember you must configure the `STATICFILES_DIRS`:
171
+
Assuming static files is properly configured using Django built-ins or something like [django-storages](https://django-storages.readthedocs.io/), a simple production deployment can use Django's own `collectstatic`. Remember the Django settings values of `STATICFILES_DIRS`, `BUNDLE_DIR_NAME`, `STATS_FILE`, and Webpack's `output.path` must all be compatible:
172
+
173
+
```javascript
174
+
// webpack.config.js
175
+
module.exports= {
176
+
// ...
177
+
context:__dirname,
178
+
output: {
179
+
// Emit bundle files at "assets/webpack_bundles/":
With `collectstatic` properly configured, you must first run your Webpack build in production-mode, then call`collectstatic`. For example, your deployment script should do something like this before (re)starting the Django webserver:
213
+
In your deployment script, you must first run your Webpack build in production-mode, before calling`collectstatic`:
@@ -192,6 +233,10 @@ However, production usage for this package is **fairly flexible**, as the entire
192
233
193
234
In case you wish to use [Dynamic Imports](https://webpack.js.org/guides/code-splitting/#dynamic-imports), please check out [this example](https://github.com/django-webpack/django-webpack-loader/tree/master/examples/dynamic-imports), in particular how [webpack.config.js](https://github.com/django-webpack/django-webpack-loader/blob/master/examples/dynamic-imports/webpack.config.js) is configured. The key is to set the `publicPath`.
194
235
236
+
### Extra options for `webpack-bundle-tracker`
237
+
238
+
Check `webpack-bundle-tracker`[README](https://github.com/django-webpack/webpack-bundle-tracker) for all supported options, such as relative paths, integrity hashes, timestamp logging, etc.
239
+
195
240
### Extra `WEBPACK_LOADER` settings in Django
196
241
197
242
Set those extra settings inside like this:
@@ -205,7 +250,7 @@ WEBPACK_LOADER = {
205
250
206
251
-`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
207
252
208
-
-`INTEGRITY`is flag enabling [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) on rendered `<script>`and`<link>` tags. Integrity hashis get from stats fileand configuration on side of `BundleTracker`, where configuration option `integrity: true`is required.
253
+
-`INTEGRITY`is flag enabling [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) on rendered `<script>`and`<link>` tags. Integrity hashis get from stats fileand configuration on side of `BundleTracker`, where [configuration option](https://github.com/django-webpack/webpack-bundle-tracker#options) `integrity: true` is required.
209
254
210
255
-`LOADER_CLASS`is the fully qualified name of a python classas a string that holds the custom Webpack loader. This is where behavior can be customized as to how the stats fileis loaded. Examples include loading the stats filefrom 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 fileas an object.
211
256
@@ -221,8 +266,6 @@ class ExternalWebpackLoader(WebpackLoader):
221
266
return requests.get(url).json()
222
267
```
223
268
224
-
-`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.
225
-
226
269
-`SKIP_COMMON_CHUNKS` (Default: `False`) 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.
227
270
228
271
### Rendering by file extension
@@ -309,7 +352,7 @@ The `suffix` option can be used to append a string at the end of the file URL. F
309
352
310
353
### Multiple Webpack configurations
311
354
312
-
`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:
355
+
`django-webpack-loader` also supports multiple Webpack configurations. Assuming you have different Webpack configs, each with a different `output.path`, 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:
0 commit comments