It's essentially a uglifyjs webpack plugin, but extended with extra option.
You can replace webpack.optimize.UglifyJsPlugin
with this plugin. Besides common usage of uglifyjs,
the new-added option wrapCatch
enables you:
wrap eval
:
...
eval( 'var a = 5; console.log( a )' );
...
=>
...
try {
eval( 'var a = 5; console.log( a )' );
}
catch ( e ) {
e.message += '<info extracted from the source, such as function name or code snippets>';
throw e;
}
...
wrap function body
:
function a() {
// function body goes here
}
=>
function a() {
try {
// function body goes here
}
catch ( e ) {
e.message += '<info extracted from the source, such as function name or code snippets>';
throw e;
}
}
you should only:
- set the
wrapCatch
option to true. - add directive
"use catch;"
where you need the plugin to wrap something for you.
npm install --save pro-uglifyjs-webpack-plugin
in
webpack.config.js
var proUglify = require( 'pro-uglifyjs-webpack-plugin' );
config.plugins = config.plugins.concat( [
new proUglify( {
wrapCatch: true,
compress: { ... },
mangle: false,
output: {
comments: true
}
} )
] );
in
file.js
"use catch";
...