N
N
nonamer_city2022-02-14 09:16:51
Bootstrap
nonamer_city, 2022-02-14 09:16:51

How to add jquery and bootstrap to gulp?

Greetings.
Tell me how to add js files from bootstrap and jquery?
I import them in js file

import  "jquery/dist/jquery"
import "../../node_modules/popper.js/dist/umd/popper"
import "../../node_modules/bootstrap/dist/js/bootstrap.bundle"


my gulp config looks like this
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const watch = require('gulp-watch');

const sass = require('gulp-sass')(require('sass'));
const autoprefixer = require('gulp-autoprefixer');
const sourcemap = require('gulp-sourcemaps')
const pug = require('gulp-pug')
const del = require('del')

gulp.task('pug', (callback) => {
    return gulp.src('./src/pug/pages/**/*.pug')
        .pipe(pug({
            pretty: true
        }))
        .pipe(gulp.dest('./build/'))
        .pipe(browserSync.stream())
    callback()
})


gulp.task('scss', (callback) => {
    return gulp.src('./src/scss/style.scss')
        .pipe(sourcemap.init())
        .pipe(sass())
        .pipe(autoprefixer({
            overrideBrowserslist: ['last 4 versions']
        }))
        .pipe(sourcemap.write())
        .pipe(gulp.dest('./build/css/'))
        .pipe(browserSync.stream())
    callback()
});

gulp.task('cleanbuild', () => {
    return del('./build')
})

gulp.task('copyimg', (callback) => {
    return gulp.src('./src/img/**/*.*')
        .pipe(gulp.dest('./build/img/'))
    callback()
})

gulp.task('copyjs', (callback) => {
    return gulp.src('./src/js/**/*.*')
        .pipe(gulp.dest('./build/js/'))
    callback()
})

gulp.task('watch', () => {
    watch(['./build/js/**/*.*', './build/img/**/*.*'], gulp.parallel(browserSync.reload))
    watch(['./src/scss/**/*.scss'], gulp.parallel('scss'))
    watch(['./src/pug/**/*.pug'], gulp.parallel('pug'))
    watch(['./src/img/**/*.*'], gulp.parallel('copyimg'))
    watch(['./src/js/**/*.*'], gulp.parallel('copyjs'))
});



gulp.task('server', () => {
    browserSync.init({
        server: {
            baseDir: "./build/"
        }
    });
});

gulp.task('default',
    gulp.series(
        gulp.parallel('cleanbuild'),
        gulp.parallel('scss', 'pug', 'copyimg', 'copyjs'),
        gulp.parallel('server', 'watch')
    )
);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
black1277, 2022-02-14
@black1277

You need to use the webpack project builder Gulp and webpack - how and why to make friends with build systems...
As an alternative, you can try a combination of rollup and babel plugins

B
bondarenkoIlya, 2022-02-14
@bondarenkoIlya

Like this one can do

// libs to css

gulp.task('css', function () {
  return gulp.src([
    'node_modules/normalize.css/normalize.css',
    'node_modules/slick-carousel/slick/slick.css'
  ])
    .pipe(concat('_libs.scss'))
    .pipe(gulp.dest('app/scss'))
    .pipe(browserSyns.reload({ stream: true }))
});

// js

gulp.task('js', function () {
  return gulp.src([
    'node_modules/slick-carousel/slick/slick.js'
  ])
    .pipe(concat('libs.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('app/js'))
    .pipe(browserSyns.reload({ stream: true }))
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question