I'm using webpack commmon chuncks to define a global library object (common components) that will be used in common with other generated bundles.
Common code (components.js
)
MyLib = window.MayLib = {}
MyLib.Utils = {
commonFn : function (){
/* common code */
}
}
module.exports = MayLib;
First common usage (dashboard.js
)
require.ensure ('./components', function () {
MyLib.Dashboard = {
/** Dashboad code here */
}
})
second common usage (account.js
)
require.ensure ('./components', function (){
MyLib.Account = {
/** Account code here */
}
})
After generate bundles, a new common code has been created but MyLib is undefined in global window, "cannot set property of undefined"