G
G
Gagatyn2020-12-15 16:44:58
Django
Gagatyn, 2020-12-15 16:44:58

How to set up gulp tasks on a django project?

There is a layout built with gulp.
At startup , the py manage.py runserverproject starts, but styles, pictures are not loaded (404).

I saw on the Internet that they do the runserver task with exec . Runserver is added to browserSync and in my case the watcher object is told to watch js, css and template.

After running the gulp command, the error is .

How to set up gulp tasks to follow html/css and django project files?

const gulp = require("gulp");
const exec = require('child_process').exec;
const browserSync = require('browser-sync').create();

gulp.task('runserver', function () {
    let proc = exec('python manage.py runserver')
});

gulp.task('browserSync', ['runserver'], function () {
    browserSync.init({
        notify: false,
        port: 8000,
        proxy: 'localhost:8000'
    })
});

const server = (done) => {
    sync.init({
        server: {
            baseDir: 'build'
        },
        cors: true,
        notify: false,
        ui: false,
    });
    done();
}

const watcher = () => {
    gulp.watch("src/sass/**/*.scss", {
        delay: 500
    }, gulp.series("styles"));
    gulp.watch("src/*.html", {
        delay: 500
    }, gulp.series("copyHtml"));
    gulp.watch("build/*.html").on("change", sync.reload);
    gulp.watch("src/js/*.js", {
        delay: 500
    }, gulp.series("js"));
// тут:
    gulp.watch('s/static/scss/**/*.scss', ['styles']);
    gulp.watch('s/static/css/**/*.css');
    gulp.watch('s/static/js/**/*.js', browserSync.reload);
    gulp.watch('s/templates/**/*.html', browserSync.reload);
}

const build = gulp.series(
    clean,
    styles,
    images,
    copyHtml,
    js
);

exports.default = gulp.series(
    build, server, watcher
);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question