gulp-sourcemaps
Usage
Inline maps
Inline maps are embedded in the source file.
Example:
var gulp = ;var concat = ;var uglify = ;var sourcemaps = ; gulp;
All plugins between sourcemaps.init()
and sourcemaps.write()
need to support source maps.
External source map files
To write external source map files, pass a path relative to the destination to sourcemaps.write()
.
Example:
var gulp = ;var concat = ;var uglify = ;var sourcemaps = ; gulp;
Load existing source maps
To load existing source maps, pass the option loadMaps: true
to sourcemaps.init()
.
Example:
var gulp = ;var concat = ;var uglify = ;var sourcemaps = ; gulp;
Init Options
loadMaps
Set to true to load existing maps for source files. Supports the following:- inline source maps
- source map files referenced by a
sourceMappingURL=
comment - source map files with the same name (plus .map) in the same directory
Write Options
-
addComment
By default a comment containing / referencing the source map is added. Set this to
false
to disable the comment (e.g. if you want to load the source maps by header).Example:
gulp; -
includeContent
By default the source maps include the source code. Pass
false
to use the original files.Including the content is the recommended way, because it "just works". When setting this to
false
you have to host the source files and set the correctsourceRoot
. -
sourceRoot
Set the path where the source files are hosted (use this when
includeContent
is set tofalse
). This is an URL (or subpath) relative to the source map, not a local file system path. If you have sources in different subpaths, an absolute path (from the domain root) pointing to the source file root is recommended, or define it with a function.Example:
gulp;Example (using a function):
gulp;
Plugin developers only: How to add source map support to plugins
- Generate a source map for the transformation the plugin is applying
- Important: Make sure the paths in the generated source map (
file
andsources
) are relative tofile.base
(e.g. usefile.relative
). - Apply this source map to the vinyl
file
. E.g. by using vinyl-sourcemaps-apply. This combines the source map of this plugin with the source maps coming from plugins further up the chain.
Example:
var through = ;var applySourceMap = ;var myTransform = ; module { { // generate source maps if plugin source-map present if filesourceMap optionsmakeSourceMaps = true; // do normal plugin logic var result = ; filecontents = resultcode; // apply source map to the chain if filesourceMap ; this; ; } return through;};