with uglify sourcemap helps es6 gulp gulp-uglify

uglify - gulp-rename



Uglify lanza un error de Parse (4)

Encontré este mismo problema con gulp-concat-sourcemap y gulp-uglify . Lo resolví ignorando los archivos de mapas con gulp-ignore :

gulp.task("uglify-src", function() { gulp.src([ "src/js/**/*.js" ]) .pipe(concat("app.js")) .pipe(ignore.exclude([ "**/*.map" ])) .pipe(uglify()) .pipe(gulp.dest("dist/js")); });

Cuando uso gulp-uglify con browserify obtengo un error

events.js:72 throw er; // Unhandled ''error'' event ^ Error at new JS_Parse_Error (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:189:18) at js_error (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:197:11) at croak (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:656:9) at token_error (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:664:9) at expect_token (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:677:9) at expect (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:680:36) at /home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1222:13 at /home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:703:24 at expr_atom (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1152:35) at maybe_unary (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1327:19) at expr_ops (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1362:24) at maybe_conditional (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1367:20) at maybe_assign (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1391:20) at expression (/home/rkmax/my-project/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1410:20)

esta es mi tarea de scripts

gulp.task(''scripts'', function() { var bundler = browserify({ entries: [''./src/scripts/main.js''], debug: debug }).transform(stringify()); // the error persist even without this transformation bundler .bundle() .on(''error'', handleErrors) .pipe(source(getBundleName() + ''.js'')) .pipe(jshint()) .pipe(jshint.reporter(''default'', { verbose: true })) .pipe(jshint.reporter(''fail'')) .pipe(buffer()) .pipe(sourcemaps.init({loadMaps: true})) .pipe(uglify()) .pipe(sourcemaps.write(''./'')) .pipe(gulp.dest(''./web/js'')); });



Podría ser un simple error en su archivo fuente de JavaScript. Intente deshabilitar uglify comentándolo en su gulpfile y vea si la consola de su navegador detecta el problema real.

gulp.task(''minified'', function () { return gulp.src(paths.concatScripts) .pipe(sourcemaps.init()) //.pipe(uglify()) .pipe(sourcemaps.write(''.'', { addComment: false })) .pipe(gulp.dest(publishUrl)); });


uglify analizará el contenido del script antes de minificarlo. Sospecho que uno de los mapas de origen de browserify se incluye en la transmisión hacia abajo para uglify . De todos modos, para encontrar el problema, puede usar el método de log gulp-util para manejar las excepciones de uglify . Ejemplo:

... var gulpUtil = require(''gulp-util''); gulp.task(''scripts'', function() { ... .pipe(sourcemaps.init({loadMaps: true})) .pipe(uglify().on(''error'', gulpUtil.log)) // notice the error event here .pipe(sourcemaps.write(''./'')) .pipe(gulp.dest(''./web/js'')); });

Si aún tiene problemas para solucionar el problema, publique los detalles después de incorporar el registro de errores.