Gulp V4 need advanced sourcemap settings
See original GitHub issueAs of new Gulp v4 I can get rid of gulp-sourcemaps plugin. As far as I know Gulp v4 uses its own sourcemap. I refactored my project to use Gulp v4 sourcemap, however I am missing advanced settings in sourcemap. I have following project structure:
├── dist
│ ├── app.bot.js
│ ├── app.bot.js.map
│ └── authorize
│ ├── authorize.js
│ └── authorize.js.map
├── gulpfile.js
├── package.json
├── package-lock.json
├── src
│ ├── app.bot.ts
│ └── authorize
│ └── authorize.ts
└── tsconfig.json
As you can see after typescript compilation all files that were in src/*.ts
goes into dist/*.js
.
Path from generated *.map
file to original *.ts
file is incorect. It is correct only for one nested level.
I need correct path for debug in VSCode.
E.g. path from app.bot.js.map
to app.bot.ts
is correct:
"sources":["../src/app.bot.ts"]
E.g. path from authorize.js.map
to authorize.ts
is invalid:
"sources":["../src/authorize/authorize.ts"]
With gulp-sourcemaps plugin I managed to do correct path as following:
const gulp = require('gulp');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const tsProject = ts.createProject('tsconfig.json');
const outputDir = './dist';
gulp.task('build', () => tsProject.src()
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(tsProject())
.js.pipe(sourcemaps.write('./', {
includeContent: false,
sourceRoot: '.'
})).pipe(gulp.dest(outputDir))
);
With Gulp v4 sourcemap I can not do above example, right now I have this (but it does not help):
const gulp = require('gulp');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const outputDir = './dist';
function build() {
return gulp.src('./src/**/*.ts', { sourcemaps: true })
.pipe(tsProject()).js
.pipe(gulp.dest(outputDir, { sourcemaps: '.' }))
}
Is there any possibility to setup advanced settings for Gulp v4 sourcemap (so it will generate correct sourcemap path)?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Please reopen this issue. It’s not about TS. You can reproduce the issue with babel too.
In fact, you can reproduce the issue without any transpiling step. It’s a gulp issue.
https://github.com/3cp/gulp-sm-demo
In this tiny demo, there are two files in src/folder:
src/index.js
andsrc/foo/index.js
.Because of the extra folder under
src/
, the compileddist/foo/index.js.map
is incorrect in the context without sourceRoot.For an app that uses this npm module, it thinks:
dist/index.js
is at pathdist/index.js
. (notsrc/index.js
, but not a big issue)dist/foo/index.js
is at pathdist/foo/foo/index.js
. (incorrect duplicated folder structure)This can be fixed by using
gulp-sourcemaps
:https://github.com/3cp/gulp-sm-demo/tree/gulp-sourcemaps
gulp-sourcemaps smartly does
"sourceRoot": "../src/"
todist/index.js.map
, so the source path will becomessrc/index.js
."sourceRoot": "../../src/"
(note it smartly added extra “…” to match deeper folder) todist/foo/index.js.map
, so the source path will becomessrc/foo/index.js
.So the default gulp v4 sourceMap offering is incorrect in term of source path. But this can be fixed in gulp v4 gracefully because the sourceMap writing is handled by
gulp.dest
, it can compare the dest location with original source location, then smartly mutate sourceMap"sources"
field or add"sourceRoot"
field.I can try to make a PR if this makes sense.
@3cp Thanks for your good reproduction codes. I’m trying to solve this issue.