css declare variables with meteor [duplicate] - css

This question already has answers here:
How can I define colors as variables in CSS?
(19 answers)
Closed 8 years ago.
What is the cleanest easiest way to declare a variable in CSS with meteor? Between the two CSS compilers SASS and LESS, which one can allow me to declare variables so I do not need to define exact values, instead, have control from a variable. For example...
variableNameOne: value;
variableNameTwo: value;
.sidebar-nav li a {
color: variableNameOne;
}
I do not wish to do anything more advanced than this in css. I am using boootstrap in meteor.
CSS3 apparently supports variables by declaring them at the top of the styling sheet inside :root {varName: value;} but it is not supported in all browsers as far as I have read.
Is this the best practice to install nemo64's bootstrap and less? sourced from http://www.manuel-schoebel.com/blog/meteorjs-and-twitter-bootstrap---the-right-way
// 1. Add the less compiler so meteor compiles everything for you
meteor add less
// 2. Add the bootstrap
meteor add nemo64:bootstrap
// 3. Clone this stylesheet boiler
// Also delete the .git folder and .gitignore if you don't like those
cd yourapp/client/
git clone https://github.com/DerMambo/stylesheets.git
// 4. Add everything you need into the file
// yourapp/client/vendor/custom.bootstrap.json

I would strongly advise using a CSS precompiler, once you start using it you'll never want to go back.
Since you're using bootstrap, I'll list the 2 CSS precompilers that bootstrap provides support for : LESS and SASS.
LESS :
Probably the easiest solution, LESS is baked into Meteor (just meteor add less and throw .less and .import.less files in your sources) and it provides every feature you'll probably need if not a CSS guru.
I recommend this package https://github.com/Nemo64/meteor-bootstrap to integrate a LESS customizable bootstrap in your app, you'll be able to override bootstrap variables (colors, responsive breakpoints, and a ton of other things just by changing variables values, no more dirty CSS hacks with !important).
SASS :
Sass is considered superior to LESS as far as features are concerned and is probably a better choice in the long term if you plan to spend times in web application stylesheets design.
There is package that adds support for Sass source files compilation within a Meteor app (https://atmospherejs.com/fourseven/scss), and you should be able to find a decent bootstrap-sass package too.
Be aware that Meteor Sass is based on node-sass which is based on libsass, a reimplementation of the original Ruby Sass in C++, which is not exactly up-to-date with the regular Ruby implementation, but this should hardly be a problem since only pretty advanced features lacks support in libsass.
Please note that this is an ultra-short presentation of CSS precompilers and thus subject to primarily opinion-based comments.

Related

What is the difference between gulp-clean-css vs gulp-csso vs gulp-minify-css?

Recently I learned gulp and I saw three gulp plugins called gulp-clean-css, gulp-csso, gulp-minify-css ( deprecated ).
I saw in internet but no question found like that, except this website but it shows only graph of downloads.
So my question is
Which plugin I use in my big project to minify my multiple CSS
What is the cons and pros of above plugins
CSSO (75 commits) is simply used to minify and generate source maps for pre-processed files.
Clean-CSS (1583 commits) has a lot more options : it can remove units when they're not needed, convert colors for shorter declarations, can remove duplicate rules, restructure rules, etc.
I would suggest looking into CSS Nano (1923 commits) as well since it has the same options as Clean CSS but is used more widely since it is built on the PostCSS ecosystem. Here is the list of all the possible optimisations.
It basically depends of the complexity of your project and what you're currently using.

How to start structuring your own css when not working with a framework like bootstrap/bulma/materialize

I'm starting a new angular project and it has been decided not to use a framework like bootstrap/bulma/materialize/... but write our own sassy component library.
I have done some research but to be honnest I don't realy know where to start (besides a css reset). I'm still a junior, have already worked on some features in a previous existing project. Now I have to start of the front end for new project and would like to build everything as structured and reusable as possible but I'm a little lost where to start.
What's your plan of action when you start writing your?
How do you structure your angular components library?
Have you ever seen a good tutorial about this that I should definitely check out as well?
From my point of view, it is not a simple task. But you can start from using SCSS which will give you a wide access to term reusability. And also you may need to work on flexbox/grid-layout (Not the case if you need to support old browsers like IE 11 and below) to implement a handful of styled components. By the combination of scss and 'flexbox`, I think most of the components can be created simply and reused in the way you want it to be.
I strongly recommend avoiding the usage of libraries and write our own code instead. Because the power we will have at the time is infinite. You will be amazed to have it.
But at the same time, if the project is a long-running project and your requirements are on the way, then I would suggest you to rethink about eliminating libraries like 'bootstrap, materialize. Otherwise, if the requirements change in time and you may need to use a number of libraries to achieve the functionalities you may need. (Experience is the best teacher)
On most of my projects to date I have not used a framework and written my own CSS library and would recommended it. I don't have any experience with Angular, only React. All I can share with you is my current setup.
I use gulp to compile SASS files into a main.css file and BEM methodology (You could also look at SMACSS). Each 'block' (defined by BEM) has a separate file in either Layout or Modules.
I separate my SASS files into the following folder:
Base - Used for - resets /Grids / helpers/ typography/ base (general base styles eg wrap)
Layout - Used for containers - header/footer/sidebar ect
Lib - used for mixins
Modules - used for components - form / button / alert / icon / accordion ect
Settings - color / font / responsive - used to set sass varibles to be used in all other files.
I hope that helps.

Can Sass or Less be configured to compile just certain classes?

Let's say I have a large Sass/Less project such as Bootstrap, and I want to use one single element of it, (say, a text box.) Is is possible to have Sass/Less compile just the classes needed for that, referencing whatever variables and mixins that are across multiple files, just to compile that 1 (or 2, or 5, or 10) class(es)?
You could create mixins that aren't executed immediately by adding parenthesis. In my less library, I use a node script to create an autoload.less file which I can reference.
From there, I create my final classes as:
#import "autoload.less";
.myClass {
#myLessModule > .aMixin();
}
I don't think this is a perfect solution but it is working fairly well for me, and the resulting stylesheets do not contain excess stylings.
There currently aren't any features in Less/Sass to accommodate this. What you are looking for is a post-build process to remove unused CSS classes. The most notable currently is Uncss which has plugins available for most build tools (Gulp, Grunt, etc)

EmberJS CSS options

I'm trying to sift through all the CSS options / packages available for EmberJS and am looking for suggestions. I suppose it will help if I list what I need:
SASS syntax (variables, nesting, creating mixins, and extending)
Ability to import other CSS libraries
Pod support (although I'm not positive I'll be using this feature at the moment, but I at least want to be able to have one CSS per route/component)
Autoprefixer
Is there an all-in-one Ember package that will give me all these? Thanks!
SASS syntax (variables, nesting, creating mixins, and extending)
You should think long and hard before taking the blue SASS pill. SASS is a technology trending towards obsolescence, which was designed mainly to support some bad CSS coding practices, as well as overcome some deficiencies in earlier versions of CSS.
Variables are supported by postCSS plugins in a standard way which is compatible with the upcoming CSS variable syntax.
Nesting is an answer in search of a problem. It promotes a bad style of coding involving excessive dependency on HTML structure. Properly constructed systems of CSS classes, orthogonal to HTML, make nesting unnecessary.
With regards to mixins, I have not seen a real-life situation in which mixins or other more advanced SASS features were actually necessary. Using them, you end up learning yet another (weird) programming language, which you have to debug, and make sure all the people on your team know.
When it comes to extending, CSS experts counsel against it. Besides potential issues of performance and code size, they hide the logic of the CSS code, and require jumping back and forth from file to file to maintain and extend and debug. Everything that is accomplished with extending can be handled with properly-designed CSS classes.
SASS is slow, is bifurcated (binary version vs. Ruby version), and can give rise to strange npm installation problems. My advice is to avoid it.
There is an interesting read about SASS vs. postCSS here.
Ability to import other CSS libraries
Ability to import other CSS libraries is not a function of any other decision you make, or what package you choose. You can simply import these.
Pod support (although I'm not positive I'll be using this feature at the moment, but I at least want to be able to have one CSS per route/component)
Indeed. There is at least one new-ish Ember add-on to do this (and probably more), which IMHO is designed extremely poorly and grossly over-engineered. It follows the Ember approach of doing way too much, in an opaque way, in the name of being "helpful" (until it isn't, at which point you're screwed). This is great if you want your CSS to be littered with classes like .my-component-a34fba.
Until there is a better alternative, I'd do this manually, which is quite easy. Simply place your CSS files in the pod, and then import, from your styles/app.css or equivalent file, the CSS files from the pods you want, such as #import '../pods/thingie/; to import its index.css file. Yes, you will have to do some maintenance of these imports yourself, but how many pods do you have?
What I do to avoid a huge styles/app.css that would require constant updating is to place an index.css file in each pod and import that. From there, import a stylesheet for that directory itself and any necessary subdirectories:
/* styles/app.css */
#import '../app/pods/thingie';
/* app/pods/thingie/index.css */
#import `./style`;
#import `./subdir1';
#import `./subdir2';
Autoprefixer
You need look no further than the excellent postcss/autoprefixer.
Is there an all-in-one Ember package that will give me all these?
It would be nice if all our problems could be handled by all-in-one packages. Unfortunately, all-in-one packages are always missing two features we wanted, and we can never figure out how to add them. They always do one thing we didn't want them to do, and we can never figure how to turn it off. They import old versions of their subpackages. They break when there's an Ember upgrade. They stop being maintained. The Ember philosophy itself sadly promotes this pernicious all-in-one mentality--all my problems can be solved by yet another add-on!
You are better off understanding individual technologies, choosing simple, bounded, reliable implementations of them, and weaving them together yourself. Just my two cents.
This might be the closest thing you're looking for:
https://github.com/ebryn/ember-component-css
Which supports using pods layout, and lets you use ember-cli-sass.
To use auto-prefixing, there are plenty of sass libraries out there to help you out, like Bourbon.io, which you can install via npm. Then, it should just be matter of configuring the import paths via the sass options in the ember-cli-build.js
I recommend PostCSS. Last I checked, it doesn't work out-of-the-box with ember-component-css, but you don't need ember-component-css to namespace your styles.
You can modify Ember's Component generator / blueprint to (assuming you're using pods):
Add classNames: ['component-name-here'], to the generated component.js file.
Create a _component-name-here.css file/partial in app/styles/components (or similar), with a class .component-name-here to contain all styles in the partial.
If necessary, #import that new partial in your app.css.
Then all your Component styles will be namespaced.
To handle variables, nesting and Autoprefixer, you just need to set up PostCSS with the right plugins, e.g.:
plugins: [
{
module: require('postcss-partial-import'),
},
{
module: require('postcss-nested'),
},
{
module: require('postcss-custom-media'),
},
{
module: require('postcss-custom-properties'),
},
{
module: require('autoprefixer'),
options: { browsers: ['last 2 versions'] }
},
],
I'm using ember-cli-css-preprocess, which gives you the option to use SASS as well (alongside PostCSS), if you wish.

