gulp-if
gulp-if copied to clipboard
Extension problem (and suggested solution)
Hello guys,
I came across with this problem, when I tried to run the HTML task...
gulp.task('html', ['javascript', 'stylesheet'], function () {
var assets = $.useref.assets({searchPath: ['.tmp', 'app/*.html', './']});
return gulp.src('app/*.html')
.pipe(assets)
//OTHER PIPES
.pipe($.if('*.js', $.uglify().on('error', gutil.log)))
.pipe($.if('*.css', $.csso()))
//OTHER PIPES
.pipe(gulp.dest('dist'));
});
... I got this error:
Error
at new JS_Parse_Error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
at parse_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)
at Object.next_token [as input] (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9)
at next (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25)
at Object.parse (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2061:15)
at /home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:71:33
at Array.forEach (native)
at Object.exports.minify (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:66:15)
at /home/ezequiel/Escritorio/Modus/node_modules/gulp-uglify/minifier.js:65:22
message: '/home/ezequiel/Escritorio/Modus/app/css/main.css: Unexpected character \'@\'',
fileName: '/home/ezequiel/Escritorio/Modus/app/css/main.css',
lineNumber: 1,
stack: 'Error\n at new JS_Parse_Error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)\n at js_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)\n at parse_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)\n at Object.next_token [as input] (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9)\n at next (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25)\n at Object.parse (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2061:15)\n at /home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:71:33\n at Array.forEach (native)\n at Object.exports.minify (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:66:15)\n at /home/ezequiel/Escritorio/Modus/node_modules/gulp-uglify/minifier.js:65:22',
showStack: false,
showProperties: true,
plugin: 'gulp-uglify' }
events.js:160
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
at parse_error (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)
at Object.next_token [as input] (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1946:9)
at next (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2075:25)
at Object.parse (eval at <anonymous> (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2061:15)
at /home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:71:33
at Array.forEach (native)
at Object.exports.minify (/home/ezequiel/Escritorio/Modus/node_modules/uglify-js/tools/node.js:66:15)
at /home/ezequiel/Escritorio/Modus/node_modules/gulp-uglify/minifier.js:65:22
and it's kind of weird, because it seems that "main.css" is getting through uglify even though the extension IS NOT ".js". So I changed the lines to
.pipe($.if('/\.js$/', $.uglify().on('error', gutil.log)))
//Instead of: .pipe($.if('*.js', $.uglify().on('error', gutil.log)))
.pipe($.if('/\.css$/b', $.csso()))
//Instead of: .pipe($.if('*.css', $.csso()))
and seems to be working fine.
I couldn't find the solution anywhere, so I hope this could be useful for anybody.
@ezequieltejada Not working for me. Js compiled, no error in console in build time but JS not compiled properly.
I have the same problem:
[02:22:03] Finished 'copy-modules' after 60 ms
events.js:160
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (/var/jenkins_home/workspace/alidw-fe-ccms/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (/var/jenkins_home/workspace/alidw-fe-ccms/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1542:11)
at parse_error (eval at <anonymous> (/var/jenkins_home/workspace/alidw-fe-ccms/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1667:9)
I found the reason: I use some es6 syntax, the uglify-js can not support it.
https://github.com/terinjokes/gulp-uglify/issues/243