Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option for turn off source maps applying #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ gulp.task('default', () =>
);
```

Example with option for switch off source map applying. (pass false as 2nd parameter after babel options)

```js
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const concat = require('gulp-concat');

gulp.task('default', () =>
gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/preset-env']
}, false))
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
);
```


## Babel Metadata

Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function replaceExtension(fp) {
return path.extname(fp) ? replaceExt(fp, '.js') : fp;
}

module.exports = function (opts) {
module.exports = function (opts, applySourceMaps = true) {
opts = opts || {};

return through.obj(function (file, enc, cb) {
Expand Down Expand Up @@ -44,7 +44,11 @@ module.exports = function (opts) {
if (res) {
if (file.sourceMap && res.map) {
res.map.file = replaceExtension(file.relative);
applySourceMap(file, res.map);
if (applySourceMaps) {
applySourceMap(file, res.map);
} else {
file.sourceMap = res.map;
}
}

file.contents = Buffer.from(res.code);
Expand Down