Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
venv/
.DS_Store

# auto generated
README.rst
Expand Down
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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': ''
}
}
```
Expand Down Expand Up @@ -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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate "When creating multi-page applications, it's common to want to
 include common js in the base HTML"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not by mistake. If you have a clearer way to explain it, please suggest it to me, or do it yourself and push it here


<br>

## Usage
<br>
Expand All @@ -188,6 +203,8 @@ INSTALLED_APPS = (

### Templates

#### render_bundle

```HTML+Django
{% load render_bundle from webpack_loader %}

Expand All @@ -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" })]
};

```

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>


Expand Down
1 change: 0 additions & 1 deletion examples/code-splitting/README.md

This file was deleted.

Empty file.
115 changes: 0 additions & 115 deletions examples/code-splitting/app/settings.py

This file was deleted.

25 changes: 0 additions & 25 deletions examples/code-splitting/app/urls.py

This file was deleted.

1 change: 0 additions & 1 deletion examples/code-splitting/app/views.py

This file was deleted.

16 changes: 0 additions & 16 deletions examples/code-splitting/app/wsgi.py

This file was deleted.

7 changes: 0 additions & 7 deletions examples/code-splitting/assets/js/app.jsx

This file was deleted.

Binary file removed examples/code-splitting/db.sqlite3
Binary file not shown.
10 changes: 0 additions & 10 deletions examples/code-splitting/manage.py

This file was deleted.

19 changes: 0 additions & 19 deletions examples/code-splitting/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions examples/code-splitting/requirements.txt

This file was deleted.

37 changes: 0 additions & 37 deletions examples/code-splitting/webpack.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions examples/hot-reload/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ module.exports = {
],

module: {
loaders: [
use: [
// we pass the output from babel loader to react-hot loader
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel'], },
{ test: /\.jsx?$/, exclude: /node_modules/, use: ['react-hot', 'babel-loader'], },
],
},

resolve: {
modulesDirectories: ['node_modules', 'bower_components'],
extensions: ['', '.js', '.jsx']
extensions: ['.css', '.js', '.jsx']
},
}
8 changes: 4 additions & 4 deletions examples/simple/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ module.exports = {
],

module: {
loaders: [
use: [
// we pass the output from babel loader to react-hot loader
{ test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel'], },
{ test: /\.jsx?$/, exclude: /node_modules/, use: [ 'babel-loader'], },
],
},

resolve: {
modulesDirectories: ['node_modules', 'bower_components'],
extensions: ['', '.js', '.jsx']
extensions: ['.css', '.js', '.jsx']
},
}
3 changes: 3 additions & 0 deletions tests/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-react"]
}
6 changes: 6 additions & 0 deletions tests/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
'CACHE': False,
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-app2.json'),
},
'EXCLUDE_RUNTIME': {
'CACHE': False,
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
'EXCLUDE_RUNTIME': True
}
}

Expand Down
Loading