gulp-concat - box js-code in already available



  • There was a need to insert the jquery code in the circumference:

    $(document).ready(function(){
        <код>
    })
    

    In principle, it is possible to do all this through a process of content, where the first and last file will have the lines of this function:

    gulp.task('concat-js', function() {
        return gulp.src(['path/jquery-a.js', 'myscripts/**/*.js', 'path/jquery-a.js'])
        .pipe(concat('main.js'))
        .pipe(gulp.dest('app/dist/js'));
    })
    

    Where:

    /jquery-a.js
    $(document).ready(function(){
    

    /jquery-b.js
    })

    Obviously, this is the worst bicycle and there must be a rational solution.



  • It was easy enough, even funny:
    Set. https://www.npmjs.com/package/gulp-insert and we're doing the dishes:

    gulp.task('jquerry-wrap', function() {
        return gulp.src('<файл в который надо добавить обертку>')
        .pipe(insert.wrap('$(document).ready(function(){', '})'))
        .pipe(gulp.dest('<директория с тем же файлом>'));
    })
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2