I am trying to load angular -ui-router into Webpack as an external dependency. The module name is "angular -ui-router". Here is an example:
module.exports = webpackMerge(commonConfig, { ... externals: { 'angular': true, 'angular-ui-router': true }, ... });
The problem is that Webpack creates a module in my app.bundle.js, which looks like this:
}, function(module, exports) { module.exports = angular; }, 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, causing the following error:
Uncaught ReferenceError: ui is not defined
The only fix I found for this problem:
module.exports = webpackMerge(commonConfig, { ... externals: { 'angular': true, 'angular-ui-router': 'window["angular-ui-router"]' }, ... });
This gives the correct result.
Is there a better way?
javascript webpack angular-ui-router
Joseph238
source share