Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

opbeat/django-assets-bundles

Repository files navigation

Assets in Django with gulp as a pipeline

This is the approach we use on Opbeat.com. In gulp it uses the ```gulp-asset-manifest```_ module. In Django, it uses custom template tags to load the manifest.

We use it for JS and CSS, in this example it’s some JS library files.

gulpfile.js

gulp.task('prepare-scripts', function() {
   gulp.src('static/js/libs/*.js')
        .pipe(concat('libs.min.js'))
        .pipe(uglify())
        .pipe(rev())
        .pipe(assetManifest({
            bundleName: 'lib_js',
            manifestFile: 'assets/asset_manifest.json',
            log: true,
            pathPrepend: CACHED_DIR
        }))
        .pipe(gulp.dest(CACHED_DIR));
});

asset_manifest.json

{
    "lib_js": [
        "static/build/cached/libs.min-69896a86.js"
    ],
}

template.html

{% load assets_url %}

{% do_asset "lib_js" %}
    <script type="text/javascript" src="{{ ASSET_URL }}" charset="utf-8" crossorigin></script>
{% end_do_assets %}

result.html

<script type="text/javascript" src="/static/build/cached/libs.min-69896a86.js" charset="utf-8" crossorigin></script>

About

Assets in Django (Work in progress)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages