-
Couldn't load subscription status.
- Fork 340
render_entrypoint tag #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e8b19f1
05df949
522be18
c12f42c
29ca185
8e57724
2a14570
e4c0a45
3eaee95
56dd1c6
f18738c
bad972b
83df98b
47c577d
88e49a6
a4db79f
883dea4
7206556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| venv/ | ||
| .DS_Store | ||
|
|
||
| # auto generated | ||
| README.rst | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,9 @@ WEBPACK_LOADER = { | |
| 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'), | ||
| 'POLL_INTERVAL': 0.1, | ||
| 'TIMEOUT': None, | ||
| 'IGNORE': [r'.+\.hot-update.js', r'.+\.map'] | ||
| 'IGNORE': [r'.+\.hot-update.js', r'.+\.map'], | ||
| 'EXCLUDE_RUNTIME': False, | ||
| 'BASE_ENTRYPOINT': '' | ||
| } | ||
| } | ||
| ``` | ||
|
|
@@ -166,6 +168,19 @@ and your webpack config is located at `/home/src/webpack.config.js`, then the va | |
|
|
||
| <br> | ||
|
|
||
| #### EXCLUDE_RUNTIME | ||
|
|
||
| `EXCLUDE_RUNTIME` is meant to be used with `render_entrypoint`. When creating multi-page applications, it's common to want to | ||
| split a single runtime file that is used by all chunks. You can do that by using `{% render_bundle 'runtime' %}` in your base HTML file and setting `EXCLUDE_RUNTIME` to `True` in order to not include it again when using `{% render_entrypoint 'example_entry_point' %}` | ||
|
|
||
| <br> | ||
|
|
||
| #### BASE_ENTRYPOINT | ||
|
|
||
| `BASE_ENTRYPOINT` is meant to be used with `render_entrypoint`. When creating multi-page applications, it's common to want to | ||
| include common js in the base HTML. If the main entrypoint's name is `main`, you can do that by including `{% render_entrypoint 'main' %}` in your base HTML file. Now in another entrypoints (that extend the base HTML file), there might be some chunks that were already included in `main`, that means they would be included twice in the final rendered HTML, to avoid that, set `BASE_ENTRYPOINT` to `'main'`, then any duplicate chunks between an entrypoint and the main entrypoint would be included only once. | ||
|
||
|
|
||
| <br> | ||
|
|
||
| ## Usage | ||
| <br> | ||
|
|
@@ -188,6 +203,8 @@ INSTALLED_APPS = ( | |
|
|
||
| ### Templates | ||
|
|
||
| #### render_bundle | ||
|
|
||
alihazemfarouk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ```HTML+Django | ||
| {% load render_bundle from webpack_loader %} | ||
|
|
||
|
|
@@ -212,6 +229,46 @@ INSTALLED_APPS = ( | |
| </head> | ||
| ``` | ||
|
|
||
| #### render_entrypoint (Available only when using Webpack v.4 or newer) | ||
|
|
||
| ```HTML+Django | ||
| {% load render_entrypoint from webpack_loader %} | ||
|
|
||
| {% render_entrypoint 'index' %} | ||
| ``` | ||
|
|
||
| `render_entrypoint` will render all the proper `<script>` and `<link>` tags needed in your template for that endpoint. | ||
| Using this, you can make use of webpack 4 code splitting features. | ||
| Example webpack config: | ||
| ```javascript | ||
| module.exports = { | ||
| ..., | ||
| entry: { | ||
| index: "./myapp/static/src/pages/index.js", | ||
| contact_us: "./myapp/static/src/pages/contact_us.js", | ||
| }, | ||
| ..., | ||
| plugins: [new BundleTracker({ filename: "./webpack-stats.json" })] | ||
| }; | ||
|
|
||
alihazemfarouk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| Just as `render_bundle`, `render_entrypoint` also takes a second argument which can be a file extension to match, and can be used in a similar way, | ||
|
|
||
| ```HTML+Django | ||
| {% load render_entrypoint from webpack_loader %} | ||
|
|
||
| <html> | ||
| <head> | ||
| {% render_entrypoint 'main' 'css' %} | ||
| </head> | ||
| <body> | ||
| .... | ||
| {% render_entrypoint 'main' 'js' %} | ||
| </body> | ||
| </head> | ||
| ``` | ||
|
|
||
| <br> | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "presets": ["@babel/preset-react"] | ||
| } |