简体   繁体   English

使用gulp,Browserify,reactify,UglifyJS的源地图

[英]Source maps using gulp, Browserify, reactify, UglifyJS

I'm trying to get source maps for my JavaScript files working with Chrome. 我正在尝试获取与Chrome一起使用的JavaScript文件的源地图。 The problem with the current gulp script is that the source maps (that Browserify creates) lead to minified versions of files. 当前gulp脚本的问题在于源映射(Browserify创建)导致文件的缩小版本。

For example, let's say that app.jsx is an entry file for Browserify and it has require('a') and require('b') calls in it. 例如,假设app.jsx是Browserify的入口文件,它require('a')require('b')调用。 app.jsx gets browserified, reactified and uglifyied and written to app.js as expected. app.jsx获得浏览器化,重新设置和uglifyied并按预期写入app.js。 However, all of the source maps references within module a and module b are also minified: 但是,模块a和模块b中的所有源映射引用也会缩小:

var gulp = require('gulp'),
    browserify = require('browserify'),
    watchify = require('watchify'),
    source = require('vinyl-source-stream'),
    buffer = require('vinyl-buffer'),
    bundler;

bundler = browserify({
    entries: '/app.jsx',
    cache: {},
    packageCache: {},
    fullPaths: true
});

bundler
    .transform('reactify');
    .transform({
        global: true
    }, 'uglifyify');

bundler = watchify(bundler);
bundler.on('update', function() {
    return bundler
        .bundle()
        .pipe(source('app.js'))
        .pipe(buffer())
        .pipe(gulp.dest('/js'));
});

Any ideas of how to get this working? 有关如何使其工作的任何想法?

It looks like it's an issue with uglifyify ( https://github.com/hughsk/uglifyify/issues/16 ). 看起来这是uglifyify的问题( https://github.com/hughsk/uglifyify/issues/16 )。 It seems it just doesn't know how to generate source maps. 它似乎只是不知道如何生成源地图。

There are some alternatives: 有一些替代方案:

  1. Uglify after bundling with the gulp-uglify plugin and the gulp-sourcemaps plugin. 捆绑丑化 一饮而尽,丑化插件和一饮而尽,sourcemaps插件。 Unfortunately this is slightly less optimal since it won't remove dead require statements. 不幸的是,这不太理想,因为它不会删除死的require语句。

  2. Create separate development and distribution builds . 创建单独的开发和分发版本 You can then generate source maps for your development build without uglification. 然后,您可以在不进行uglification的情况下为开发构建生成源映射。 Your distribution build could be uglified with no source maps. 您的分发版本可以在没有源映射的情况下进行验证。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM