We use require.js to manage library dependencies. During development it loads our code from individual JS files, while the production build is optimized into a single JS file.
I'm now trying to load external JS libraries dynamically. I'm trying to add new libraries with require.config
and then use them:
require.config({paths:{ "d3":"https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min" }})
require(['d3'], function(d3) { console.log("Works!") })
It works as expected in the non-optimized build. However, in the optimized build it produces an error:
Uncaught Error: undefined missing d3
It seems that the optimized require somehow different from the non-optimized library. How can I get dynamic configuration and loading working in the optimized build?