Skip to content

Commit 48f9e6e

Browse files
committed
Updated tests, docs and examples.. and some minor fixes
1 parent 3929600 commit 48f9e6e

File tree

14 files changed

+74
-75
lines changed

14 files changed

+74
-75
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ target/
6060
.ropeproject/
6161

6262
examples/**/ve/
63+
examples/**/venv/
6364
examples/**/node_modules/
6465
examples/**/assets/bundles/
6566
examples/**/assets/webpack-stats.json
@@ -71,3 +72,4 @@ tests/venv3/
7172
tests/node_modules/
7273
tests/assets/bundles/
7374
tests/webpack-stats.json
75+
tests/webpack-stats-app2.json

README.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,6 @@ and your webpack config is located at `/home/src/webpack.config.js`, then the va
148148
149149
One of the core principles of django-webpack-loader is to not manage webpack itself in order to give you the flexibility to run webpack the way you want. If you are new to webpack, check one of the [examples](https://github.com/owais/django-webpack-loader/tree/master/examples), read [my detailed blog post](http://owaislone.org/blog/webpack-plus-reactjs-and-django/) or check [webpack docs](http://webpack.github.io/).
150150
151-
#### Multiple webpack projects
152-
153-
It is possible to manage multiple webpack projects by adding extra entries in `WEBPACK_LOADER` as follows:
154-
155-
```python
156-
WEBPACK_LOADER = {
157-
'DEFAULT': {
158-
'BUNDLE_DIR_NAME': 'bundles/',
159-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
160-
},
161-
'APP2': {
162-
'BUNDLE_DIR_NAME': 'bundles/',
163-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-app2.json'),
164-
}
165-
}
166-
```
167151
168152
#### Settings
169153
@@ -202,29 +186,42 @@ INSTALLED_APPS = (
202186
</head>
203187
```
204188
205-
`render_bundle` third argument (defaults to `'DEFAULT'`) tells which `WEBPACK_LOADER` project contains the bundle. For example, to render bundles from several projects just define your `WEPACK_LOADER` like this,
189+
<br>
190+
191+
192+
#### Multiple webpack projects
193+
194+
Version 2.0 and up of 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.
206195
207196
```python
208197
WEBPACK_LOADER = {
209-
'APP1': {
210-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-app1.json'),
198+
'DEFAULT': {
199+
'BUNDLE_DIR_NAME': 'bundles/',
200+
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
211201
},
212-
'APP2': {
213-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-app2.json'),
202+
'DASHBOARD': {
203+
'BUNDLE_DIR_NAME': 'dashboard_bundles/',
204+
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats-dashboard.json'),
214205
}
215206
}
216207
```
217208
218-
then use `render_bundle` as follows
219-
220209
```HTML+Django
221210
{% load render_bundle from webpack_loader %}
222211
223212
<html>
224213
<body>
225214
....
226-
{% render_bundle 'main' 'js' 'APP1'%}
227-
{% render_bundle 'main' 'js' 'APP2'%}
215+
{% render_bundle 'main' 'js' 'DEFAULT' %}
216+
{% render_bundle 'main' 'js' 'DASHBOARD' %}
217+
218+
<!-- or render all files from a bundle -->
219+
{% render_bundle 'main' config='DASHBOARD' %}
220+
221+
<!-- the following tags do the same thing -->
222+
{% render_bundle 'main' 'css' 'DASHBOARD' %}
223+
{% render_bundle 'main' extension='css' config='DASHBOARD' %}
224+
{% render_bundle 'main' config='DASHBOARD' extension='css' %}
228225
</body>
229226
</head>
230227
```

examples/code-splitting/app/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BUNDLE_DIR_NAME': 'bundles/',
112-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
111+
'DEFAULT': {
112+
'BUNDLE_DIR_NAME': 'bundles/',
113+
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json')
114+
}
113115
}

examples/code-splitting/webpack-stats.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/hot-reload/app/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BUNDLE_DIR_NAME': 'bundles/',
112-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
111+
'DEFAULT': {
112+
'BUNDLE_DIR_NAME': 'bundles/',
113+
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json')
114+
}
113115
}

examples/hot-reload/webpack-stats.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/simple/app/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BUNDLE_DIR_NAME': 'bundles/',
112-
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
111+
'DEFAULT': {
112+
'BUNDLE_DIR_NAME': 'bundles/',
113+
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json')
114+
}
113115
}

examples/simple/webpack-stats.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/app/tests/test_webpack.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from django_jinja.builtins import DEFAULT_EXTENSIONS
1212
from django.views.generic.base import TemplateView
1313

14-
from webpack_loader.utils import get_config, get_assets, get_bundle, WebpackException
14+
from webpack_loader.utils import get_assets, get_config, get_bundle, WebpackException
15+
from webpack_loader.errors import BAD_CONFIG_ERROR
1516

1617

1718
BUNDLE_PATH = os.path.join(settings.BASE_DIR, 'assets/bundles/')
@@ -42,12 +43,7 @@ def test_config_check(self):
4243
'STATS_FILE': 'webpack-stats.json',
4344
}):
4445
errors = webpack_cfg_check(None)
45-
expected_errors = [Error(
46-
'Error while parsing WEBPACK_LOADER configuration',
47-
hint='Is WEBPACK_LOADER config compliant with the new format?',
48-
obj='django.conf.settings.WEBPACK_LOADER',
49-
id='django-webpack-loader.E001',
50-
)]
46+
expected_errors = [BAD_CONFIG_ERROR]
5147
self.assertEqual(errors, expected_errors)
5248

5349
with self.settings(WEBPACK_LOADER={
@@ -102,7 +98,7 @@ def test_templatetags(self):
10298
self.assertIn('<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet"/>', result.rendered_content)
10399
self.assertIn('<script type="text/javascript" src="/static/bundles/main.js"></script>', result.rendered_content)
104100

105-
self.assertIn('<link type="text/css" href="/static/bundles/styles-app2.css" rel="stylesheet">', result.rendered_content)
101+
self.assertIn('<link type="text/css" href="/static/bundles/styles-app2.css" rel="stylesheet"/>', result.rendered_content)
106102
self.assertIn('<script type="text/javascript" src="/static/bundles/app2.js"></script>', result.rendered_content)
107103
self.assertIn('<img src="/static/my-image.png"/>', result.rendered_content)
108104

@@ -151,7 +147,7 @@ def test_reporting_errors(self):
151147
#TODO:
152148
self.compile_bundles('webpack.config.error.js')
153149
try:
154-
get_bundle('main', DEFAULT_CONFIG)
150+
get_bundle('main', get_config(DEFAULT_CONFIG))
155151
except WebpackException as e:
156152
self.assertIn("Cannot resolve module 'the-library-that-did-not-exist'", str(e))
157153

tests/webpack-stats-app2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)