F
F
freeman02042016-05-29 16:10:34
gulp.js
freeman0204, 2016-05-29 16:10:34

How to make 2 files through gulp, connect the libraries in a separate file and the common.js file?

If you just connect all the js files and connect, then custom scripts do not work. It is necessary to connect jikveri. But the jiquery is in a linked file with libraries and custom scripts in the same place, but it doesn’t work that way. It is necessary that the jivery be connected first.
Now I have all plugins, libraries and custom scripts in my js folder.
My task

gulp.task('js', function() {
  return gulp.src('frontend/assets/js/*.js')
    .pipe(concat('all.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('public/js'));
});

How to make 2 files through gulp, connect the libraries in a separate file and the common.js file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2016-05-29
@freeman0204

Perhaps I didn’t quite understand your question, how cleverly and wisely you asked it, but for example, I send everything to builds in the form of 2 files: main.js and vendor.js, in principle, the same thing with styles. As for the task, here is an example of my own (library is not important):

// ~ Compile JS ~
var jsFilter = gulpFilter('**/*.js');

// Concat vendor JS (uglify for production)
gulp.task('js:vendor', function() {
    gulp.src(mainBowerFiles({
          "overrides": {
              "jquery": {
                  "main": "./dist/jquery.min.js"
              },

              "bootstrap": {
                  "main": "./dist/js/bootstrap.min.js"
              },

              "magnific-popup": {
                  "main": "./dist/jquery.magnific-popup.min.js"
              }
          }
  }))
      .pipe(jsFilter)
      .pipe(concat('vendor.js'))
      .pipe(gulpIf(env !== 'dev', uglify()))
      .pipe(gulp.dest(outputDir + 'js'))
});

// Concat own JS (uglify for production)
gulp.task('js', function() {
    gulp.src(src.js)
        .pipe(jsHint())
        .pipe(jsHint.reporter('default'))
        .pipe(concat('script.js'))
        .pipe(gulpIf(env !== 'dev', uglify()))
        .pipe(gulp.dest(outputDir + 'js'))
        .pipe(connect.reload());
});

I make settings depending on the production or development version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question