码迷,mamicode.com
首页 > 其他好文 > 详细

gulp配置browserify多入口

时间:2015-12-14 20:58:17      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

需要 var es = require(‘event-stream‘);

gulp.task(‘browserify‘, function(){
    var files = [
        {
            fpath: ‘./js/main.js‘,
            fname: ‘main.js‘
        },
        {
            fpath: ‘./js/main2.js‘,
            fname: ‘main2.js‘
        }
    ];

    var tasks = files.map(function(entry){
        return browserify({ entries: [entry.fpath] })
        .bundle()
        .pipe(source(entry.fname))
        .pipe(buffer())
        .pipe(uglify())
        .pipe(rename({ extname: ‘.bundle.js‘ }))
        .pipe(gulp.dest(‘./dist/s/js‘));
    });
    
    return es.merge.apply(null, tasks);
});

 

附上完整 gulpfile.js 如下:

‘use strict‘;

var gulp = require("gulp"),
    browserify = require(‘browserify‘),
    source = require("vinyl-source-stream"),
    buffer = require(‘vinyl-buffer‘),
    less = require("gulp-less"),
    minifyCss = require(‘gulp-minify-css‘),
    uglify = require(‘gulp-uglify‘),
    rename = require(‘gulp-rename‘),
    es = require(‘event-stream‘),
    watchify = require(‘watchify‘);

gulp.task(‘less‘, function(){
    gulp.src(‘./less/*.less‘)
        .pipe(less())
        .pipe(minifyCss({
            advanced: false,
            compatibility: ‘ie7‘
        }))
        .pipe(gulp.dest(‘./dist/s/css‘));
});

gulp.task(‘browserify‘, function(){
    var files = [
        {
            fpath: ‘./js/main.js‘,
            fname: ‘main.js‘
        },
        {
            fpath: ‘./js/main2.js‘,
            fname: ‘main2.js‘
        }
    ];

    var tasks = files.map(function(entry){
        return browserify({ entries: [entry.fpath] })
        .bundle()
        .pipe(source(entry.fname))
        .pipe(buffer())
        .pipe(uglify())
        .pipe(rename({ extname: ‘.bundle.js‘ }))
        .pipe(gulp.dest(‘./dist/s/js‘));
    });
    
    return es.merge.apply(null, tasks);
});

gulp.task(‘watch‘, function(){
    gulp.watch(‘./less/*.less‘, [‘less‘]);
    gulp.watch(‘./js/**/*.js‘, [‘browserify‘]);
});

gulp.task(‘default‘, [‘less‘, ‘browserify‘]);

gulp.task(‘serve‘, [‘less‘, ‘browserify‘, ‘watch‘]);

 

gulp配置browserify多入口

标签:

原文地址:http://www.cnblogs.com/simpapaya/p/5046146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!