192.gulp-concat插件合并多个文件
因为在网页的开发中,为了加快网页渲染的速度,如果我们的js文件比较多的话,就可以使用gulp-concat插件,将多个js文件合并成一个文件,该插件的安装同样是在终端窗口执行命令:npm install gulp-concat --save-dev.
示例代码如下(1):
var gulp = require('gulp'); var concat = require('concat'); var uglify = require('uglify'); gulp.task('js', function() { gulp.src(['./js/index.js', './js/nav.js']) //将文件合并成一个index.js文件 .pipe(concat('index.js')) // 将文件进行丑化处理 .pipe(uglify({ 'toplevel':true, 'compress': { 'drop_console': true, 'drop_debugger': true, } })) //为文件进行重命名 .pipe(rename({'suffix': '.min'})) .pipe(gulp.dest('./dist/js/')) });
示例代码如下(2):
var gulp = require('gulp'), uglify = require('gulp-uglify'), rename = require('gulp-rename'), concat = require('gulp-concat'), pipeline = require('readable-stream').pipeline; gulp.task('js02', function() { return pipeline( gulp.src(['./js/index.js','./js/nav.js']), concat('index.js'), //压缩主要是依靠uglify()函数; uglify(), rename({ 'suffix': '.min', }), gulp.dest('./dist/js/') ) });
相关推荐
MrLiar 2015-11-09
idnochinese 2019-07-01
UndefineOrNull 2019-07-01
星辰的笔记 2020-07-04
zhongweinan 2020-06-10
liangjielaoshi 2020-06-11
jiangfulai 2020-04-18
UndefineOrNull 2020-02-29
UndefineOrNull 2020-03-01
hlihaihong 2020-02-18
UndefineOrNull 2020-02-12
yinuoqingqin 2020-01-13
星辰的笔记 2020-01-13
UndefineOrNull 2020-01-13
hlihaihong 2020-01-13
kaosini 2020-01-12
hlihaihong 2020-01-12
kaosini 2020-01-12