gulp babel - gulp sourcemaps正在出现越野车

时间:2016-03-07 12:57:05

标签: gulp gulp-sourcemaps

这是任务:

var gulp = require('gulp'),
    clean = require('gulp-clean'),
    copy = require('gulp-copy'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    sourcemaps = require('gulp-sourcemaps'),
    uglify = require('gulp-uglify'),
    babel = require('gulp-babel'),
    jshint = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    Server = require('karma').Server,
    _ = require('lodash');

gulp.task('js-build', ['copy-iso'], function(){
    return gulp.src(['client/src/application.js', 'client/src/**/*.js'])
        .pipe(sourcemaps.init())
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(sourcemaps.write('.', {
            sourceRoot: '/src',
            includeContent: false
        }))
        .pipe(gulp.dest('./client/build'));
});

基本上,这会生成一个在某些时候映射不正确的源映射。我测试的方式是我在chrome中加载它,打开开发工具并尝试添加断点。这是一个例子:

源:

(function () {
        'use strict';

        angular
            .module('core')
            .filter('phoneNumberFormat', phoneNumberFormat);

        function phoneNumberFormat() {
            return phoneNumberFilter;

            function phoneNumberFilter(number) {
                /* 
                @param {Number | String} number - Number that will be formatted as telephone number
                Returns formatted number: (###) ###-####
                    else if number.length < 7: (###) ###

                Does not handle country codes that are not '1' (USA)
                */
                if (!number) { return ''; }

                number = number.toString().replace(/[^0-9]+/g, '');

                var formattedNumber = '';

                // if the first character is '1', strip it out and add it back
                var c = (number[0] == '1') ? '1 ' : '';
                number = number[0] == '1' ? number.slice(1) : number;

                // # (###) ###-#### as c (area) front-end
                var area = number.substring(0, 3);
                area = area.length > 0 ? area.length == 3 ? "(" + area + ") " : "(" + area : '';

                var front = number.substring(3, 6);
                front = front + (front.length == 3 ? '-' : '');

                var end = number.substring(6, 10);

                formattedNumber = c + area + front + end;
                return formattedNumber;
            }
        }
    })();

建:

'use strict';

(function () {
            'use strict';

            angular.module('core').filter('phoneNumberFormat', phoneNumberFormat);

            function phoneNumberFormat() {
                        return phoneNumberFilter;

                        function phoneNumberFilter(number) {
                                    /* 
                                    @param {Number | String} number - Number that will be formatted as telephone number
                                    Returns formatted number: (###) ###-####
                                        else if number.length < 7: (###) ###
                                      Does not handle country codes that are not '1' (USA)
                                    */
                                    if (!number) {
                                                return '';
                                    }

                                    number = number.toString().replace(/[^0-9]+/g, '');

                                    var formattedNumber = '';

                                    // if the first character is '1', strip it out and add it back
                                    var c = number[0] == '1' ? '1 ' : '';
                                    number = number[0] == '1' ? number.slice(1) : number;

                                    // # (###) ###-#### as c (area) front-end
                                    var area = number.substring(0, 3);
                                    area = area.length > 0 ? area.length == 3 ? "(" + area + ") " : "(" + area : '';

                                    var front = number.substring(3, 6);
                                    front = front + (front.length == 3 ? '-' : '');

                                    var end = number.substring(6, 10);

                                    formattedNumber = c + area + front + end;
                                    return formattedNumber;
                        }
            }
})();
//# sourceMappingURL=phone-number.filter.js.map

你可以看到两者几乎相同。不过,我不能在这一行上设置一个断点:

return phoneNumberFilter;  

当我这样做时(将断点放在源文件或构建文件中),我会被重定向到它下面的行(function phoneNumberFilter(number) {)。

这些奇怪的重定向几乎在每个文件中都会出现,我似乎无法找到任何押韵或理由。有时他们会将某些行重定向到某个行的结尾处... idk。

提前致谢。

0 个答案:

没有答案