I have used the react-rails gem for a while. While using it, I placed my ES6 components under app/assets/javascript/components
folder and placed plain old JavaScript files to app/assets/javascript
. The good thing was I was able to easily refer the objects of old style Javascript files from the ES6 components.
After migrating to webpacker gem, I tried to keep similar approach. I placed the modules under app/javascript/packs
and placed old style JavaScript files unde app/javascript
folder.
I guess, with webpack in place I have to use import / export mechanics but that I could not achieved either.
So my question is how can I use old javascript files and refer the objects inside them, within components.
For example the content of a dummy global_data.js
file that reside in app/javascript
directory is as follows:
function globalData (){
}
globalData.prototype.data = {};
var g_GlobalData = new globalData();
What is the ES6 way to use g_GlobalData
variable within components?