E
E
Enickckey2022-03-10 16:13:02
gulp.js
Enickckey, 2022-03-10 16:13:02

How to add gsap to gulp?

Greetings.
Tell me how to add gsap and exactly scrolltrigger to gulp?
Here is my build

const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const watch = require('gulp-watch');
const concatCss = require('gulp-concat-css');
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('copyfonts', (callback) => {
    return gulp.src('./src/fonts/**/*.*')
        .pipe(gulp.dest('./build/fonts/'))
    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','copyfonts'),
        gulp.parallel('server', 'watch')
    )
);


I have downloaded gsap.
But in main.js file when importing
import {gsap} from "gsap"
import {ScrollTrigger} from "gsap/ScrollTrigger.min.js"

I get this error
6229fc1d0566e855721570.jpeg
How do I import files correctly so that I can work with the library?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-10
@Seasle

Include in HTML only the one main.js, because gsapyou ScrollTriggerincluded it in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question