Keep original typescript source maps after using browserify

前端 未结 6 1157
再見小時候
再見小時候 2020-12-13 10:23

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

I\'m using -m commonjs

6条回答
  •  -上瘾入骨i
    2020-12-13 11:15

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

提交回复
热议问题