minify icon indicating copy to clipboard operation
minify copied to clipboard

SourceMaps doesn't work as expected with minify

Open HACHIMIam opened this issue 6 years ago • 0 comments

Describe the bug SourceMaps doesn't work as expected with Minify and works very well when i remove the minify preset

To Reproduce

Minimal code to reproduce the bug this is the sourceMap config

const gulp = require('gulp');
const paths = require('./../lib/paths');
const gulpif = require('gulp-if');
const changed = require('gulp-changed');
const plumber = require('gulp-plumber');
const sourcemaps = require('gulp-sourcemaps');

gulp.task('es6', () => {
    const babel = require('gulp-babel');
    const config = require('./../lib/config');
    const babelConfiguration = require('./../configuration/babel.config');

    const scripts = paths.getAppPaths();
    return gulp.src([
        ...scripts.sources,
    ], { base: scripts.root })
        .pipe(gulpif(config.global.sourceMaps, sourcemaps.init()))
        .pipe(plumber())
        .pipe(changed(scripts.dist, { extension: '.js' }))
        .pipe(babel(babelConfiguration))
        .pipe(gulpif(config.global.sourceMaps, sourcemaps.write('.')))
        .pipe(gulp.dest(scripts.dist));
});

the configuration/babel.config is this

const config = require('./../lib/config');
const babelEnv = require('@babel/preset-env');
const browsersList = require('./browserslist');
const babelSystemJS = require('@babel/plugin-transform-modules-systemjs');
const path = require('path');
const { argv } = require('yargs');

const babelPlugins = [];

if (config.global.jspm) {
    babelPlugins.push([babelSystemJS]);
}

const presets = [
    [babelEnv, {
        // "useBuiltIns": "entry",
        // "targets": browsersList,
    }],
];

if (argv.production) {
    presets.push(['minify', {
        builtIns: false,
        mangle: {
            keepFnName: true,
        },
    }]);
}


module.exports = {
    babelrc: false,
    plugins: babelPlugins,
    cwd: path.dirname(__dirname),
    presets,
    moduleIds: false,
    comments: false,
};

as you notice i only enabled the minify for production because the sourceMaps doesn't work well when i added minify

Actual Output

in Production i have this with minify Screenshot 2019-07-18 at 09 21 23

Expected Output

in development i have this without minify

Screenshot 2019-07-18 at 09 48 33

Configuration

i m using babel-minify with babel-preset-minify version ^0.5.0 in babelrc and gulp-sourcemaps: ^2.6.4,

HACHIMIam avatar Jul 18 '19 07:07 HACHIMIam