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.
- Host: GitHub
- URL: https://github.com/prantlf/gulp-sourcemaps-identity
- Owner: prantlf
- License: mit
- Created: 2022-08-07T20:31:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-07T20:55:28.000Z (over 3 years ago)
- Last Synced: 2025-03-12T03:35:52.003Z (11 months ago)
- Topics: gulp-plugin, gulpplugin, identity, source-maps, sourcemaps
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gulp-sourcemaps-identity
[

](https://www.npmjs.com/package/gulp-sourcemaps-identity)
[](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/