Is Less a single pass compilation process? - css

Does Less perform one pass over the files or does it do multiple passes?
Mainly, I'm concerned if I include another file that redefines variables/mixins, will the variables/mixins be the original or the override values be used for the generation?

Yes, mixins variables that are declared later in the code override previous code, just like in css if you declare the same class in two places the later ones property values will be the ones to be in effect.

Related

Prevent compiler from moving code from one chunk to another?

I read on this answer the following statement:
"Keep in mind that the compiler can and does move code from one chunk into other chunk output files if it determines that it is only used by that chunk."
Is there any way to switch that off?
I have a 'main' chunk and an 'optional' chunk, and I'm finding the code from the optional chunk is being moved entirely into the main.
My optional code will only be called from the main code, but only if it's determined that we actually want to load the optional stuff (based on a flag that's external to both.)
I want to minimize the size of the main code for cases where the optional stuff isn't needed, but it doesn't seem to be possible with closure as far as I can see.
EDIT:
To split the code I use the -chunk options on the (java) commandline. The 'main' one I point at several folders ('src/Infra/*.js' etc) and use 'auto' for the numFiles for the chunk. The 'optional' I point at three specific files, no wildcard, and specify 3 as numFiles.
To load the 'optional' script the 'main' writes a script tag to the page and has a Promise resolve when it loads. 'optional' is supposed to instantiate the class it defines, and push a reference to that instance to an array in the global namespace, then main reads the ref from the array, and calls an init() method on it, passing in some dependencies.
Is there a better-supported (and equally compact) way of doing it?
EDIT2: in case anyone has a similar issue, I resolved it using the "nameCache" feature of uglifyjs, so the separate components don't necessarily need to be compiled at the same time.
The compiler does not move code "up" the module graph. What's happening is the compiler somehow believes that symbols defined in your optional chunk are directly required.
This most frequently occurs because you are using dependency management and modules. When the compiler sorts dependencies, if any of the "optional" files are directly imported via require for CommonJS, import for ES6 or goog.require for Closure. In this case the compiler adds them to the main module.
To be more specific, I'd actually have to see code.

How can I use/emulate regex-like backreferences in attribute selectors?

What I want to do is write a selector that matches an arbitrary value in one place, then later requires a different value be equal to it. If [attr="value"] parsed "value" as a regex, then this would solve my problem:
*[class="(.+)"] *[class="if_\1"] {/* styles */}
Obviously I could just list each possible class individually, but that takes a great deal of convenience out of it.
Is this possible?
No, it's not possible. Attribute selectors are almost completely static and provide almost no dynamic matching functionality (beyond that of substring matches, which are still static and not dynamic pattern-based). They do not support anything like what you see in everyday regular expressions.
A stylesheet preprocessor such as Sass or LESS will allow you to generate the static CSS rules needed, but all that does is automate the manual task of listing all possible values individually, which proves my first point.

Where to put common Functions/Constants in ASP.Net MVC

I am new to ASP.Net MVC. I have a couple of controllers and models. They all use a set of static functions and constants which I call common code.
In my MVC project I have folders for Controller, models and view etc,
Where is all the common code supposed to be put ?
Is is OK to create a Common folder and create new class for my static functions and same for global constants ?
If you reuse this common code often across solutions, you might want to consider compiling it into its own class library and simply referencing the assembly.
Another thing you'll want to consider is the nature of the common functions. Are they truly just helper functions (like manipulating strings and stuff like that) or do they make more sense mixed into your business layers?
Basic rule is to keep it organized be consistent. There's no right or wrong way to structure your application...only hundreds of thousands of opinions.
Exactly you can create Helper folder when you set your extension methods or another common utility.
But for constants suggest you to create Ressource File
Remarks : All text , warning or info messages, put theses elements in ressource and don't write in code, for gloabalization need(It's my case on project)

Compiling multiple LESS files with different variable values

I'm currently creating a site that has multiple color themes - it seemed natural to use LESS and #variables for this (using Wordpress / WP-Less). I soon realized I couldn't find a really clean way have only one, monolithical stylesheet, as, of course, after compiling variables can't be overwritten, and it's unfeasible to compile on every page render.
Creating separate theme stylesheets (which only contain the variable-modified values) seems to be the only way to go, but it will be somewhat cumbersome to maintain in the future.
I'm utilizing only 1-3 variables, but they are referenced many times.
Is it possible to utilize WP-Less/Lessphp to render multiple .css from one .less with several different variables changed?
Or is there a simpler / other standard way to achieve the above?
Less offers a way to modify variables at run-time:
Here's an excerpt from the docs online - http://lesscss.org/:
Modify variables
modifyVars enables modification of LESS variables in run-time. When called with new values, the LESS file is recompiled without reloading. Simple basic usage:
less.modifyVars({
'#buttonFace': '#5B83AD',
'#buttonText': '#D9EEF2'
});

Do the names of Qt's objects have to be unique?

Does the QObject::objectName property have to be unique for the whole application? For example, let's say I have button somewhere called "new", then somewhere else I'm going to create a QShortcut also called "new". Is it going to cause a problem to Qt?
I know about properly naming objects (something called "new" is not a good name) but I just want to know whether I need to be extra careful or not.
Object names are not required to be unique. However, there are at least two things I can think of to consider when naming your objects:
QObject::findChild() - A function where you can search for QObjects by name.
Style sheets. If you ever specify a style sheet for a widget by name, it will apply to objects in the hierarchy underneath the widget with that style that have that name.
Other things to consider:
Objects to not require names. If you're not using the names in any meaningful way, you don't have to set them. I normally don't set them for one-off objects like QTimers and such.
If you're using designer to make a .ui file (doesn't sound like you are, but just in case), uic tends to spit out warnings for duplicate names. So if you don't want to see those warnings, keep the names in the .ui file unique (designer tends to enforce this by appending _1, _2, etc to duplicate names).

Resources