npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@airy/maleo-css-plugin

v0.1.9

Published

CSS support for [Maleo](https://github.com/airyrooms/maleo.js) capable of extracting css to single css file or route based css files, and server side rendering css.

Downloads

36

Readme

Maleo CSS Plugin

CSS support for Maleo capable of extracting css to single css file or route based css files, and server side rendering css.

Installation

NPM

$ npm install --save @airy/maleo-css-plugin

Yarn

$ yarn add @airy/maleo-css-plugin

How To Use

Basic Usage

Add maleo css plugin to your maleo.config.js file.

// maleo.config.js
const cssPlugin = require('@airy/maleo-css-plugin');

module.exports = cssPlugin();

Then you can import your css files to our custom Wrap component and your CSS will be available for all page.

/* style.css */
.wrapper {
  height: 100%;
  width: 100%;
  background-color: red; /* why not 😉 */
}
// _wrap_.jsx
import React from 'react';
import Wrap from '@airy/maleo/wrap';

import './style.css';

export default class CustomWrap extends Wrap {}

Now all your component able to use the CSS you have defined, for example

// Component.jsx
import React from 'react';

export default class Component extends React.Component {
  render() {
    // This component will have the .wrapper style we defined above
    return (
      <div className="wrapper">
        <h1>Hello World</h1>
      </div>
    )
  }
}

Advanced Usage

With CSS Modules

A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. Maleo-css-plugins uses css-loader, and you can configure the css-loader at maleo.config.js through cssLoader options key.

For example:

// maleo.config.js
const cssPlugin = require('@airy/maleo-css-plugin');

module.exports = cssPlugin({
  cssLoader: {
    modules: true, // Add this line
    localIdentName: '[path][name]__[local]--[hash:base64:5]', // Optional default: '[hash:base64]'
    // other options
    // url: true,
    // import: true,
    // context: undefined,
    // hashPrefix: undefined,
    // getLocalIdent: undefined,
    // sourceMap: false,
    // camelCase: false,
    // importLoaders: 0,
    // exportOnlyLocals: false,
  },
});

And now on your code you can import your CSS file as such:

// Component.jsx
import React from 'react';

import style from './style.css';

export default class Component extends React.Component {
  render() {
    // This component will have the .wrapper style we defined above
    return (
      <div className={style.wrapper}>
        <h1>Hello World</h1>
      </div>
    )
  }
}

More options can be found here css-loader


Enable Isomorphic Style Loader

Isomorphic Style Loader is a CSS style loader for Webpack that is optimized for isomorphic (universal) web apps. more

By enabling ISL, you gain server side rendering with style but you can not use this when you enable extract css feature. Since it doesn't make sense to have different ways of styling both during SSR and on CSR.

To enable ISL:

// maleo.config.js
const cssPlugin = require('@airy/maleo-css-plugin');

module.exports = cssPlugin({
  enableISL: true, // Add this line
  cssLoader: {
    modules: true,
    localIdentName: '[path][name]__[local]--[hash:base64:5]',
  },
});

After having done so, you need to add provided Higher Order Component to your custom wrap.

// _wrap_.jsx
import React from 'react';
import Wrap from '@airy/maleo/wrap';

import PageWithStyles from '@airy/maleo-css-plugin/pageWithStyles'; // Add this line

@PageWithStyles // Add this line
export default class CustomWrap extends Wrap {}

And now you can use your CSS style on your component like this

// Component.jsx
import React from 'react';
import withStyles from '@airy/maleo-css-plugin/withStyles'; // Add this line

import style from './style.css';

@withStyles(style) // Add this line
export default class Component extends React.Component {
  render() {
    // This component will have the .wrapper style we defined above
    return (
      <div className={style.wrapper}>
        <h1>Hello World</h1>
      </div>
    )
  }
}

withStyles is a Higher Order Component that receives your CSS style and will pass all your style to PageWithStyles and render your styling.

If you opt to enable ISL, you must add PageWithStyles to your custom wrap and use withStyles decorator as such to every of your component that uses your CSS style.

Extract CSS to CSS File

By enabling this feature, it extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS or single file CSS, and SourceMaps.

Extract CSS feature has already optimized and minify your CSS file and only runs on production environment.

To enable this feature, you need to enable it on maleo.config.js

// maleo.config.js
const cssPlugin = require('@airy/maleo-css-plugin');

module.exports = cssPlugin({
  extractCss: true,
  // you can also pass the option here such as:
  // extractCss: {
  // Here are the default option
  //  filename: '[name].css',
  //  chunkFilename: 'style-chunk-[name].css',
  //  singleCssFile: false, // if enabled, it will extract all the CSS files into single css file
  //  publicPath: undefined, // automatically follows webpack's publicPath if set undefined
  //  cache: true, // will enable long term caching by appending '[contenthash]' to filename and chunkFilename
  // },
  cssLoader: {
    modules: true,
    localIdentName: '[path][name]__[local]--[hash:base64:5]',
  },
});

Having done so, you can use your CSS on your React Component like so

// Component.jsx
import React from 'react';

import style from './style.css';

export default class Component extends React.Component {
  render() {
    // This component will have the .wrapper style we defined above
    return (
      <div className={style.wrapper}>
        <h1>Hello World</h1>
      </div>
    )
  }
}