I
I
itsjustmypage2016-09-09 12:48:55
Building projects
itsjustmypage, 2016-09-09 12:48:55

How do you port frontend dependencies when building in Gulp?

How do you transfer your NPM dependencies and their components from the node_modules folder to a hypothetical /vendors folder when building a front-end project? Any external files, such as jQuery and Bootstrap, to transfer only what is needed, automating the process as much as possible for the future.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2016-09-09
@ptrvch

I use Bower for the frontend, but it doesn't change the essence

var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

var paths = {
    srcLibs = [ 
        'bower/angular/angular.min.js',
        'bower/angular-translate/angular-translate.min.js',
        ...
        ],
    srcApp = [
        'app/app.js',
        'app/auth/AuthFactory.js',
        ...
        ]
}

gulp.task('libsbundle', function() {
    return  gulp.src(paths.srcLibs)
        .pipe(concat('lib.js'))
        .pipe(gulp.dest('build/'))
});

gulp.task('app', function() {
    return gulp.src(paths.srcApp)
        .pipe(concat('app.js'))
        // минимизация для продакшн
        //.pipe(uglify()) 
        .pipe(gulp.dest('build/'))
});

gulp.task('watch', function() {
    gulp.watch(paths.srcApp, ['app']);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question