How to modify Bootstrap's LESS variables in a Flask app?

I am making a static website with Flask and using the flask-bootstrap extension to simplify the front-end development. I concurrently have been learning Rails and so I understand that there are a few of these languages that compile down to CSS (LESS/SASS/SCSS). As I understand it, Bootstrap by default uses LESS, and in my Rails app I had to convert LESS variables (with an # symbol at the beginning) into SCSS variables (with a $). This wasn't too difficult, no problem.
I noticed that in Miguel Grinberg's tutorial (Flask Web Development, O'Reilly) Bootstrap is used (Flask-Bootstrap extension), and there is the brief mention of {% block styles %} used to include stylesheets that way, I am confused about how I can go about modifying the existing LESS variables that come by default with Bootstrap so that I can modify the grid structure and not mess things up with my own custom stylesheets. I want to be able to do, for example, is modify the #body-bg LESS variable, or any of the ones here: http://getbootstrap.com/customize
It is very interesting question. I also was interesting in creating styles dynamically. You need follow another ways. It is not possible by the way you have described above.
You mentioned you used Flask-Bootstrap. This extension adopts the Flask project to use the Twitter Bootstrap styles. I have not fond any SASS/LESS functionality.
http://pythonhosted.org/Flask-Bootstrap/#
https://github.com/mbr/flask-bootstrap
If you look at the static folder of the extension you will not find any tracks of SASS/LESS.
As I know Twitter Bootstrap is generated by LESS. There is also a SASS fork. You regenerate styles and replace them in the static folder of the Flask-Bootstrap project.
If you want to do it dynamically you need create your own solution. I do not know a ready extension. It is the very challenging task.

Resources