Skip to content

letolab/django-webpack-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-webpack-loader

Join the chat at https://gitter.im/owais/django-webpack-loader


NOTE: This is very very new. Do not use in proudction yet.


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 and lets you use the generated bundles in django.



Configuration

Assumptions

Assuming assets/ is in settings.STATICFILES_DIRS like

STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'assets'), )

Assuming your webpack config lives at `./assets/webpack.config.js` and looks like this
module.exports = { context: __dirname, entry: { app: './js/index' output: { path: require("path").resolve('./assets/bundles/'), filename: "[name]-[hash].js", }, plugins: [ new BundleTracker({filename: './assets/webpack-stats.json'}) ] } 

Default Configuration

WEBPACK_LOADER = { 'BASE_URL': 'webpack_bundles/', 'STATS_FILE': 'webpack-stats.json', 'POLL_DELAY': 0.5, 'IGNORE': ['.+\.hot-update.js', '.+\.map'] }

WEBPACK_BUNDLE_URL
WEBPACK_LOADER = { 'BASE_URL': STATIC_URL + 'bundles/' }

BASE_URL is used to build the complete public url to the bundle that is used in <script> or <link> tags.

If the bundle generates a file called main-cf4b5fab6e00a404e0c7.js, then with the above config, the <script> tag will look like this

<script type="text/javascript" src="/assets/bundles/main-cf4b5fab6e00a404e0c7.js"/>

STATS_FILE
WEBPACK_LOADER = { 'STATS_FILE': os.path.join(BASE_DIR, 'assets/webpack-stats.json') }

STATS_FILE is the filesystem path to the file generated by webpack-bundle-tracker plugin. If you initialize webpack-bundle-tracker plugin like this

new BundleTracker({filename: './assets/webpack-stats.json'})

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


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.


Usage

Templates
{% load render_bundle from webpack_loader %} {{ render_bundle 'main' }}

render_bundle will render the proper <script> and <link> tags needed in your template.


Enjoy your webpack with django :)

About

Transparently use webpack with django

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 80.3%
  • JavaScript 14.9%
  • HTML 4.3%
  • Other 0.5%