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

@magiclabs/next-css

v1.0.0

Published

Feature-parity with NextJS's built-in CSS with the flexibility to support your favorite pre-processor(s)!

Downloads

121

Readme

▲ + 💅 Better CSS Support for NextJS

Feature-parity with NextJS's built-in CSS with the flexibility to support your favorite pre-processor(s)!

This is a NextJS configuration decorator with the goal of approximately mirroring NextJS's built-in CSS support without losing the flexibility of technology choice. For example, at Magic Labs, we are invested in LESS! However, the built-in CSS features of NextJS are very desirable, so we created @magiclabs/next-css to bridge the gap.

🔗 Installation

@magiclabs/next-css is available as an NPM package:

# Via NPM:
npm install --save @magiclabs/next-css

# Via Yarn:
yarn add @magiclabs/next-css

Peer Dependencies

This module requires NextJS (^12.0.0) as a peer dependency. Additionally, any Webpack dependencies related to your CSS pre-processor of choice are required to be installed separately.

📚 Usage

The stylesheet is compiled to .next/static/css. Next.js will automatically add the css file to the HTML. In production, a chunk hash is added so that styles are updated when a new version of the stylesheet is deployed.

Basic Configuration

Create a next.config.js in the root of your project (next to pages/ and package.json).

// next.config.js
const { withCSS } = require('@magiclabs/next-css'); // Please note the named export!

module.exports = withCSS({
  // Array of objects configuring any CSS pre-processors you like!
  preProcessors: [
    {
      extensions: [...], // i.e.: ["less"] or ["sass", "scss"]
      use: [...], // Receives same configuration as Webpack > Module > Rule > Use
    },
  ],

  // Also valid as a factory function!
  // Receives the same arguments as a NextJS custom `webpack` function.
  preProcessors: (config, options) => [...],
});

Configuration Fields

  • preProcessors: An array of PreProcessorItem objects, or a function returning an array of PreProcessorItem objects with the following shape:

⚡️ Quick Starts

You can easily configure @magiclabs/next-css for the following common use-cases:

With LESS

First, install your LESS-specific dependencies:

# Via NPM:
npm install --save less less-loader

# Via Yarn:
yarn add less less-loader

Next, configure the pre-processor with @magiclabs/next-css:

// next.config.js
const { withCSS } = require('@magiclabs/next-css');

module.exports = withCSS({
  preProcessors: [
    {
      extensions: ["less"],
      use: [require.resolve('less-loader')],
    },
  ],
});

⚖️ Trade-offs

  • More dependencies leads to longer NPM package installation times. These are marginal for a typical project.

  • This is a wholesale re-implementation of NextJS CSS support, so there may be some inconsistencies between the end results. NextJS notably benefits from aggressive internal optimizations which may be missing or unaccounted for here. That being said, we try our best to match the internal implementation as closely as possible.