Webpack: How to remove extra css classes from built out css file? - vue.js

Suppose I have one sass file named common.scss, suppose there are another 2 sass files, each named chat.scss and thread.scss, each of the 2 sass file import common.scss in the begining, like
#import 'common'
......
other self class definition codes
......
The case is, in build out production files phase, sometimes I only need to import chat.scss, but sometimes I need to import both chat.scss and thread.scss. When import both scss files, as you can see there will be extra class definition as each of them import common.scss. So I want to know is there any webpack plugin can remove extra class definition in build phase ?

Related

Dynamic struct member names like in javascript in golang

I am writing a multi-lang website.
I read the language info from users cookies, and I have several translation modules such as en.go gr.go etc.
The modules are of type map[string]string.The problem here is in javascript I can do something like lang[cookies.lang]["whatever message"].'But go does not support accessing struct members in this way.
I could make switch case ormap[string]map[string]string` and map all possible languages, but this is much extra work.
So is there any way golang provides some way to access members like js brackets notation?
Not: There was a similar question on the stack, and somebody wrote to use "reflect" package, but I could not quite understand how it works and failed to reproduce by myself works and failed to reproduce by myself.
One possible route would be to use a map[string]map[string]string.
You could then have a base package in which you declare your base translation variable and in your translation modules, you can use an init function to populate the relevant sub-map. It's essentially optional if you want to do this as separate packages or just separate files (doing it as packages means you have better compile-time control of what languages to include, doing it as files is probably less confusing).
If you go the packages root, I suggest the following structure:
translation/base This is where you export from
translation/<language> These are "import only" packages
Then, in translation/base:
package "base"
var Lang map[string]map[string]string
And in each language-specific package:
package "<language code>"
import "language/base"
var code = "<langcode>"
func init() {
d := map[string]string{}
d[<phrase1>] = "your translation here"
d[<phrase2>] = "another translation here"
// Do this for all the translations
base.Lang[code] = d
}
Then you can use this from your main program:
package "..."
import (
"language/base"
_ "language/lang1" // We are only interested in side-effects
_ "language/lang2" // Same here...
)
Not using separate packages is (almost) the same. You simply ensure that all the files are in the same package and you can skip the package prefix for the Lang variable.
A toy example on the Go Playground, with all the "fiddly" bits inlined.

Loop through files in a directory or a list

I am trying to generate multiple CSS classes for a single .css file to be used by the body element of a page to change the page's entire color scheme.
I have a folder of .less files containing variables #base00 to #base0F for their specific color scheme (https://github.com/AndrewBelt/hack.chat/tree/master/client/base16) and would like to import each of these files for each CSS class name.
Here's some psuedocode to achieve what I need.
// This syntax does not exist in LESS
for each #scheme in ./base16/ {
#import "#scheme"
body.#{scheme} {
background: #base00;
color: #base07;
}
...
}
I might have to think outside of the box for this one, like creating a Makefile to build by replacing variable by command line and concatenate each .css file generated by LESS to a single master .css file. But perhaps there is a more elegant way using pure LESS.
No, there's no built-in file system functions/features Less. (It's designed to work in several environments and some of those do not even permit "directory sniffing"). If necessary one can write a plugin to provide such functionality, but I suppose in this case it would be more easy to do this externally.
Compiling and concatenating multiple files is not necessary the simplest method. For example you can simply generate Less file that imports all schemes and applies each to a main template, e.g. just a list of:
.scheme-name {
#import "scheme-name";
#import (multiple) "scheme-styles-template";
}
statements. Where scheme-styles-template is the same as your scheme.less except body to be defined as:
body& {
background: #base00;
color: #base05;
}

Yii import conditions

models. *
classes. *
How do not import some files of the directories? And import them only when we need?
For example: I need import file models/SomeModel.php only in controller SomeController.php. I need import file classes/SomeClass.php only in controller SomeController.php and Some2Controller.php.
use when needed:
Yii::import('application.models.SomeModel');// protected/models/SomeModel.php
Yii::import('application.classes.SomeClass');// protected/classes/SomeClass.php
But beware that import() is different than require or include, import relies on Class names being the same as file names.

Dynamic including/autoload of external TypoScript templates

Is it possible to include automatically all external TS templates in some folders to avoid manual linking ?
Instead of writing each time manually INCLUDE_TYPOSCRIPT like this :
Constants :
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/1.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/2.ts">
...
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/999.ts">
Setup :
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/1.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/2.ts">
...
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/constants/999.ts">
I would like to have something like this instead of manual include file per file :
Constants :
<INCLUDE_TYPOSCRIPT_ALL: source="FILE:fileadmin/templates/typoscript/constants/">
Setup :
<INCLUDE_TYPOSCRIPT_ALL: source="FILE:fileadmin/templates/typoscript/setup/">
Recursive option could be helpful also.
Is it possible, or I need to hack the core to realize such functionality ?
The only way is including sub-files in one main file. It's similar approach like using #import in CSS files for including other substyles.
Then you can just include one file in your TS:
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/templates/typoscript/setup/main.ts">
and at the main.ts you can paste additional includes

Name the root directory of project generated with Maven Archetype

How can I control the name of the top directory of the maven module created by my maven archetype? Currently it creates a new folder named$artifactId. Or even more directly, is there a way that my archetype can create a folder named after the module's artifactId, but with dashes replaced by underscores?
The naming convention for artifactId's is to use dashes (hyphens). I don't think there is any way to make the module's directory named something other than the artifactId. That being said, it is onlvy convention, not a requirement, that your module be named the same as your artifactId. This means that after your project is generated, you could simply change either the artifactId or module folder name or both to whatever you want.
You can rename root folder by making an archetype-post-generate groovy script like :
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
Path projectPath = Paths.get(request.outputDirectory, request.artifactId)
// RENAME ROOT FOLDER INCLUDING A PREFIX FOR EXAMPLE
Files.move(projectPath, projectPath.resolveSibling("prefix-" + projectPath.toFile().getName()))
I got round this by adding a second required property to the archetype, and then using that in place of artifactId within the generated pom etc.
In archtype-metadata.xml:
<requiredProperties>
...
<requiredProperty key="projectCode"/>
</requiredProperties>
In pom.xml (and other substitutions):
<artifactId>${projectCode}</artifactId>
So the folder gets the name supplied for artifactId, but in the pom it is given the name supplied for projectCode.
Unfortunately you don't seem to be able to supply a default value for artifactId within archtype-metadata.xml (I always want the folder name to be the same).