When compressing the js script, an error occurs:

SyntaxError: Unexpected token: name ($ content)

Before compression, the script works fine.

(function () { let $content = $('.s-content'); let $back2top = $('.back-to-top'); let $windowHeight; let contentBottom; function onScrollWindow() { let offsetY = window.pageYOffset; if (offsetY - $content.offset().top > 100 && !$back2top.hasClass('back-to-top_visible')) { $back2top.addClass('back-to-top_visible'); } else { if (offsetY - $content.offset().top < 100 && $back2top.hasClass('back-to-top_visible')) { $back2top.removeClass('back-to-top_visible'); } } if (offsetY + $windowHeight >= contentBottom && !$back2top.hasClass('back-to-top_pinned')) { $back2top.addClass('back-to-top_pinned'); } else { if (offsetY + $windowHeight < contentBottom && $back2top.hasClass('back-to-top_pinned')) { $back2top.removeClass('back-to-top_pinned'); } } } function onResizeWindow() { $windowHeight = $(window).height(); contentBottom = $content.offset().top + $content.height() + 25; } $(document).ready(function () { if ($content.length < 1 || $back2top.length < 1) { return; } $windowHeight = $(window).height(); contentBottom = $content.offset().top + $content.height() + 25; document.addEventListener('scroll', function () { onScrollWindow(); }, true); window.addEventListener('resize', function () { onResizeWindow(); }, true); }); })(); 
  • It seems to me the problem in your variables with dollars. - Alexey Shimansky
  • If the dollar is removed, swears just on the content - Danila Nikonets
  • Yes, and what the dollar can not please - Danila Nikonets
  • four
    Most likely the problem is that the constrictor does not understand es6, in particular your let - Grundy
  • Quite interesting, given that the collector checks for es6 itself and does not allow var to be used. - Danila Nikonets

1 answer 1

For ES6, you can use uglify-es , so it will compress files correctly.

 let gulp = require('gulp'), uglifyes = require('uglify-es'), composer = require('gulp-uglify/composer'), uglify = composer(uglifyes, console); gulp.task('js:vendor', function () { return gulp.src('paths-to-src') .pipe(uglify()) .pipe(gulp.dest('paths-to-dest')); });