I've recently changed my library code to es6 using webpack, babel, and all of this family.
So my production is single file in the end.. compares to before that I had a lot of files that were being loaded dynamically by demand.
My problem is that I'm using another library that loads some of their class dynamically, and in order to customise them I need to provide URL to my custom objects/classes. It was not a problem at first, because I had a lot of files, but now my code is bundled into a single file.
Is there a way js/es6/... to give some content/string and create a fake url to it, so the other library will 'load' it ?
for example:
My classes are
file ../myLib/CustomLayer2D.js
Class CustomLayer2D {
...
}
file ../myLib/CustomLayer3D.js
Class CustomLayer3D {
...
}
file ../myLib/CustomLayer.js This is the use of the other library
Accessor.createSubClass([layer], {
viewModulePaths:{
"2d": "need to provide here a url to 2d layer file",
"3d": "need to provide here a url to 3d layer file"
}
});
file ../myLib/CustomLayer.js
Class CustomLayer2D {
...
}
Class CustomLayer3D {
...
}
Accessor.createSubClass([], {
viewModulePaths:{
"2d": "need to provide here a path to 2d layer",
"3d": "need to provide here a path to 3d layer"
}
});
I'd prefer finding a way and not exclude my custom classes from the bundle (my last resort).
Thanks for @Kaiido comment and a bit of more research I've came to a full solution.
In our webpack.config.js
we are adding our files to run through the raw-loader
- so instead of bundling the real code it will bundle the file as it is - Text file.
In our code we simply import our file/s and put it in <<The Code>>
URL.createObjectURL(new Blob([<<The Code>>], {type: 'text/plain'}));
It looks like this
webpack.config.js
under rules
property
{
test: /myLib\\CustomLayer2D.js|myLib\\CustomLayer3D.js/,
loader: 'raw-loader',
}
file myLib/CustomLayer.js
import layer2DCode from './myLib/CustomLayer2D.js'
import layer3DCode from './myLib/CustomLayer3D.js'
Accessor.createSubClass([], {
viewModulePaths:{
"2d": URL.createObjectURL(new Blob([layer2DCode], {type: 'text/plain'})),
"3d": URL.createObjectURL(new Blob([layer3DCode], {type: 'text/plain'}))
}
});