gulp maintain same destination path as in the source

331 views Asked by At

I have a below angular folder structure . I want to uglify/minify the js and html files. Finally I want the same folder structure is maintained in the "build" folder. How can I do this in gulp?

client<folder>
    views<folder> 
        index.html
        app.js
        home <folder>
            home.js
            home.html
        page1<folder>
            page1.js
            page1.html
        page2<folder>
            page2.js
            page2.html
        page3<folder>
            page3.js
            page3.html

Thanks

1

There are 1 answers

0
Danscho On

Take a look at the provided code

var gulp = require('gulp');
var uglify = require('gulp-uglify'); //uglifies your JavaScript
var minify = require('gulp-htmlmin'); //minifies your HTML

gulp.task('build', ['uglify', 'copyHTML'], function() {});

gulp.task('copyHTML', function() {
    return gulp.src('client/**/*.html')
        .pipe(minify({ collapseWhitespace: true })
        .pipe(gulp.dest('dist/'));
});

gulp.task('uglify', function() {
    return gulp.src('client/**/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('dist/'));
});

Additional info: gulp-uglify, gulp-htmlmin