Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
gulp-sourcemaps
Advanced tools
The gulp-sourcemaps package is a plugin for Gulp that allows you to generate source maps for your files. Source maps are files that map from the transformed source to the original source, enabling you to debug your code more easily by seeing the original source in your browser's developer tools.
Initialize Source Maps
This feature initializes the source map generation process. The `sourcemaps.init()` method is called before any transformations are applied to the files, and `sourcemaps.write('.')` writes the source maps to the same directory as the transformed files.
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function () {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
Write Inline Source Maps
This feature writes the source maps inline within the transformed files. The `sourcemaps.write()` method without any arguments will embed the source map directly into the output file.
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function () {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
Custom Source Map Path
This feature allows you to specify a custom path for the source maps. The `sourcemaps.write('../maps')` method writes the source maps to a directory named 'maps' that is one level up from the output directory.
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function () {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('dist'));
});
The gulp-sourcemap package is another plugin for generating source maps in Gulp. It is similar to gulp-sourcemaps but is less popular and has fewer features. It is a simpler alternative for basic source map generation needs.
The gulp-babel package is primarily used for transpiling JavaScript using Babel, but it also has built-in support for generating source maps. It is a good choice if you are already using Babel for transpilation and want to generate source maps as part of the same process.
The gulp-uglify package is used for minifying JavaScript files. It can also generate source maps for the minified files. It is useful if you want to combine minification and source map generation in a single step.
Package | gulp-sourcemaps |
Description | Write source maps |
Node Version | ≥ 0.9 |
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('javascript', function() {
gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
All plugin between sourcemaps.init()
and sourcemaps.write()
need to support source maps.
inline
By default the source maps are inlined. Pass false
to write separate files.
includeContent
By default the source maps include the source code. Pass false
to use the original files.
sourceRoot
Set the path where the source files are hosted (use this when includeContent
is set to false
).
file
by calling file.applySourceMap(sourceMap)
.
This combines the source map of this plugin with the source maps coming from plugins further up the chain.var through = require('through2');
var myTransform = require('myTransform');
module.exports = function(options) {
function transform(file, encoding, callback) {
// generate source maps if plugin source-map present
if (file.sourceMap) {
options.makeSourceMaps = true;
}
// do normal plugin logic
var result = myTransform(file.contents, options);
file.contents = new Buffer(result.code);
// apply source map to the chain
if (file.sourceMap) {
file.applySourceMap(result.map);
}
this.push(file);
callback();
}
return through.obj(transform);
};
FAQs
Sourcemap support for gulpjs.
The npm package gulp-sourcemaps receives a total of 453,582 weekly downloads. As such, gulp-sourcemaps popularity was classified as popular.
We found that gulp-sourcemaps demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.