2

I use the "gulp-babel" before uglifying my js files. The module blocks the minification because a third party js script is not "strict mode" compilant.

// Include gulp
var gulp = require('gulp');
var baseDir = "./";
var jsources = [
    "sites/**/js/*.js",
    "!sites/**/js/*.min.js"
];

// Include Plugins
var jshint = require('gulp-jshint');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');


// Minify JS
gulp.task('scripts', function () {
    return gulp.src(jsources, { base: baseDir })
        .pipe(babel({
            presets: [
                ['env', { modules: false }]
            ]
        }))
        .pipe(uglify().on('error', function (e) { console.log(e); }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest(baseDir));
});

As result I obtain an error because a js file is not strict mode compilant: enter image description here

I don't want to modify that third-party file to make it strict mode compilant. How can I disable that check for that file or another similar files?

Just now the minification is blocked because of that kind of files...

I tried

  • to install the "transform-remove-strict-mode" plugin and then do

    .pipe(babel({
        "presets": ["env"],
        "plugins": ["transform-remove-strict-mode"]
    }))
    
  • I also tried the

    .pipe(babel({
        presets: [
            ["es2015", { "modules": false }]
        ]
    }))
    

but the output is still the same...

serge
  • 13,940
  • 35
  • 121
  • 205

3 Answers3

1

Use the ignore option to avoid transpiling your 3rd party code. The transform-remove-strict-mode plugin doesn't work because it's already too late.

mikeapr4
  • 2,830
  • 16
  • 24
  • so, there is no option to *remove the strict mode*, but to ignore files?!... there are actually a lot of 3rd party files in the solution that does not fit the strict mode, so it takes a lot to identify and list them all... – serge May 10 '17 at 13:58
  • Then use `only` (it's the opposite of `ignore`), an inclusive list – mikeapr4 May 10 '17 at 14:47
  • Thanks, the `ignore` works, but I think better is to include these files, just remove the "strict mode", if possible. – serge May 10 '17 at 15:12
0

Try gulp-uglify with mangle option

uglify({ mangle: false })
Sreeragh A R
  • 2,871
  • 3
  • 27
  • 54
0

Maybe it's too late but you could try to do it this way:

gulp.task('foo_task', () => {

gulp.src('foo/src/path')

    .pipe(concat('foo_file.js')
    .pipe(babel({ presets: ['env'] }))
    .pipe(uglify())
    .pipe(gulp.dest('foo/dist/path'))

    .pipe(concat([ '/dist/path', 'foo/src/path' ]))
    .pipe(uglify())
    .pipe(gulp.dest('foo/dist/path'))

});
Luis Veliz
  • 247
  • 4
  • 8