An open API service indexing awesome lists of open source software.

https://github.com/prantlf/gulp-sourcemaps-identity

Gulp plugin for adding identity mappings to source maps with no mappings, handling JavaScript sources.
https://github.com/prantlf/gulp-sourcemaps-identity

gulp-plugin gulpplugin identity source-maps sourcemaps

Last synced: 11 months ago
JSON representation

Gulp plugin for adding identity mappings to source maps with no mappings, handling JavaScript sources.

Awesome Lists containing this project

README

          

# gulp-sourcemaps-identity

[![Latest version](https://img.shields.io/npm/v/gulp-sourcemaps-identity)
![Dependency status](https://img.shields.io/librariesio/release/npm/gulp-sourcemaps-identity)
](https://www.npmjs.com/package/gulp-sourcemaps-identity)
[![Code coverage](https://codecov.io/gh/prantlf/gulp-jsonlint/branch/master/graph/badge.svg)](https://codecov.io/gh/prantlf/gulp-sourcemaps-identity)

> [Gulp] plugin for adding identity mappings to source maps with no mappings, handling JavaScript sources.

Some gulp plugins may have troubles processing a source, which was just read from a file and not generated by a transpiler. The source map mappings will be empty in such case. This plugin will replace the empty string with mappings pointing every token to its original location. It will ensure *identity mappings*, but only *if no mappings have been included* and only *for JavaScript sources*.

## Usage

First, install `gulp-sourcemaps-identity` as a development dependency:

```sh
npm i -D gulp-sourcemaps-identity
```

Then, add it to your `gulpfile.js`:

```js
import gulp from 'gulp'
import sourcemaps from 'gulp-sourcemaps'
import { ensureMappings } from 'gulp-sourcemaps-identity'

gulp
.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(ensureMappings())
.pipe(sourcemaps.write('../dist', {
includeContent: false,
sourceRoot: '../dist'
}))
.pipe(gulp.dest('dist'))
```

## API

### ensureMappings(options)

Options may be passed as properties in an object to the `jsonlint` function. The following are their defaults:

```js
ensureMappings({
filter: undefined,
verbose: false
})
```

* `filter`: when set to a function, if the function returns `true`, the file and its source map will be processed, otherwise they will be skipped
* `verbose`: when set to `true`, status of each processed file will be printed on the console, otherwise only warnings and errors will be printed

```js
// if sources include various types, process only scripts
filter(file) {
return file.relative.endsWith('.js')
}
```

## Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

## License

Copyright (C) 2022 Ferdinand Prantl

Licensed under the [MIT License].

[MIT License]: http://en.wikipedia.org/wiki/MIT_License
[Gulp]: http://gulpjs.com/