Read the statement by Michael Teeuw here.
Javascript equivalent of @import in css
-
I put my custom css for modules in their own file and then import in custom.css to make it a little easier to work with. Is there a way to accomplish this with the config.js also? I use this “template” in custom.css: @import “./MyCss/customModulename.css”
-
@DDE12 no. config.js is loaded into the browser where import is not supported
-
@sdetweil
How does config.js “override” the settings in the config of the module? That’s basically what I would like to do except it wouldn’t really override config.js since I wouldn’t have anything specific for the module there. The config.js would just pick up the settings from the specific custom config file I make for each module. -
@DDE12 the code uses the Object .assign() method to merge the config.js module config:{} section onto the defaults section
from Magicmirror/js/main.js
config = Object.assign({}, defaults, config);
this says
starting with an empty object {} add the module defaults and then add the config.js module config onto that, REPLACING any properties already defined. return the merged result.
so, if config.js doesn’t set any value, you get whats in the module defaults section
thats why you can do
{ module:"clock", position:"top_left" }
with no config
-
@DDE12 there is no way to do what you want in the FINAL config.js
one can make a preprocessing step that handles the imports/requires, and produces the final config.js
we have discussed using this approach for variable substitution, (hide userids/password/apikeys…), without having to interntegrate all that code into the MM base
see https://github.com/MichMich/MagicMirror/issues/1756the ‘issue’ in that the code loads config.js into the webpage as part of a <script> tag… so all pre-processing has to be done before the file is loaded… and it has to be ‘on filesystem’, unless there is a fetch hook added to check for this one filename and handle it differently
technical debt just gets deeper and deeper as you think about solving different problems here… priacy/security/modularization(yours)/etc…
edit: editor thought script tag as a REAL script tag and deleted all the content after
-
@sdetweil said in Javascript equivalent of @import in css:
the ‘issue’ in that the code loads config.js into the webpage as part of a
Did you have more to discuss?
I read through the link you posted and the possible solution there and did not see a clear solution that I could follow and tweak. I’m just a tinkerer. I tried your MMM-Config early on but was getting some unwanted results and went away from it. I might work with it again and how it goes. I also thought I could use the expand/collapse feature Notepad++ and put the name of the module after “{”. Notepad++ also has a bookmark feature (that’s the blue dot next to the line 51 indicator) and I think there is a plug-in to extend the bookmark capabilities.
.Ultimately, I’m trying to have the config.js be a little cleaner and make it easier work through so I am not scrolling through all the lines of code looking for the module section I need. Which, in turn, will help prevent spikes in my blood pressure :face_with_steam_from_nose: . Thank you for looking at this and explaining what the code is doing.
-
@DDE12 show me the issues w mmm-config.
I try to discover every modules usage thru defaults, but many are unclear or undocumented… but I provide a way to get clean content in the form, but it takes a little work.
I can ship the schema file in MMM-Config if the module is abandonedthere are lots of old, unmaintained modules
-
@sdetweil said in Javascript equivalent of @import in css:
but many are unclear or undocumented…
there are lots of old, unmaintained modulesAnd yayhoos like me making modules. :beaming_face_with_smiling_eyes:
If I start using MM-Config again and find some oddities, I will post separately so it’s not “hiding” under this topic. -
@DDE12 thanks… and can open issue in module…
an example fun time
in defaults foo: false, // must be boolean?
later
if(this.config.foo) element.innerHtml=this.config.foo // no is a string