K
K
Kilila2018-05-02 00:57:25
gulp.js
Kilila, 2018-05-02 00:57:25

How to speed up the assembly and minification of js scripts?

There are four js files: two of them are third-party, two are written by hand. The minification speed of the final file is always the same - 20 seconds, how can I reduce it?
Here is the required part of the code in the hapfile:

var gulp =  require("gulp"),
    concat = require("gulp-concat"),
    uglify = require("gulp-uglifyjs");

gulp.task("auto-scripts", function() {
  return gulp.src([
    "app/public/vendors/jquery/jquery.min.js",
    "app/public/vendors/ckeditor/ckeditor.js"
    ])
  .pipe(concat("auto-scripts.js"))
  .pipe(gulp.dest("app/public/meta/js"))
})

gulp.task("hand-scripts", function() {
  return gulp.src([
    "app/public/js/application.js",
    "app/public/meta/js/script.js"
    ])
  .pipe(concat("hand-scripts.js"))
  .pipe(gulp.dest("app/public/meta/js"))
});

gulp.task("scripts", ["auto-scripts", "hand-scripts"], function() {
  return gulp.src([
    "app/public/meta/js/auto-scripts.js",
    "app/public/meta/js/hand-scripts.js"
    ])
  .pipe(concat("scripts.min.js"))
  .pipe(uglify())
  .pipe(gulp.dest("app/public/meta/js"))
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2018-05-02
@Kilila

  1. No need to rebuild vendors for every sneeze.
    There are two scripting modes - development and production.
    In development mode, you do not rebuild vendors with a watcher, include two files in html (conditionally vendor.js and main.js), generate source maps, and do not minify the code.
    When everything is ready, you assemble a build for the site - glue everything into one file, minify the code, disable source maps.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question