Home

Awesome

CSS Modules in Meteor

This is a working experiment. Just to test if this is possible (and it is ;)).

In Meteor we have the possibility to import CSS in .js files. These CSS contents are attached to the <head> tag in Meteor app.

I've used that functionality and modified modules package (for now only as local package in /packages folder)

Run it!

$ git clone https://github.com/juliancwirko/meteor-css-modules-test.git
$ cd meteor-css-modules-test
$ npm install
$ meteor

What I've done:

This all allows me to use pseudo CSS Modules in Meteor. You can find examples in this repo and below:

Example from Meteor React tutorial:

import React, { Component, PropTypes } from 'react';

import style from './task.css';

// Task component - represents a single todo item
export default class Task extends Component {
  render() {
    return (
      <li className={style.test2}>{this.props.task.text}</li>
    );
  }
}

Task.propTypes = {
  task: PropTypes.object.isRequired,
};

As you can see I can import a .css file and then use it like: className={style.classname}. All css classes will be attached to the <head> and they will be changed to be uniq. Check out .css and .js files in this repo to test it. You can also clone it and run.

What is not so cool:

What could be improved: