B4J Question [BANano] [SOLVED] Transpiler Option to exclude certain css and js files when using B4xlib on new projects?

Mashiane

Expert
Licensed User
Hi there

Here is a scenario. I'm creating a universal library with various components that I might use in my projects. Depending on each project, I might use certain CSS and JS files from the b4xlib.

The current implementation for b4xlibs is that when referencing the lib on your project, all css and js files are automatically included in your project using the b4xlib. Perfect!

In my library converted into b4xlib i have this for example defined in AppStart.

CSS & JS Files:
BANano.Header.AddCSSFile("vue-material.min.css")
    BANano.Header.AddCSSFile("default.css")
    BANano.Header.AddCSSFile("vue-material-slider.css")
    BANano.Header.AddJavascriptFile("vue-material.min.js")
    BANano.Header.AddJavascriptFile("vue-material-slider.umd.js")
And somewhere, this also..

Another CSS & JS Files:
BANano.Header.AddJavascriptFile("jquery.knob.min.js")
    BANano.Header.AddJavascriptFile("tron-knob.js")
    BANano.Header.AddJavascriptFile("md5.min.js")
    BANano.Header.AddJavascriptFile("hashes.min.js")
    BANano.Header.AddJavascriptFile("bCrypt.js")
    BANano.Header.AddJavascriptFile("moment.js")
After compiling my lib, all these css and js files are available for use in any of my projects, but...

Now assume that I'm working on a new project and do not want to use tron, md5, hashes, bcrypt and moment js files on my new project, how can I have these excluded in my new BANAno project?

The un-needed js and css files are included in the generated HTML scripts for the page currently, these are also merged when that option is turned on.

Thanks!

PS: I understand the need to reference CDN for some of the resources, however at cases, one is running intranet apps without a need for an internet access thus the added resources.
 

alwaysbusy

Expert
Licensed User
Check out https://www.b4x.com/android/forum/threads/banano-v3-rc1-the-next-iteration.106460/#content

the DependsOnAsset trick for custom views may work too. BUT as soon as something references to a module with DependsOnAsset, it is included.

e.g.

Module1
DependsOnAsset(...)

Method11


Module2
Method21
Module1.Method11

Method22


Main
Module2.Method22

In this case because in main we use Module2 (which has a method that uses a method from Module 2), the asset will be included, even though we never call Method11 from Module1.

EDIT: In general, it is better to split up your libraries I think, as this will always work better in reducing the size than any 'logic' I can build.
 

Mashiane

Expert
Licensed User
In general, it is better to split up your libraries I think, as this will always work better in reducing the size
Thanks, I'm trying to implement .DependsOnAsset in my class modules as I am not using custom controls. Will see what I come up with.

What would you advise in case you have a js file and the only use for it is when one calls RunJavascriptMethod from the js files? How can I exclude it if I don't want it? The assumption is still on keeping a single repo for the code base?

Thanks
 
Top