[英]Typescript sourcemaps wrong after gulp-uglify
I have created a gulp / typescript workflow that performs the following actions. 我创建了一个gulp / typescript工作流,它执行以下操作。
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.