L
L
Lev Yakovlev2022-02-16 13:03:19
Node.js
Lev Yakovlev, 2022-02-16 13:03:19

How to compile only those files that are used in a gulp project?

I have a prompt folder, which contains all the plugins and libraries for any occasion.
This folder is compiled into dist.

Question: how to compile only those plugins or libraries that are used at a particular moment in a gulp project?

I use minification for this folder, and so far this code has been written:

gulp.task('prompt', function () {
    return gulp.src('prompt/**/*.js')
        .pipe(uglifyEs())
        .pipe(gulp.dest('dist/prompt')),
    gulp.src('prompt/**/*.css')
        .pipe(csso())
        .pipe(gulp.dest('dist/prompt')),
    gulp.src(['prompt/**/*.*', '!prompt/**/*.css', '!prompt/**/*.js'])
        .pipe(gulp.dest('dist/prompt'));
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2022-02-16
@delphinpro

for any occasion.

well, why is that?
Put only the necessary packages from the same npm into the project and build them.
Use modern javascript to easily import packages.
Use babel to build.
npm install jquery
import $ from 'jquery';

$('.selector');

gulp.task('js', function () {
    return gulp.src('src/app.js')
        .pipe(babel())
        .pipe(terser()) // uglify устарел давно
        .pipe(gulp.dest('dist/js')),
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question