babel / babel/minify

SourceMaps doesn't work as expected with minify

Open
#959 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

**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](https://user-images.githubusercontent.com/23213435/61438233-44928e80-a93f-11e9-9fb3-ba2886b01a8c.png)

**Expected Output**

in development i have this without minify

![Screenshot 2019-07-18 at 09 48 33](https://user-images.githubusercontent.com/23213435/61439207-60972f80-a941-11e9-9fc2-3a07cdeb34d6.png)

**Configuration**

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

Contributor guide

Open the contributing guide

Research direction

Start with the Gulp `es6` task and `configuration/babel.config`, then reproduce the production build with `gulp-sourcemaps` and the `minify` preset enabled. Compare the generated source map and production output with the development build; done means minified output maps back to the original source as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.