Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Meteor Cookbook
  • Table Of Contents Toc
Meteor Cookbook

Meteor Cookbook

By : Isaac Strack
4.4 (5)
close
close
Meteor Cookbook

Meteor Cookbook

4.4 (5)
By: Isaac Strack

Overview of this book

This book is meant for developers of all experience levels looking to create mobile and full-stack web applications in JavaScript. Many of the simple recipes can easily be followed by less-experienced developers, while some of the advanced recipes will require extensive knowledge of existing web, mobile, and server technologies. Any application or enterprise web developer looking to create full-stack JavaScript-based apps will benefit from the recipes and concepts covered in this book.
Table of Contents (14 chapters)
close
close
13
Index

Using CSS compilers

As any CSS junkie already knows, using standard CSS to create style sheets can be tedious, redundant work. Many designers and developers prefer to use a dynamic style sheet language or preprocessors, such as Less, Stylus, and SCSS/SASS.

Meteor not only enables the use of preprocessors, but also treats them just like any other file so that changes are reflected immediately.

This recipe will show you how to enable some of the more popular CSS compilers in your Meteor application.

Getting ready

Nothing is needed to prepare for this recipe, other than having Meteor installed, and a project created so that you can begin using CSS compilers.

How to do it…

We're going to cover three different preprocessors, as they all work in a similar way.

Using Stylus

  1. Open a terminal window and navigate to the root folder of your project.
  2. Enter the following command:
    $ meteor add stylus
    

    You should see a response similar to the following in the terminal window:

    stylus  added, version 1.0.7
    

    Stylus is now installed and ready to be used. You can test this by creating a .styl file and adding a script (for example, add test.styl to your client/styles folder).

When you start your Meteor application with the meteor command, Stylus files will be processed and proper CSS will be rendered.

Tip

You can use the nib code in Meteor as well. Just add @import 'nib' to your .styl files, and Meteor takes care of the rest.

Using Less

  1. Open a terminal window and navigate to the root folder of your project.
  2. Enter the following command:
    $ meteor add less
    

    You should see the following response in the terminal window:

    less  added, version 1.0.14
    

    Now the Less package is installed, and you can use the Less stylesheet syntax to create your CSS.

As with Stylus, you can test this by creating a .less file and adding some style declarations (for example, add test.less to your client/styles folder).

When you start your Meteor application with the meteor command, the Less files will be compiled by Meteor into standard CSS and rendered as usual.

Tip

If you're fond of using @import statements in your Less stylesheets, make sure you use the .lessimport extension. Otherwise, Meteor will automatically import and compile any and all .less files it can find.

Using SCSS / SASS

  1. Open a terminal window and navigate to the root folder of your project.
  2. Enter the following command:
    $ meteor add fourseven:scss
    

    You should see a response similar to the following in the terminal window:

    fourseven:scss  added, version 2.1.1
    

SCSS and SASS files can now be used to style your CSS. Just as before, you can test this by creating a .scss or .sass file and adding some style declarations (for example, add test.sass to your client/styles folder).

When you start your Meteor application with the meteor command, the SCSS or SASS files will be compiled by Meteor into standard CSS and rendered.

How it works…

When you installed any of the preprocessors with the meteor add command, it installed the corresponding npm packages tailored to work inside of Meteor.

As with other files, Meteor will monitor changes to any *.styl, .less, .scss, and .sass files, compile the changes into CSS, and render the changes immediately.

See also

  • The Adding Meteor packages recipe in Chapter 2, Customizing with Packages
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Meteor Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon