简体   繁体   English

在gulp-uglify之后,typescript sourcemaps错误

[英]Typescript sourcemaps wrong after gulp-uglify

I have created a gulp / typescript workflow that performs the following actions. 我创建了一个gulp / typescript工作流,它执行以下操作。

  1. gulp.watch(..) gulp.watch(..)
  2. gulp-typescript 一饮而尽,打字稿
  3. gulp-uglify 一饮而尽,丑化
  4. gulp-sourcemaps 一饮而尽,sourcemaps

using the following.. 使用以下..

var tsProject = ts.createProject('tsconfig.json') // See below for options

gulp.task('watch-ts', function () {
    return gulp.watch(paths.scriptSrc + '/**/*.ts', ['compile-ts']);
});

gulp.task('compile-ts', function () {
    var tsResult = gulp
        .src(paths.scriptSrc + '/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(ts(tsProject));

    return tsResult
        .js
        .pipe(uglify())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(paths.scripts));
});

{
    "compilerOptions": {
        "outFile": "app.js",
        "target": "es5",
        "removeComments": true,
        "noImplicitAny": false,
        "module": "system",
        "experimentalDecorators": true,
        "declaration": false,
        "noEmitOnError": true
    }
}

So after the js file + sourcemap have been created, when i attempt to step in and debug in one of my typescript files using the Chrome debugger the breakpoints jump all over the place and one line jumps to some random line for each F10 press. 因此,在创建了js文件+源映射之后,当我尝试使用Chrome调试器插入并调试我的一个打字稿文件时,断点会跳到整个地方,并且每行F10按下一行跳转到一些随机行。 I believe something strange has happened when generating the sourcemaps but dont know what. 我相信在生成源图时会发生一些奇怪的事情,但不知道是什么。

If i comment out ".pipe(uglify())" then i can debug perfectly and there are no problems. 如果我注释掉“.pipe(uglify())”那么我可以完美地调试并且没有问题。

Does anyone know what could be causing this behavior? 有谁知道可能导致这种行为的原因是什么?

The uglify plugin strips your js-code but does not change the sourcemaps. uglify插件会删除你的js-code,但不会更改源图。 So the mappings provided by the sourcemap do not match with your actual js-files anymore. 因此,源映射提供的映射不再与您的实际js文件匹配。

Most uglify-plugins have a option to generate sourcemaps on there own so you could try that. 大多数uglify-plugins都有自己生成源图的选项,所以你可以试试。

I recommend to have two different build-tasks. 我建议有两个不同的构建任务。 One for development, which does not uglify your code and emits sourcemaps and one for production, which uglifies your code but does not emit sourcemaps. 一个用于开发,它不会破坏您的代码并发出源映射,而是一个用于生成的源代码,它会使您的代码变得丑陋,但不会发出源代码映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Typescript + Gulp + Sourcemaps错误的源路径 - Typescript + Gulp + Sourcemaps wrong source path AngularJS:TypeScript编译过程和gulp-uglify-是否可以通过IIFE强制TS生成函数而不是变量? - AngularJS: TypeScript compile process and gulp-uglify - is there a way to force TS to produce functions instead of variable with IIFE? 使用TypeScript和Babel的Gulp源图 - Gulp sourcemaps with TypeScript and Babel Gulp中的TypeScript + Browserify + SourceMaps? - TypeScript + Browserify + SourceMaps in Gulp? Sourcemaps使用typescript和browserify / gulp可怕地破坏了 - Sourcemaps horribly broken using typescript and browserify/gulp 带有多个包和源映射的gulp-typescript - gulp-typescript with multiple bundles and sourcemaps Typescript -> Babelify -> Browserify -> Uglify Buildchain in Gulp - Typescript -> Babelify -> Browserify -> Uglify Buildchain in Gulp VSCode断点不能在带有gulp-sourcemaps生成的源映射的typescript中工作 - VSCode breakpoint not working in typescript with sourcemap generated by gulp-sourcemaps 将打字稿缩小为一个JS文件,使用gulp保持源地图正常工作 - Minify typescript into one JS file, keep the sourcemaps working using gulp 使用Gulp如何首先编译Typescript然后连接结果并uglify它? - Using Gulp how to first compile Typescript then concatenate the result and uglify it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM