How to use gulp-sourcemaps

Comprehensive gulp-sourcemaps code examples:

How to use gulp-sourcemaps.mapSources:

882
883
884
885
886
887
888
889
890
891
result = result
    .pipe(tscFilesTracker)
    .pipe(sourcemaps.init())
    .pipe(tsc())
    .pipe(
        sourcemaps.mapSources(function (sourcePath, file) {
            let tsFileName = path.basename(file.path).replace(/js$/, 'ts');
            const qualifiedSourcePath = path.dirname(file.path).replace('out/', 'src/').replace('out\\', 'src\\');
            if (!fs.existsSync(path.join(qualifiedSourcePath, tsFileName))) {
                const tsxFileName = path.basename(file.path).replace(/js$/, 'tsx');

How to use gulp-sourcemaps.init:

21
22
23
24
25
26
27
28
29
30
31
 */
function wxss(wxssFileList) {
  if (!wxssFileList.length) return false


  return gulp.src(wxssFileList, {cwd: srcPath, base: srcPath})
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.init()))
    .pipe(gulpif(wxssConfig.less, less({paths: [srcPath]})))
    .pipe(rename({extname: '.wxss'}))
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.write('./')))
    .pipe(_.logger(wxssConfig.less ? 'generate' : undefined))

How to use gulp-sourcemaps.write:

24
25
26
27
28
29
30
31
32
33
34


  return gulp.src(wxssFileList, {cwd: srcPath, base: srcPath})
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.init()))
    .pipe(gulpif(wxssConfig.less, less({paths: [srcPath]})))
    .pipe(rename({extname: '.wxss'}))
    .pipe(gulpif(wxssConfig.less && wxssConfig.sourcemap, sourcemaps.write('./')))
    .pipe(_.logger(wxssConfig.less ? 'generate' : undefined))
    .pipe(gulp.dest(distPath))
}