使用browserify后保留原始打字稿源地图 [英] Keep original typescript source maps after using browserify

查看:208
本文介绍了使用browserify后保留原始打字稿源地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我正在将2个依赖的TypeScript文件编译为js,它使用tsc 1.0生成源地图(每个文件一个源地图)

Background: I am compiling 2 dependent TypeScript files to js, which produces also source maps (one source map per file) using tsc 1.0

我正在使用 -m commonjs 然后使用browserify生成一个 bundle.js

I'm using -m commonjs and then use browserify to generate a single bundle.js

但是我注意到我在包中得到了两次原始的源地图引用,这似乎不起作用。

However I noticed that I get the original source map references twice in the bundle, which doesn't seem to work.

传递 --debug 似乎也没有做到这一点。

Passing --debug doesn't seem to do the trick either.

我有一种感觉这个问题: https:// github.com/substack/node-browserify/issues/325 有些相关,但我无法弄清楚问题是如何解决的。

I had a feeling this issue: https://github.com/substack/node-browserify/issues/325 is somewhat related, but I couldn't figure out how the issue was resolved.

建议 https://github.com/substack/browser-pack ,但我不完全明白如何使用它,它是browserify的替代品吗?

Also https://github.com/substack/browser-pack was suggested, but again I don't fully understand how to use it, is it a replacement to browserify?

底线,我想合并2个js文件,但是使用browserify将js合并到ts源地图。这可能吗?

Bottom line, I would like to merge the 2 js files but "merge" the js to ts source maps using browserify. Is that possible?

推荐答案

使用 minifyify browserify插件我相信你可以将TypeScript与Browserify一起使用并保留源地图。编译TypeScript文件后,您应该能够通过browserify使用minifyify插件传递entry文件(通过commonjs语法导入另一个文件)。

Using the minifyify browserify plugin I believe you can use TypeScript with Browserify and retain the source maps. After compiling the TypeScript files you should be able to pass the "entry" file (the one that imports the other one via commonjs syntax) through browserify with the minifyify plugin.

var browserify = require('browserify'),
    bundler = new browserify();

bundler.add('entry.js');
bundler.plugin('minifyify', {map: 'bundle.js.map'});
bundler.bundle({debug: true}, function (err, src, map) {
  if (err) console.log(err);
  fs.writeFileSync('bundle.js', src);
  fs.writeFileSync('bundle.js.map', map);
});

这篇关于使用browserify后保留原始打字稿源地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