Skip to content

Commit 4911d04

Browse files
committed
Release 0.0.6:
* Breaking changes: Instead of defining a BASE_URL, webpack loader now expects BUNDLE_DIR_NAME. `BUNDLE_DIR_NAME` refers to the directory that is added to STATICFILES_DIRS and contains the webpack output directory.
1 parent f68c0ec commit 4911d04

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Read http://owaislone.org/blog/webpack-plus-reactjs-and-django/ for a detailed s
99

1010
<br>
1111

12-
Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.
12+
Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.
1313

1414

1515
Django webpack loader consumes the output generated by [webpack-bundle-tracker](https://github.com/owais/webpack-bundle-tracker) and lets you use the generated bundles in django.
@@ -41,9 +41,11 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4141

4242
<br>
4343
Assuming `assets/` is in `settings.STATICFILES_DIRS` like
44+
45+
STATIC_ASSETS = os.path.join(BASE_DIR, 'assets')
4446
```python
4547
STATICFILES_DIRS = (
46-
os.path.join(BASE_DIR, 'assets'),
48+
STATIC_ASSETS,
4749
)
4850
```
4951

@@ -71,7 +73,7 @@ module.exports = {
7173
### Default Configuration
7274
```python
7375
WEBPACK_LOADER = {
74-
'BASE_URL': 'webpack_bundles/',
76+
'BUNDLE_DIR_NAME': 'webpack_bundles/', # must end with slash
7577
'STATS_FILE': 'webpack-stats.json',
7678
'POLL_DELAY': 0.2,
7779
'IGNORE': ['.+\.hot-update.js', '.+\.map']
@@ -80,19 +82,19 @@ WEBPACK_LOADER = {
8082
8183
<br>
8284
83-
#### WEBPACK_BUNDLE_URL
85+
#### BUNDLE_DIR_NAME
8486
```python
8587
WEBPACK_LOADER = {
86-
'BASE_URL': STATIC_URL + 'bundles/'
88+
'BUNDLE_DIR_NAME': 'bundles/' # end with slash
8789
}
8890
```
8991
90-
`BASE_URL` is used to build the complete public url to the bundle that is used in `<script>` or `<link>` tags.
92+
`BUNDLE_DIR_NAME` refers to the dir in which webpack outputs the bundles. It should not be the full path. If `./assets` it one of you static dirs and webpack generates the bundles in `./assets/output/bundles/`, then `BUNDLE_DIR_NAME` should be `output/bundles/`.
9193
92-
If the bundle generates a file called `main-cf4b5fab6e00a404e0c7.js`, then with the above config, the `<script>` tag will look like this
94+
If the bundle generates a file called `main-cf4b5fab6e00a404e0c7.js` and your STATIC_URL is `/static/`, then the `<script>` tag will look like this
9395
9496
```html
95-
<script type="text/javascript" src="/assets/bundles/main-cf4b5fab6e00a404e0c7.js"/>
97+
<script type="text/javascript" src="/static/output/bundles/main-cf4b5fab6e00a404e0c7.js"/>
9698
```
9799
98100
<br>
@@ -166,17 +168,16 @@ module.exports = config;
166168
`settings.py`
167169
```python
168170
if not DEBUG:
169-
WEBPACK_LOADER['BASE_URL'] = STATIC_URL + '/dist'
170-
WEBPACK_LOADER.update({
171-
'BASE_URL': STATIC_URL + '/dist',
172-
'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats-prod.json'
173-
})
171+
WEBPACK_LOADER.update({
172+
'BUNDLE_DIR_NAME': 'dist/',
173+
'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats-prod.json'
174+
})
174175
```
175176
176177
<br><br>
177178
178179
179-
You can also simply generate the bundles on the server before running collectstatic if that works for you.
180+
You can also simply generate the bundles on the server before running collectstatic if that works for you.
180181
181182
182183
--------------------

examples/code-splitting/app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BASE_URL': STATIC_URL + 'bundles/',
111+
'BUNDLE_DIR_NAME': 'bundles/',
112112
'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats.json'),
113113
}

examples/hot-reload/app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BASE_URL': STATIC_URL + 'bundles/',
111+
'BUNDLE_DIR_NAME': 'bundles/',
112112
'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats.json'),
113113
}

examples/simple/app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@
108108
)
109109

110110
WEBPACK_LOADER = {
111-
'BASE_URL': STATIC_URL + 'bundles/',
111+
'BUNDLE_DIR_NAME': 'bundles/',
112112
'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats.json'),
113113
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name = 'django-webpack-loader',
44
packages = ['webpack_loader', 'webpack_loader/templatetags'], # this must be the same as the name above
5-
version = '0.0.5',
5+
version = '0.0.6',
66
description = 'Load your webpack bundles and chunks in django',
77
author = 'Owais Lone',
88
author_email = 'hello@owaislone.org',

webpack_loader/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import time
44

55
from django.conf import settings
6+
from django.contrib.staticfiles.storage import staticfiles_storage
67

78

89
__all__ = ('get_bundle',)
910

1011

1112
config = {
12-
'BASE_URL': 'webpack_bundles/',
13+
'BUNDLE_DIR_NAME': 'webpack_bundles/',
1314
'STATS_FILE': 'webpack-stats.json',
1415
# FIXME: Explore usage of fsnotify
1516
'POLL_INTERVAL': 0.1,
@@ -37,7 +38,8 @@ def filter_files(files):
3738
filename = F['name']
3839
ignore = any(regex.match(filename) for regex in ignores)
3940
if not ignore:
40-
F['url'] = '{}{}'.format(config['BASE_URL'], filename)
41+
relpath = '{}{}'.format(config['BUNDLE_DIR_NAME'], filename)
42+
F['url'] = staticfiles_storage.url(relpath)
4143
yield F
4244

4345

0 commit comments

Comments
 (0)