I'm exploring grunt-inline module and faced with the following problem. I have the following task's config:
grunt.initConfig({
inline: {
options: {
uglify: true
},
dist: {
src: 'src/index.html',
dest: 'dist/index.html'
}
}
});
From the config above uglify: true
option means executing UglifyJS.minify
on this line:
var c = options.uglify ? UglifyJS.minify(inlineFilePath).code : grunt.file.read( inlineFilePath );
The problem is that if UglifyJS.minify
throws exception (which I'm just faced with) the grunt inline
command will not fails but exits quite.
So, either the problem with this module of lacking some grunt's flags from my side?
It would be great if you could explain me how to break grunt execution on any exceptions.
EDIT: Also I've noticed that if I catch exception and re-throw it myself it breaks grunt well, like the following:
try {
var c = options.uglify ? UglifyJS.minify(inlineFilePath).code : grunt.file.read( inlineFilePath );
} catch(e) {
throw new Error(e.message);
}
So why does't exception from UglifyJS.minify(inlineFilePath).code
break gruntjs task?
Looks like a problem with the module. I can't seem to find a way to flag and return these errors. You could try replace that line with:
UPDATE: So why does't exception from UglifyJS.minify(inlineFilePath).code break gruntjs task?
Looks like this is an issue with the error itself:
JS_Parse_Error
This is not a properly constructed error and is not caught by grunt. Looks like you have to catch it yourself and wrap it in anew Error()
as you have done above until a fix goes in. See link below:https://github.com/mishoo/UglifyJS2/issues/348