原文来自:https://www.jianshu.com/p/e66395f40f3f
<pre>
功能描述
生成sourcemap文件(什么是sourcemap?请参考,简单讲就是文件压缩后不利于查看与调试,但是有了sourcemap,出错的时候,除错工具将直接显示原始代码,而不是转换后的代码)
插件安装
$ cnpm install gulp-sourcemaps --save-dev
使用方法
例1:生成JS文件的sourcemap
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps')
pump = require('pump');
gulp.task('jsmin', function(cb) {
pump([
gulp.src('src/js/*.js'),
sourcemaps.init(),
concat('demo.js'),
uglify(),
sourcemaps.write('.'),
gulp.dest('dist/js')
], cb)
});
例2:生成CSS文件的sourcemap
var gulp = require('gulp'),
minifyCss = require('gulp-clean-css'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps')
pump = require('pump');
gulp.task('jsmin', function(cb) {
pump([
gulp.src('src/css/*.css'),
sourcemaps.init(),
concat('demo.css'),
minifyCss(),
sourcemaps.write('.'),
gulp.dest('dist/js')
], cb)
});