I’m using webpack with webpack.optimize.UglifyJsPlugin
on an Angular app, I’d like to use this syntax to define controller:
// in header.controller.js
class HeaderController {...}
export default HeaderController;
// in app.js
import HeaderController from './header.controller'
angular.module('app', [])
.controller(HeaderController.name, HeaderController);
However, I found uglify will change the class name, how to disable this?
https://www.npmjs.com/package/ng-annotate-loader
@sokra That’s not the case,
ng-annotate
can only handle the missing dependencies, but this issue is related to function name has been mangled. I tried to use the config below:But it can not solve this issue.
Finally I found the root cause, if you use
-p
, the UglifyJSPlugin will mangle variables by default, even if you have anothernew webpack.optimize.UglifyJsPlugin
in your config, so if you want to config the UglifyJSPlugin, do not use-p
.I also file a bug on Webpack’s doc webpack/docs#49, the default mangle option for UglifyJsPlugin is not false, so if you do not want to mangle variables, you need to explicitly set this to false:
new webpack.optimize.UglifyJsPlugin({mangle: false})
.This issue is not AngularJS specific. I’m using webpack@1.13.0 for a React application and the mangling of class names as a default config option in for
-p
builds is affecting me. I don’t understand why this issue is closed with a link to a doubtful workaround applicable only to AngularJS apps.666,it works!!! thks guys
You may should not use
Function.prototype.name
. Disabling mangling is only a workaround.