简体   繁体   English

gulp-sourcemaps不与babel 6合作

[英]gulp-sourcemaps not working with babel 6

So, babel published version 6 which is drastically different. 因此,巴贝尔发布了第6版,这是完全不同的。 The sourcemaps are not coming out right (clicking in the a js file does not in chrome developer does not lead me to the correct corresponding line in the es6 source file). 源图不是正确的(点击一个js文件不会在chrome开发人员没有引导我到es6源文件中的正确对应行)。

Here is my gulpfile: 这是我的gulpfile:

"use strict";

var gulp = require("gulp"),
    sourcemaps = require("gulp-sourcemaps"),
    babel = require("gulp-babel"),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename');

var paths = ['dojo-utils', 'dom-utils/dom-utils', 'esri-utils/esri-utils', 'esri-utils/classes/EsriAuthManager/EsriAuthManager'];

gulp.task("default", function () {
    paths.forEach(function(path){
        var pathArr = path.split("/");
        var parent = pathArr.slice(0, pathArr.length - 1).join('/');
        var file = pathArr[pathArr.length - 1];
        var directory = "./" + (parent ? parent + "/" : "");

        gulp.src(directory + file + '.es6')
            .pipe(sourcemaps.init())
            .pipe(babel({
                "presets": [
                    "es2015"
                ],
                "plugins": ["transform-es2015-modules-amd"]
            }))
            //.pipe(uglify())
            .pipe(rename(file + '.js'))
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest(directory));
    });
});

Note that I am using babel 6 here. 请注意,我在这里使用babel 6。

I have also tried this variation: 我也尝试过这种变化:

gulp.src(directory + file + '.es6')
            .pipe(babel({
                "presets": [
                    "es2015"
                ],
                "plugins": ["transform-es2015-modules-amd"],
                "sourceMaps": "both"
            }))
            .pipe(rename(file + '.js'))
            .pipe(sourcemaps.init())
            //.pipe(uglify())
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest(directory));

TLDR; TLDR; Babel 6 breaks sourcemaps when using the amd transform, moving Back to Babel 5 should do the trick. Babel 6在使用amd变换时打破了源图,移动Back to Babel 5应该可以解决问题。

I had to wrap my head around the way you load files into the stream (you should check out the Gulp documentation on gulp.src and its support for arrays of files and globs), but I tried to replicate your problem with a more simple version and came to the same result. 我不得不围绕你将文件加载到流中的方式(你应该查看gulp.src上的Gulp文档及其对文件和globs数组的支持),但我尝试用更简单的版本复制你的问题并得出了相同的结果。 Here is what I found: 这是我发现的:

The right order in the pipe should be as follows: 管道中的正确顺序应如下:

gulp.src([...])                    // start stream
    .pipe(rename(function (path) { // rename files based on path
        path.extname = '.js';      // no need to reach outside the scope
    }))
    .pipe(sourcemaps.init())       // sourcemaps now tracks the files passed to it
    .pipe(babel({
         // ...options as above
    })
    .pipe(sourcemaps.write('.'))   // adds the sourcemaps to the stream
    .pipe(gulp.dest(...));         // writes the stream to disk

This way, the sourcemaps should map to the correct file and contain all transforms done by Babel. 这样,源图应映射到正确的文件,并包含Babel完成的所有转换。

However this only works fine until you add the transform-es2015-modules-amd plugin to the Babel configuration. 然而,直到您添加变换ES2015模块,AMD插件巴贝尔配置这只是正常工作。

It looks like there is an open ticket regarding that matter and the only solution for now is to go back to Babel 5. See T3044 Occasional useless source maps . 看起来有一个关于这个问题的开放票,现在唯一的解决方案是回到Babel 5.参见T3044偶尔无用的源地图

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

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