Coder Social home page Coder Social logo

Comments (8)

ivogabe avatar ivogabe commented on August 20, 2024 1

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.

from gulp-typescript.

baabgai avatar baabgai commented on August 20, 2024

Setting sourceRoot to empty string did work, thanks!

On Sat, Jan 17, 2015 at 8:48 PM, Ivo Gabe de Wolff <[email protected]

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
#52 (comment)
.

from gulp-typescript.

jon-hall avatar jon-hall commented on August 20, 2024

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.

from gulp-typescript.

ivogabe avatar ivogabe commented on August 20, 2024

Can you set the base property in the options object of gulp-typescript instead of gulp-sourcemaps?

from gulp-typescript.

jon-hall avatar jon-hall commented on August 20, 2024

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.

from gulp-typescript.

zivkan avatar zivkan commented on August 20, 2024

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:

  • adding {base:"."} to the call to src()
  • adding sourceRoot to sourcemap.write's options
  • changing, or removing the base option in the call to typescript
  • removing the .js call at the end of the line that calls typescipt

but I haven't found a way to get it to use relative urls with typescript yet.

from gulp-typescript.

ejmarino avatar ejmarino commented on August 20, 2024

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.

from gulp-typescript.

ivogabe avatar ivogabe commented on August 20, 2024

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' }))

from gulp-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.