I'm trying to load angular-ui-router in Webpack as an external dependency. The module name is "angular-ui-router". Here's an example:
module.exports = webpackMerge(commonConfig, {
...
externals: {
'angular': true,
'angular-ui-router': true
},
...
});
The problem with this is that Webpack creates a module in my app.bundle.js that looks like the following:
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = angular;
/***/ },
/* 2 */
/***/ function(module, exports) {
module.exports = angular-ui-router;
/***/ }
/******/ ]);
When the browser tries to load the module, it evaluates module.exports = angular-ui-router
as an expression, throwing the following error:
Uncaught ReferenceError: ui is not defined
The only fix I have found for this issue is:
module.exports = webpackMerge(commonConfig, {
...
externals: {
'angular': true,
'angular-ui-router': 'window["angular-ui-router"]'
},
...
});
This yields the correct result.
Is there a better way?
I was having the same problem, so I got it solved using something like this
module.exports = webpackMerge(commonConfig, {
...
externals: [
....
'angular-ui-router': {
commonjs: 'angular-ui-router'
}
}
],
...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With