Closed baabgai closed 9 years ago
Does setting the sourceRoot
option to ''
solve this? Changing the default value of sourceRoot
to an empty string might solve this issue. Mentioning @shiwano since he added sourceRoot option.
Setting sourceRoot to empty string did work, thanks!
On Sat, Jan 17, 2015 at 8:48 PM, Ivo Gabe de Wolff <notifications@github.com
wrote:
Does setting the sourceRoot option to '' solve this? Changing the default value of sourceRoot to an empty string might solve this issue. Mentioning @shiwano https://github.com/shiwano since he added sourceRoot option.
— Reply to this email directly or view it on GitHub https://github.com/ivogabe/gulp-typescript/issues/52#issuecomment-70381454 .
Unfortunately, I'm getting the same issue, and setting sourceRoot to '' doesn't appear to resolve it. My build step looks like this:
gulp.task('tsc', [], function () {
'use strict';
var tsRes = gulp.src('src/*.ts', { base: './' })
.pipe($.sourcemaps.init())
.pipe($.typescript({
target: 'ES6',
sortOutput: true
}));
return tsRes.js
.pipe($.concat('script.js'))
.pipe($.sourcemaps.write('.', { includeContent: false, sourceRoot: '' }))
.pipe(gulp.dest('./dist'));
});
My TypeScript files are all internal modules present under the 'src' directory, and the generated sourcemap's 'sources' collection ends up containing all absolute paths; while the map file the TypeScript compiler generates when using the --out flag has relative paths.
Can you set the base property in the options object of gulp-typescript instead of gulp-sourcemaps?
That solved it, cheers for the help.
Edit: Looks like I was mistaken, the first step of the build is now as follows
var tsRes = gulp.src(files.ts)
.pipe($.sourcemaps.init())
.pipe($.typescript({
target: 'ES6',
sortOutput: true,
base: './'
}));
And I'm still getting absolute filepaths in the sourcemap, any further suggestions would be appreciated.
I'm also having the same problem. My gulpfile has this:
gulp.src("app/**/*.ts")
.pipe(sourcemap.init())
// .pipe(typescript({base:"."})).js
.pipe(concat("app.js"))
.pipe(uglify())
.pipe(sourcemap.write(".", { includeContent: false }))
.pipe(gulp.dest("."));
With the typescript line commented out (they're still plain javascript files, I'm trying to migrate to typescript), the map file contains relative paths. With the line uncommented, the map file contains absolute paths.
I tried:
but I haven't found a way to get it to use relative urls with typescript yet.
I had solved the absolute path problem putting:
sourceRoot : ''
in my typescript project object like this:
var typeScriptProject = typescript.createProject({
declarationFiles: false,
noExternalResolve: false,
removeComments: false,
sourceRoot: ''
});
but a new problem arise...
I have source files organized in folders but when I put sourceRoot in project properties all the files paths are removed and the file are flattened out.
This is the section of map file without sourceRoot:
"sources": [
"C:/Development/FrontEnd/scripts/module.ts",
"C:/Development/FrontEnd/scripts/controllers/controllers.ts"
]
but with sourceRoot = '':
"sources": [
"module.ts",
"controllers.ts"
]
I would expect this kind of result:
"sources": [
"module.ts",
"controllers/controllers.ts"
]
as I get when i sourcemap javascript instead typescript.
Solved by removing the sourceRoot option. Because the sourceRoot property was present in the source map, gulp-concat would add that to the source property of the source map generated by gulp-concat, which resulted in an absolute path. That's now fixed by removing sourceRoot from the source-map generated by TypeScript.
Also I removed the sourceRoot option, since gulp-sourcemap has a sourceRoot option. Gulpfiles should now look like:
return gulp.src('lib/**/**.ts')
.pipe(sourcemaps.init())
.pipe(ts())
.pipe(sourcemaps.write())
.pipe(gulp.dest('release'));
If you want to provide a sourceRoot option, you can use
.pipe(sourcemaps.write('.', { sourceRoot: 'foo' }))
In the sourcemap files written together with gulp-sourcemaps the TypeScript files end up with absolute paths instead of relativ paths in the sources tag. This leads to errors when Firefox tries to read sourcemap files and to cumbersome long paths in Chrome. When using gulp-sourcemaps on javascript files the expected relative paths are set.