Skip to content
Open
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
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
[![Build Status](https://travis-ci.org/owais/django-webpack-loader.svg?branch=master)](https://travis-ci.org/owais/django-webpack-loader)
[![Coverage Status](https://coveralls.io/repos/owais/django-webpack-loader/badge.svg?branch=master&service=github)](https://coveralls.io/github/owais/django-webpack-loader?branch=master)

<br>

Read http://owaislone.org/blog/webpack-plus-reactjs-and-django/ for a detailed step by step guide on setting up webpack with django using this library.

<br>


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


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.


<br>
## Compatibility

Test cases cover Django>=1.6 on Python 2.7 and Python>=3.3. 100% code coverage is the target so we can be sure everything works anytime. It should probably work on older version of django as well but the package does not ship any test cases for them.
Expand All @@ -29,10 +28,10 @@ npm install --save-dev webpack-bundle-tracker
pip install django-webpack-loader
```

<br>

## Configuration

<br>

### Assumptions

Assuming `BASE_DIR` in settings refers to the root of your django app.
Expand All @@ -52,7 +51,6 @@ STATICFILES_DIRS = (
)
```

<br>
Assuming your webpack config lives at `./webpack.config.js` and looks like this
```javascript
var path = require("path");
Expand All @@ -74,7 +72,6 @@ module.exports = {
```


<br>
### Default Configuration
```python
WEBPACK_LOADER = {
Expand All @@ -88,7 +85,6 @@ WEBPACK_LOADER = {
}
```

<br>

#### CACHE
```python
Expand All @@ -100,7 +96,6 @@ WEBPACK_LOADER = {
```
When `CACHE` is set to True, webpack-loader will read the stats file only once and cache the result. This means web workers need to be restarted in order to pick up any changes made to the stats files.

<br>

#### BUNDLE_DIR_NAME
```python
Expand All @@ -119,7 +114,6 @@ If the bundle generates a file called `main-cf4b5fab6e00a404e0c7.js` and your ST
<script type="text/javascript" src="/static/output/bundles/main-cf4b5fab6e00a404e0c7.js"/>
```

<br>

#### STATS_FILE
```python
Expand All @@ -138,24 +132,21 @@ new BundleTracker({filename: './webpack-stats.json'})

and your webpack config is located at `/home/src/webpack.config.js`, then the value of `STATS_FILE` should be `/home/src/webpack-stats.json`

<br>

#### IGNORE
`IGNORE` is a list of regular expressions. If a file generated by webpack matches one of the expressions, the file will not be included in the template.

<br>

#### POLL_INTERVAL

`POLL_INTERVAL` is the number of seconds webpack_loader should wait between polling the stats file. The stats file is polled every 200 miliseconds by default and any requests to are blocked while webpack compiles the bundles. You can reduce this if your bundles take shorter to compile.

**NOTE:** Stats file is not polled when in production (DEBUG=False).

<br>


## Usage
<br>


#### Manually run webpack to build assets.

Expand Down Expand Up @@ -199,8 +190,6 @@ INSTALLED_APPS = (
</head>
```

<br>


#### Multiple webpack projects

Expand Down Expand Up @@ -261,8 +250,6 @@ CKEDITOR.config.contentsCss = '{{ editor_css_files.0.publicPath }}';
```


<br>

## How to use in Production

**It is up to you**. There are a few ways to handle this. I like to have slightly separate configs for production and local. I tell git to ignore my local stats + bundle file but track the ones for production. Before pushing out newer version to production, I generate a new bundle using production config and commit the new stats file and bundle. I store the stats file and bundles in a directory that is added to the `STATICFILES_DIR`. This gives me integration with collectstatic for free. The generated bundles are automatically collected to the target directory and synched to S3.
Expand Down Expand Up @@ -292,8 +279,6 @@ if not DEBUG:
})
```

<br><br>


You can also simply generate the bundles on the server before running collectstatic if that works for you.

Expand Down Expand Up @@ -326,7 +311,6 @@ Then in your base jinja template:
```

--------------------
<br>


Enjoy your webpack with django :)