S
S
Stanislav2015-08-06 23:53:02
Node.js
Stanislav, 2015-08-06 23:53:02

Gulp, how to save directories after minifying files?

Tell me how to save directories when minifying files.
For example, there are two directories:

./static/ajax/
./static/ajax/created/

I want to collect all the files in the ./static/ajax/ folder, merge them and move them to the folder with the ./static/build/build.min.js file
And move the files from the ./static/ajax/created/ folder to the ./ folder static/build/created/created.min.js
At the moment, I have merged the files in the ./static/ajax/ folder, but with another folder, I don’t understand what to do
var gulp		= require('gulp')
  , jshint	= require('gulp-jshint')
    , concat    = require('gulp-concat')
  , rename    = require('gulp-rename')
  , uglify    = require('gulp-uglify');

var paths = {
  "js"		: ['./static/ajax/*.js', './static/ajax/created/*.js'],
  "jsIn"		: './static/build', 
  "jsName"	: 'build.js',
  "jsNameMin"	: 'build.min.js'
};

/*	Листинг файлов
------------------------------------------------------------------------------------------------------------------------*/
gulp.task('lint', function() {
  gulp.src(paths.js)
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

/*	Конкатенация и минификация файлов
------------------------------------------------------------------------------------------------------------------------*/
gulp.task('minify', function(){
    gulp.src(paths.js)
        .pipe(concat(paths.jsName))
        .pipe(gulp.dest(paths.jsIn))
        .pipe(rename(paths.jsNameMin))
        .pipe(uglify())
        .pipe(gulp.dest(paths.jsIn));
});

/*	Действия по умолчанию
------------------------------------------------------------------------------------------------------------------------*/
gulp.task('default', function(){
  gulp.run('lint', 'minify');

  // Слежка за файлами
  gulp.watch(paths.js, function(event){
    gulp.run('lint', 'minify');
  });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lnked, 2015-08-07
@ms-dred

would this bike fit?

var paths = {
    "js": {
        "ajax": {
            "src": "./static/ajax/*.js",
            "build": "build.js",
            "dist": "./static/build"
        },
        "created": {
            "src": "./static/created/*.js",
            "build": "created.js",
            "dist": "./static/build/created"
        }
    }
}


function doit(dir)
{
    var item = paths.js[dir];

    /*  Листинг файлов
    ------------------------------------------------------------------------------------------------------------------------*/
    gulp.task('lint', function() {
        gulp.src(item.src)
            .pipe(jshint())
            .pipe(jshint.reporter('default'));
    });

    /*  Конкатенация и минификация файлов
    ------------------------------------------------------------------------------------------------------------------------*/
    gulp.task('minify', function(){
        gulp.src(item.src)
            .pipe(concat(item.build))
            .pipe(gulp.dest(item.dist))
            .pipe(rename({suffix: '.min'}))
            .pipe(uglify())
            .pipe(gulp.dest(item.dist))
    });

    gulp.run('lint', 'minify');
}

gulp.task('make', function(){
    for (var dir in paths.js)
    {
        doit( dir );
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question