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.
First, install gulp-sourcemaps-identity
as a development dependency:
npm i -D gulp-sourcemaps-identity
Then, add it to your gulpfile.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'))
Options may be passed as properties in an object to the jsonlint
function. The following are their defaults:
ensureMappings({
filter: undefined,
verbose: false
})
filter
: when set to a function, if the function returnstrue
, the file and its source map will be processed, otherwise they will be skippedverbose
: when set totrue
, status of each processed file will be printed on the console, otherwise only warnings and errors will be printed
// if sources include various types, process only scripts
filter(file) {
return file.relative.endsWith('.js')
}
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
Copyright (C) 2022 Ferdinand Prantl
Licensed under the MIT License.